Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sg_news
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD 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_news
Commits
6aee664b
Commit
6aee664b
authored
4 years ago
by
Kevin Ditscheid
Browse files
Options
Downloads
Patches
Plain Diff
[BUGFIX] Replace AbstractUpdate class
parent
d40c1409
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!25
Feature upgrade to typo3 10
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Classes/Updates/UpdateAuthors.php
+57
-53
57 additions, 53 deletions
Classes/Updates/UpdateAuthors.php
with
57 additions
and
53 deletions
Classes/Updates/UpdateAuthors.php
+
57
−
53
View file @
6aee664b
...
...
@@ -31,57 +31,58 @@ use TYPO3\CMS\Backend\Utility\BackendUtility;
use
TYPO3\CMS\Core\Database\ConnectionPool
;
use
TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
;
use
TYPO3\CMS\Core\Utility\GeneralUtility
;
use
TYPO3\CMS\Install\Updates\AbstractUpdate
;
use
TYPO3\CMS\Install\Updates\DatabaseUpdatedPrerequisite
;
use
TYPO3\CMS\Install\Updates\UpgradeWizardInterface
;
/**
* Migrate template db entries to the correct root pages
*/
class
UpdateAuthors
extends
AbstractUpdate
{
class
UpdateAuthors
implements
UpgradeWizardInterface
{
/**
* @var string
* Retrieves the next site root in the page hierarchy from the current page
*
* @param int $currentPid
* @return int
*/
protected
$identifier
=
'tx_sgnews_update_authors'
;
protected
function
getSiteRoot
(
$currentPid
):
int
{
$rootLine
=
BackendUtility
::
BEgetRootLine
((
int
)
$currentPid
);
$siteRoot
=
[
'uid'
=>
0
];
foreach
(
$rootLine
as
$page
)
{
if
((
int
)
$page
[
'is_siteroot'
]
===
1
)
{
$siteRoot
=
$page
;
break
;
}
}
return
$siteRoot
[
'uid'
];
}
/**
* @
var
string
* @
return
string
*/
protected
$title
=
'Migrate all news authors to the new author table for each site root.'
;
public
function
getIdentifier
():
string
{
return
'tx_sgnews_update_authors'
;
}
/**
* Checks whether updates are required.
*
* @param string &$description The description for the update
* @return bool Whether an update is required (TRUE) or not (FALSE)
* @return string
*/
public
function
checkForUpdate
(
&
$description
)
{
$description
=
'Create new author entries for the old author field of news pages'
;
$queryBuilder
=
GeneralUtility
::
makeInstance
(
ConnectionPool
::
class
)
->
getQueryBuilderForTable
(
'pages'
);
$queryBuilder
->
getRestrictions
()
->
removeAll
()
->
add
(
GeneralUtility
::
makeInstance
(
DeletedRestriction
::
class
));
$rowCount
=
$queryBuilder
->
select
(
'*'
)
->
from
(
'pages'
)
->
where
(
$queryBuilder
->
expr
()
->
andX
(
$queryBuilder
->
expr
()
->
eq
(
'doktype'
,
News
::
DOK_TYPE_NEWS
),
$queryBuilder
->
expr
()
->
isNotNull
(
'author'
)
)
)
->
execute
()
->
rowCount
();
return
$rowCount
>
0
;
public
function
getTitle
():
string
{
return
'Migrate all news authors to the new author table for each site root.'
;
}
/**
* Performs the according updates.
*
* @param array &$dbQueries Queries done in this update
* @param mixed &$customMessages Custom messages
* @return bool Whether everything went smoothly or not
* @return string
*/
public
function
performUpdate
(
array
&
$dbQueries
,
&
$customMessages
)
{
$dbQueries
=
[];
public
function
getDescription
():
string
{
return
'Create new author entries for the old author field of news pages'
;
}
/**
* @return bool
*/
public
function
executeUpdate
():
bool
{
$newsQueryBuilder
=
GeneralUtility
::
makeInstance
(
ConnectionPool
::
class
)
->
getQueryBuilderForTable
(
'pages'
);
$newsQueryBuilder
->
getRestrictions
()
->
removeAll
()
->
add
(
GeneralUtility
::
makeInstance
(
DeletedRestriction
::
class
));
$newsEntries
=
$newsQueryBuilder
->
select
(
'*'
)
...
...
@@ -94,7 +95,6 @@ class UpdateAuthors extends AbstractUpdate {
)
->
execute
()
->
fetchAll
();
if
(
count
(
$newsEntries
)
<=
0
)
{
$this
->
markWizardAsDone
();
return
TRUE
;
}
foreach
(
$newsEntries
as
$news
)
{
...
...
@@ -127,8 +127,6 @@ class UpdateAuthors extends AbstractUpdate {
'crdate'
=>
time
(),
'tstamp'
=>
time
(),
])
->
execute
();
$dbQueries
[]
=
$authorQueryBuilder
->
getSQL
();
$authorUid
=
(
int
)
$authorQueryBuilder
->
getConnection
()
->
lastInsertId
();
}
else
{
$authorUid
=
$author
[
0
][
'uid'
];
...
...
@@ -139,30 +137,36 @@ class UpdateAuthors extends AbstractUpdate {
->
set
(
'author'
,
''
)
->
where
(
$newsQueryBuilder
->
expr
()
->
eq
(
'uid'
,
$news
[
'uid'
]))
->
execute
();
$dbQueries
[]
=
$newsQueryBuilder
->
getSQL
();
}
$this
->
markWizardAsDone
();
return
TRUE
;
}
/**
* Retrieves the next site root in the page hierarchy from the current page
*
* @param int $currentPid
* @return int
* @return bool
*/
protected
function
getSiteRoot
(
$currentPid
):
int
{
$rootLine
=
BackendUtility
::
BEgetRootLine
((
int
)
$currentPid
);
$siteRoot
=
[
'uid'
=>
0
];
public
function
updateNecessary
():
bool
{
$queryBuilder
=
GeneralUtility
::
makeInstance
(
ConnectionPool
::
class
)
->
getQueryBuilderForTable
(
'pages'
);
$queryBuilder
->
getRestrictions
()
->
removeAll
()
->
add
(
GeneralUtility
::
makeInstance
(
DeletedRestriction
::
class
));
$rowCount
=
$queryBuilder
->
select
(
'*'
)
->
from
(
'pages'
)
->
where
(
$queryBuilder
->
expr
()
->
andX
(
$queryBuilder
->
expr
()
->
eq
(
'doktype'
,
News
::
DOK_TYPE_NEWS
),
$queryBuilder
->
expr
()
->
isNotNull
(
'author'
)
)
)
->
execute
()
->
rowCount
();
foreach
(
$rootLine
as
$page
)
{
if
((
int
)
$page
[
'is_siteroot'
]
===
1
)
{
$siteRoot
=
$page
;
break
;
}
}
return
$rowCount
>
0
;
}
return
$siteRoot
[
'uid'
];
/**
* @return array|string[]
*/
public
function
getPrerequisites
():
array
{
return
[
DatabaseUpdatedPrerequisite
::
class
];
}
}
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