Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sg_mail
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
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_mail
Commits
5b0847f3
Commit
5b0847f3
authored
5 years ago
by
Stefan Galinski
Browse files
Options
Downloads
Patches
Plain Diff
[TASK] Drastically improve the upgrade wizard (performance, functionality)
parent
3d72f981
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Classes/Updates/UpdatePidToSiteRoot.php
+25
-69
25 additions, 69 deletions
Classes/Updates/UpdatePidToSiteRoot.php
with
25 additions
and
69 deletions
Classes/Updates/UpdatePidToSiteRoot.php
+
25
−
69
View file @
5b0847f3
...
...
@@ -68,28 +68,19 @@ class UpdatePidToSiteRoot extends AbstractUpdate {
public
function
checkForUpdate
(
&
$description
)
{
$description
=
'Move site root ids to pid & update pids to their correspondent site root ids'
;
// check if site_root columns actually exist
$hasColumn
=
[];
foreach
(
$this
->
tables
as
$table
)
{
$hasColumn
[
$table
]
=
$this
->
siteRootColumnExists
(
$table
);
}
// are there site root columns differing from pids?
foreach
(
$this
->
tables
as
$table
)
{
if
(
!
$
hasColumn
[
$table
]
)
{
if
(
!
$
this
->
siteRootColumnExists
(
$table
)
)
{
continue
;
}
$queryBuilder
=
GeneralUtility
::
makeInstance
(
ConnectionPool
::
class
)
->
getQueryBuilderForTable
(
$table
);
$queryBuilder
->
getRestrictions
()
->
removeAll
()
->
add
(
GeneralUtility
::
makeInstance
(
DeletedRestriction
::
class
));
$rowCount
=
$queryBuilder
->
select
(
'*'
)
->
from
(
$table
)
->
where
(
$queryBuilder
->
expr
()
->
neq
(
'site_root_id'
,
'pid'
)
)
->
where
(
$queryBuilder
->
expr
()
->
neq
(
'site_root_id'
,
'pid'
))
->
execute
()
->
rowCount
();
if
(
$rowCount
>
0
)
{
return
TRUE
;
break
;
}
}
...
...
@@ -97,9 +88,7 @@ class UpdatePidToSiteRoot extends AbstractUpdate {
foreach
(
$this
->
tables
as
$table
)
{
$queryBuilder
=
GeneralUtility
::
makeInstance
(
ConnectionPool
::
class
)
->
getQueryBuilderForTable
(
$table
);
$queryBuilder
->
getRestrictions
()
->
removeAll
()
->
add
(
GeneralUtility
::
makeInstance
(
DeletedRestriction
::
class
));
$result
=
$queryBuilder
->
select
(
'pid'
)
->
from
(
$table
)
->
execute
()
->
fetchAll
();
$result
=
$queryBuilder
->
select
(
'pid'
)
->
from
(
$table
)
->
groupBy
(
'pid'
)
->
execute
();
foreach
(
$result
as
$row
)
{
$siteRootId
=
BackendService
::
getSiteRoot
(
$row
[
'pid'
]);
if
(
$siteRootId
!==
$row
[
'pid'
])
{
...
...
@@ -117,57 +106,29 @@ class UpdatePidToSiteRoot extends AbstractUpdate {
* @param array &$dbQueries Queries done in this update
* @param mixed &$customMessages Custom messages
* @return bool Whether everything went smoothly or not
* @throws \Doctrine\DBAL\DBALException
*/
public
function
performUpdate
(
array
&
$dbQueries
,
&
$customMessages
)
{
$dbQueries
=
[];
// set pids to siteroot
foreach
(
$this
->
tables
as
$table
)
{
if
(
!
$this
->
siteRootColumnExists
(
$table
))
{
continue
;
}
$queryBuilder
=
GeneralUtility
::
makeInstance
(
ConnectionPool
::
class
)
->
getQueryBuilderForTable
(
$table
);
$queryBuilder
->
getRestrictions
()
->
removeAll
()
->
add
(
GeneralUtility
::
makeInstance
(
DeletedRestriction
::
class
));
$result
=
$queryBuilder
->
select
(
'uid'
,
'site_root_id'
)
->
from
(
$table
)
->
execute
()
->
fetchAll
();
$dbQueries
[]
=
$queryBuilder
->
getSQL
();
/** @var array $result */
foreach
(
$result
as
$row
)
{
$queryBuilder
->
update
(
$table
)
->
where
(
$queryBuilder
->
expr
()
->
eq
(
'uid'
,
$queryBuilder
->
createNamedParameter
(
$row
[
'uid'
],
\PDO
::
PARAM_INT
))
)
->
set
(
'pid'
,
(
int
)
$row
[
'site_root_id'
])
->
execute
();
$dbQueries
[]
=
$queryBuilder
->
getSQL
();
}
}
// check if pid is a site root, if not update it to the nearest one
foreach
(
$this
->
tables
as
$table
)
{
$queryBuilder
=
GeneralUtility
::
makeInstance
(
ConnectionPool
::
class
)
->
getQueryBuilderForTable
(
$table
);
$queryBuilder
->
getRestrictions
()
->
removeAll
()
->
add
(
GeneralUtility
::
makeInstance
(
DeletedRestriction
::
class
));
$result
=
$queryBuilder
->
select
(
'uid'
,
'pid'
)
->
from
(
$table
)
->
execute
()
->
fetchAll
();
$dbQueries
[]
=
$queryBuilder
->
getSQL
();
/** @var array $result */
foreach
(
$result
as
$row
)
{
$siteRootId
=
BackendService
::
getSiteRoot
(
$row
[
'pid'
]);
if
(
$siteRootId
===
0
)
{
$siteRootId
=
1
;
}
if
(
$siteRootId
!==
(
int
)
$row
[
'pid'
])
{
$queryBuilder
->
update
(
$table
)
->
where
(
$queryBuilder
->
expr
()
->
eq
(
'uid'
,
$queryBuilder
->
createNamedParameter
(
$row
[
'uid'
],
\PDO
::
PARAM_INT
))
)
->
set
(
'pid'
,
$siteRootId
,
TRUE
)
->
execute
();
if
(
$this
->
siteRootColumnExists
(
$table
))
{
$connection
=
GeneralUtility
::
makeInstance
(
ConnectionPool
::
class
)
->
getConnectionForTable
(
$table
);
$sql
=
'UPDATE '
.
$table
.
' SET pid = site_root_id'
;
$connection
->
executeQuery
(
$sql
);
$dbQueries
[]
=
$sql
;
}
else
{
$queryBuilder
=
GeneralUtility
::
makeInstance
(
ConnectionPool
::
class
)
->
getQueryBuilderForTable
(
$table
);
$queryBuilder
->
getRestrictions
()
->
removeAll
()
->
add
(
GeneralUtility
::
makeInstance
(
DeletedRestriction
::
class
)
);
$result
=
$queryBuilder
->
select
(
'pid'
)
->
from
(
$table
)
->
groupBy
(
'pid'
)
->
execute
();
/** @var array $result */
foreach
(
$result
as
$row
)
{
$siteRootId
=
BackendService
::
getSiteRoot
(
$row
[
'pid'
]);
if
(
$siteRootId
===
0
)
{
$siteRootId
=
1
;
}
$queryBuilder
->
update
(
$table
)
->
set
(
'pid'
,
$siteRootId
)
->
where
(
'pid = '
.
$row
[
'pid'
])
->
execute
();
$dbQueries
[]
=
$queryBuilder
->
getSQL
();
}
}
...
...
@@ -180,17 +141,12 @@ class UpdatePidToSiteRoot extends AbstractUpdate {
/**
* check if site_root columns actually exist
*
* @param $table
* @param
string
$table
* @return bool
*/
private
function
siteRootColumnExists
(
$table
)
{
$connection
=
GeneralUtility
::
makeInstance
(
ConnectionPool
::
class
)
->
getConnectionForTable
(
$table
);
$result
=
$connection
->
getSchemaManager
()
->
listTableColumns
(
$table
);
if
(
\array_key_exists
(
'site_root_id'
,
$result
))
{
return
TRUE
;
}
return
FALSE
;
return
\array_key_exists
(
'site_root_id'
,
$result
);
}
}
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