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
1554b6a1
Commit
1554b6a1
authored
6 years ago
by
Torsten Oppermann
Browse files
Options
Downloads
Patches
Plain Diff
[TASK] implemented content element mapping
parent
fca7883e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!6
Feature news migration
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Classes/Command/MigrateNewsCommandController.php
+62
-13
62 additions, 13 deletions
Classes/Command/MigrateNewsCommandController.php
with
62 additions
and
13 deletions
Classes/Command/MigrateNewsCommandController.php
+
62
−
13
View file @
1554b6a1
...
...
@@ -28,14 +28,12 @@ namespace SGalinski\SgNews\Command;
use
SGalinski\SgNews\Domain\Model\News
;
use
TYPO3\CMS\Backend\FrontendBackendUserAuthentication
;
use
TYPO3\CMS\Backend\Utility\BackendUtility
;
use
TYPO3\CMS\Core\Database\DatabaseConnection
;
use
TYPO3\CMS\Core\DataHandling\DataHandler
;
use
TYPO3\CMS\Core\Utility\GeneralUtility
;
use
TYPO3\CMS\Extbase\Mvc\Controller\CommandController
;
use
TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
;
use
TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException
;
use
TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings
;
/**
* Command controller, that migrates data from tx_news to sg_news
...
...
@@ -60,30 +58,62 @@ class MigrateNewsCommandController extends CommandController {
protected
$newsRepository
;
/**
* @param int $copyPageId
* @param string $copyPageId
* this array maps new pages to their original entry in the tx_news table
*
* @var array $newsPagesMap
*/
protected
$newsPagesMap
=
[];
/**
* this array contains all pages that should be migrated to sg_news
*
* @var array $pagesToMigrate
*/
protected
$pagesToMigrate
=
[];
/**
* @var array $languageMap
*/
protected
$languageMap
=
[];
/**
* @param string $copyPageId the page id of the template that should be copied
* @param int $categoryPid the page id of the category page
* @param int $year only news from that year will be migrated
* @param string $languageMapAsJson a json, mapping language ids (old => new). this is needed if the sys_language_uids have changed
*
* @throws IllegalObjectTypeException
* @throws UnknownObjectException
*/
public
function
runMigrateNewsCommand
(
$copyPageId
,
$categoryPids
=
'340'
)
{
public
function
runMigrateNewsCommand
(
$copyPageId
,
$categoryPid
,
$year
=
2015
,
$languageMapAsJson
=
'{"3":1,"1":0,"2":2,"0":3}'
)
{
$this
->
languageMap
=
json_decode
(
$languageMapAsJson
,
TRUE
);
/** @var DatabaseConnection $db */
$db
=
$GLOBALS
[
'TYPO3_DB'
];
$where
=
'hidden = 0 and deleted = 0'
;
/** @var \mysqli_result $result */
$result
=
$db
->
exec_SELECTquery
(
'*'
,
'tx_news_domain_model_news'
,
$where
,
''
,
''
,
'50'
);
$result
=
$db
->
exec_SELECTquery
(
'*'
,
'tx_news_domain_model_news'
,
$where
);
$localDataHandler
=
GeneralUtility
::
makeInstance
(
DataHandler
::
class
);
$beUser
=
$this
->
simulateBackendUser
();
$localCommandMap
=
[
'pages'
=>
[
$copyPageId
=>
[
'copy'
=>
340
'copy'
=>
(
int
)
$categoryPid
]
]
];
$resultArray
=
[];
while
(
$row
=
$result
->
fetch_assoc
())
{
// ignore the entry if its not within the given year
if
((
int
)
date
(
'Y'
,
(
$row
[
'datetime'
]))
!==
$year
)
{
continue
;
}
$resultArray
[]
=
$row
;
// if no l10n_parent exists, create a copy of the page
...
...
@@ -96,6 +126,9 @@ class MigrateNewsCommandController extends CommandController {
// get the id of the new object
$newPageId
=
$localDataHandler
->
copyMappingArray
[
'pages'
][
$copyPageId
];
// make entry in news map, so we can fetch it later
$this
->
newsPagesMap
[
$row
[
'uid'
]]
=
$newPageId
;
/** @var News $newsPage */
$newsPage
=
$this
->
newsRepository
->
findByUidIgnoreEnableFields
(
$newPageId
);
...
...
@@ -109,19 +142,19 @@ class MigrateNewsCommandController extends CommandController {
$this
->
persistenceManager
->
persistAll
();
// update content element from the new page
$where
=
'
u
id = '
.
$newPageId
;
$where
=
'
p
id = '
.
$newPageId
;
$db
->
exec_UPDATEquery
(
'tt_content'
,
$where
,
[
'bodytext'
=>
$row
[
'bodytext'
]]);
}
}
else
{
// this row is a translation and should simply update the content accordingly
$this
->
updateTranslation
(
$row
);
}
return
;
}
$this
->
pagesToMigrate
=
$resultArray
;
}
/**
* Updates content element of a news translation
* Updates content element of a news translation
uid
*
* @param array $row
*/
...
...
@@ -129,8 +162,24 @@ class MigrateNewsCommandController extends CommandController {
/** @var DatabaseConnection $db */
$db
=
$GLOBALS
[
'TYPO3_DB'
];
// update content element from the new page
$where
=
'pid = '
.
$row
[
'l10n_parent'
];
// get entry in news map
$parentId
=
$this
->
newsPagesMap
[
$row
[
'l10n_parent'
]];
// get content element from the original page
$where
=
'pid = '
.
(
int
)
$parentId
;
/** @var \mysqli_result $result */
$result
=
$db
->
exec_SELECTquery
(
'l18n_parent'
,
'tt_content'
,
$where
);
$originalContentElement
=
$result
->
fetch_row
();
$where
=
'l18n_parent = '
.
(
int
)
$originalContentElement
[
0
];
// look up the correct language id, if they have changed
if
(
$this
->
languageMap
[(
int
)
$row
[
'sys_language_uid'
]])
{
$where
.
=
' AND sys_language_uid = '
.
$this
->
languageMap
[(
int
)
$row
[
'sys_language_uid'
]];
}
else
{
$where
.
=
' AND sys_language_uid = '
.
(
int
)
$row
[
'sys_language_uid'
];
}
$db
->
exec_UPDATEquery
(
'tt_content'
,
$where
,
[
'bodytext'
=>
$row
[
'bodytext'
]]);
}
...
...
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