Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sg_jobs
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TYPO3
sg_jobs
Commits
944d59a6
Commit
944d59a6
authored
4 years ago
by
Kevin Ditscheid
Browse files
Options
Downloads
Patches
Plain Diff
[BUGFIX] Replace AbstractUpdate class
parent
ee131407
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!23
Feature upgrade to typo3 10
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Classes/Updates/DepartmentUpdateWizard.php
+82
-69
82 additions, 69 deletions
Classes/Updates/DepartmentUpdateWizard.php
ext_localconf.php
+1
-1
1 addition, 1 deletion
ext_localconf.php
with
83 additions
and
70 deletions
Classes/Updates/DepartmentUpdateWizard.php
+
82
−
69
View file @
944d59a6
...
...
@@ -28,7 +28,8 @@ namespace SGalinski\SgJobs\Updates;
use
TYPO3\CMS\Core\Database\Connection
;
use
TYPO3\CMS\Core\Database\ConnectionPool
;
use
TYPO3\CMS\Core\Utility\GeneralUtility
;
use
TYPO3\CMS\Install\Updates\AbstractUpdate
;
use
TYPO3\CMS\Install\Updates\DatabaseUpdatedPrerequisite
;
use
TYPO3\CMS\Install\Updates\UpgradeWizardInterface
;
/**
* Class DepartmentUpdateWizard
...
...
@@ -36,48 +37,76 @@ use TYPO3\CMS\Install\Updates\AbstractUpdate;
* @package SGalinski\SgJobs\Updates
* @author Kevin Ditscheid <kevin.ditscheid@sgalinski.de>
*/
class
DepartmentUpdateWizard
ext
en
d
s
AbstractUpdat
e
{
class
DepartmentUpdateWizard
implem
en
t
s
UpgradeWizardInterfac
e
{
/**
* @var string
* Check if the job table has a deleted area field
*
* @return bool
*/
protected
$title
=
'Migrate old fulltext job areas to department records'
;
protected
function
hasDeletedAreaField
():
bool
{
return
$this
->
hasField
(
'zzz_deleted_area'
);
}
/**
* Check
s whether updates are required.
* Check
if the job table has an area field
*
* @param string &$description The description for the update
* @return bool Whether an update is required (TRUE) or not (FALSE)
* @return bool
*/
public
function
checkForUpdate
(
&
$description
)
:
bool
{
if
(
$this
->
isWizardDone
())
{
return
FALSE
;
}
if
(
!
$this
->
checkIfTableExists
(
'tx_sgjobs_domain_model_department'
))
{
return
FALSE
;
}
protected
function
hasAreaField
():
bool
{
return
$this
->
hasField
(
'area'
);
}
if
(
$this
->
hasAreaField
()
||
$this
->
hasDeletedAreaField
()
)
{
$description
=
'Job areas can be migrated to the new department records'
;
/**
* Check if the job database table has a field with the given name in it
*
* @param $fieldName
* @return bool
*/
protected
function
hasField
(
$fieldName
):
bool
{
$connection
=
$this
->
getDatabaseConnection
();
$tableColumns
=
$connection
->
getSchemaManager
()
->
listTableColumns
(
'tx_sgjobs_domain_model_job'
);
if
(
\array_key_exists
(
$fieldName
,
$tableColumns
))
{
return
TRUE
;
}
return
FALSE
;
}
/**
*
Performs the accordant updates.
*
Get the database query builder
*
* @param array &$dbQueries Queries done in this update
* @param string &$customMessage Custom message
* @return bool Whether everything went smoothly or not
* @return Connection
*/
public
function
performUpdate
(
array
&
$dbQueries
,
&
$customMessage
)
:
bool
{
$customMessage
=
''
;
protected
function
getDatabaseConnection
():
Connection
{
$connectionPool
=
GeneralUtility
::
makeInstance
(
ConnectionPool
::
class
);
return
$connectionPool
->
getConnectionForTable
(
'tx_sgjobs_domain_model_job'
);
}
/**
* @return string
*/
public
function
getIdentifier
():
string
{
return
'tx_sgjobs_departmentupdatewizward'
;
}
/**
* @return string
*/
public
function
getTitle
():
string
{
return
'Migrate old fulltext job areas to department records'
;
}
/**
* @return string
*/
public
function
getDescription
():
string
{
return
''
;
}
/**
* @return bool
*/
public
function
executeUpdate
():
bool
{
$connection
=
$this
->
getDatabaseConnection
();
$queryBuilder
=
$connection
->
createQueryBuilder
();
$field
=
$this
->
hasDeletedAreaField
()
?
'zzz_deleted_area'
:
'area'
;
...
...
@@ -87,8 +116,6 @@ class DepartmentUpdateWizard extends AbstractUpdate {
->
execute
()
->
fetchAll
();
$dbQueries
[]
=
$queryBuilder
->
getSQL
();
$newDepartments
=
[];
if
(
\count
(
$jobs
)
>
0
)
{
foreach
(
$jobs
as
$index
=>
$job
)
{
...
...
@@ -100,8 +127,6 @@ class DepartmentUpdateWizard extends AbstractUpdate {
'sys_language_uid'
=>
$job
[
'sys_language_uid'
]
];
}
else
{
$customMessage
.
=
'The Job with id '
.
$job
[
'uid'
]
.
' does not have an area set.'
.
'Please set a department manually later, because it is a required field now!'
.
\PHP_EOL
;
unset
(
$jobs
[
$index
]);
}
}
...
...
@@ -109,11 +134,11 @@ class DepartmentUpdateWizard extends AbstractUpdate {
/** @noinspection NotOptimalIfConditionsInspection */
if
(
\count
(
$jobs
)
>
0
)
{
\array_walk
(
$newDepartments
,
function
(
$department
)
use
(
&
$dbQueries
,
$connection
)
{
$queryBuilder
=
$connection
->
createQueryBuilder
();
$queryBuilder
->
insert
(
'tx_sgjobs_domain_model_department'
)
->
values
(
$department
)
->
execute
();
$dbQueries
[]
=
$queryBuilder
->
getSQL
();
}
$newDepartments
,
function
(
$department
)
use
(
&
$dbQueries
,
$connection
)
{
$queryBuilder
=
$connection
->
createQueryBuilder
();
$queryBuilder
->
insert
(
'tx_sgjobs_domain_model_department'
)
->
values
(
$department
)
->
execute
();
$dbQueries
[]
=
$queryBuilder
->
getSQL
();
}
);
$queryBuilder
->
resetQueryParts
();
...
...
@@ -143,7 +168,7 @@ class DepartmentUpdateWizard extends AbstractUpdate {
/** @noinspection NotOptimalIfConditionsInspection */
if
(
\count
(
$jobs
)
>
0
)
{
\array_walk
(
$jobs
,
function
(
$job
)
use
(
&
$dbQueries
,
$connection
)
{
$jobs
,
function
(
$job
)
use
(
$connection
)
{
$queryBuilder
=
$connection
->
createQueryBuilder
();
$queryBuilder
->
update
(
'tx_sgjobs_domain_model_job'
)
->
set
(
'department'
,
(
int
)
$job
[
'department'
])
...
...
@@ -153,56 +178,44 @@ class DepartmentUpdateWizard extends AbstractUpdate {
$queryBuilder
->
createNamedParameter
(
$job
[
'uid'
],
\PDO
::
PARAM_INT
)
)
)
->
execute
();
$dbQueries
[]
=
$queryBuilder
->
getSQL
();
}
);
}
}
}
$this
->
markWizardAsDone
();
return
TRUE
;
}
/**
* Check if the job table has a deleted area field
*
* @return bool
*/
protected
function
hasDeletedAreaField
():
bool
{
return
$this
->
hasField
(
'zzz_deleted_area'
);
return
TRUE
;
}
/**
* Check if the job table has an area field
*
* @return bool
*/
protected
function
hasAreaField
():
bool
{
return
$this
->
hasField
(
'area'
);
}
public
function
updateNecessary
():
bool
{
if
(
!
GeneralUtility
::
makeInstance
(
ConnectionPool
::
class
)
->
getConnectionForTable
(
'tx_sgjobs_domain_model_department'
)
->
getSchemaManager
()
->
tablesExist
([
'tx_sgjobs_domain_model_department'
])
)
{
return
FALSE
;
}
/**
* Check if the job database table has a field with the given name in it
*
* @param $fieldName
* @return bool
*/
protected
function
hasField
(
$fieldName
):
bool
{
$connection
=
$this
->
getDatabaseConnection
();
$tableColumns
=
$connection
->
getSchemaManager
()
->
listTableColumns
(
'tx_sgjobs_domain_model_job'
);
if
(
\array_key_exists
(
$fieldName
,
$tableColumns
))
{
if
(
$this
->
hasAreaField
()
||
$this
->
hasDeletedAreaField
()
)
{
return
TRUE
;
}
return
FALSE
;
}
/**
* Get the database query builder
*
* @return Connection
* @return array|string[]
*/
protected
function
getDatabaseConnection
():
Connection
{
$connectionPool
=
GeneralUtility
::
makeInstance
(
ConnectionPool
::
class
);
return
$connectionPool
->
getConnectionForTable
(
'tx_sgjobs_domain_model_job'
);
public
function
getPrerequisites
():
array
{
return
[
DatabaseUpdatedPrerequisite
::
class
];
}
}
This diff is collapsed.
Click to expand it.
ext_localconf.php
+
1
−
1
View file @
944d59a6
...
...
@@ -98,7 +98,7 @@ call_user_func(
);
// Register the upgrade wizard
$GLOBALS
[
'TYPO3_CONF_VARS'
][
'SC_OPTIONS'
][
'ext/install'
][
'update'
][
\SGalinski\SgJobs\Updates\D
epartment
U
pdate
W
izard
::
class
]
$GLOBALS
[
'TYPO3_CONF_VARS'
][
'SC_OPTIONS'
][
'ext/install'
][
'update'
][
'tx_sgjobs_d
epartment
u
pdate
w
iz
w
ard
'
]
=
\SGalinski\SgJobs\Updates\DepartmentUpdateWizard
::
class
;
if
(
version_compare
(
\TYPO3\CMS\Core\Utility\VersionNumberUtility
::
getCurrentTypo3Version
(),
'9.0.0'
,
'>'
))
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment