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
fe3c5bcd
Commit
fe3c5bcd
authored
6 years ago
by
Torsten Oppermann
Browse files
Options
Downloads
Patches
Plain Diff
[TASK] Implementing cateegory map, reespecting corect title & ceategory translations
parent
414b9a1f
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
+49
-25
49 additions, 25 deletions
Classes/Command/MigrateNewsCommandController.php
with
49 additions
and
25 deletions
Classes/Command/MigrateNewsCommandController.php
+
49
−
25
View file @
fe3c5bcd
...
...
@@ -83,20 +83,28 @@ class MigrateNewsCommandController extends CommandController {
*/
protected
$languageMap
=
[];
/**
* @var array $languageMap
*/
protected
$categoryMap
=
[];
/**
* @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
* @param string $categoryMapAsJson a json, mapping sys_category ids (old => new). t
*
* @throws IllegalObjectTypeException
* @throws UnknownObjectException
*/
public
function
runMigrateNewsCommand
(
$copyPageId
,
$categoryPid
,
$year
=
2015
,
$languageMapAsJson
=
'{"3":1,"1":0,"2":2,"0":3}'
$languageMapAsJson
=
'{"3":1,"1":0,"2":2,"0":3}'
,
$categoryMapAsJson
=
'{"2":10,"3":11,"4":12,"5":13,"6":14,"7":15,"8":16,"9":17}'
)
{
$this
->
languageMap
=
json_decode
(
$languageMapAsJson
,
TRUE
);
$this
->
categoryMap
=
json_decode
(
$categoryMapAsJson
,
TRUE
);
/** @var DatabaseConnection $db */
$db
=
$GLOBALS
[
'TYPO3_DB'
];
...
...
@@ -121,7 +129,6 @@ class MigrateNewsCommandController extends CommandController {
if
((
int
)
date
(
'Y'
,
(
$row
[
'datetime'
]))
!==
$year
)
{
continue
;
}
$resultArray
[]
=
$row
;
// if no l10n_parent exists, create a copy of the page
...
...
@@ -141,11 +148,13 @@ class MigrateNewsCommandController extends CommandController {
$newsPage
=
$this
->
newsRepository
->
findByUidIgnoreEnableFields
(
$newPageId
);
if
(
$newsPage
!==
NULL
)
{
// @todo create tt content element, map images, author, categories etc.
$title
=
date
(
'Y-m-d'
,
$row
[
'datetime'
])
.
' - '
.
$row
[
'title'
];
$newsPage
->
setTitle
(
$title
);
$newsPage
->
setAuthor
(
$row
[
'author'
]);
$newsPage
->
addTag
(
$this
->
getMatchingTag
(
$row
));
$matchingTag
=
$this
->
getMatchingTag
(
$row
);
if
(
$matchingTag
&&
$matchingTag
instanceof
Tag
)
{
$newsPage
->
addTag
(
$matchingTag
);
}
$this
->
newsRepository
->
update
(
$newsPage
);
$this
->
persistenceManager
->
persistAll
();
...
...
@@ -162,32 +171,20 @@ class MigrateNewsCommandController extends CommandController {
/**
* @param array $row
* @return
Tag
$tag
* @return
Object
$tag
*
* @throws IllegalObjectTypeException
* @throws UnknownObjectException
*/
private
function
getMatchingTag
(
array
$row
)
{
/** @var Tag $matchingTag */
$matchingTag
=
$this
->
tagRepository
->
findByUid
((
int
)
$row
[
'categories'
]);
if
(
$matchingTag
===
NULL
)
{
$matchingTag
=
$this
->
objectManager
->
get
(
Tag
::
class
);
/** @var DatabaseConnection $db */
$db
=
$GLOBALS
[
'TYPO3_DB'
];
$where
=
'uid = '
.
$row
[
'categories'
];
/** @var \mysqli_result $result */
$result
=
$db
->
exec_SELECTquery
(
'title'
,
'sys_category'
,
$where
);
$matchingTag
->
setTitle
(
$result
->
fetch_row
()[
0
]);
$matchingTag
->
setPid
(
1
);
$this
->
tagRepository
->
add
(
$matchingTag
);
// look up the correct category id, if they have changed
if
(
isset
(
$this
->
categoryMap
[(
int
)
$row
[
'categories'
]]))
{
$categoryId
=
$this
->
categoryMap
[(
int
)
$row
[
'categories'
]];
}
else
{
$categoryId
=
(
int
)
$row
[
'categories'
];
}
$this
->
persistenceManager
->
persistAll
();
return
$matchingTag
;
return
$this
->
tagRepository
->
findByUid
(
$categoryId
);
}
/**
...
...
@@ -209,7 +206,7 @@ class MigrateNewsCommandController extends CommandController {
$result
=
$db
->
exec_SELECTquery
(
'l18n_parent'
,
'tt_content'
,
$where
);
$originalContentElement
=
$result
->
fetch_row
();
// if its the new defaul, there is no l18n_parent
// if its the new defaul
t
, there is no l18n_parent
if
((
int
)
$this
->
languageMap
[(
int
)
$row
[
'sys_language_uid'
]
===
0
])
{
$where
=
'uid = '
.
(
int
)
$originalContentElement
[
0
];
}
else
{
...
...
@@ -224,6 +221,33 @@ class MigrateNewsCommandController extends CommandController {
}
$db
->
exec_UPDATEquery
(
'tt_content'
,
$where
,
[
'bodytext'
=>
$row
[
'bodytext'
]]);
// possibly the default language needs to be overwritten and the old default translation needs to be preserved
if
(
isset
(
$this
->
languageMap
[(
int
)
$row
[
'sys_language_uid'
]])
&&
$this
->
languageMap
[(
int
)
$row
[
'sys_language_uid'
]]
===
0
)
{
$where
=
'uid = '
.
(
int
)
$parentId
;
/** @var \mysqli_result $result */
$result
=
$db
->
exec_SELECTquery
(
'title'
,
'pages'
,
$where
);
$where
=
'pid = '
.
(
int
)
$parentId
.
' AND sys_language_uid = '
.
$this
->
languageMap
[
0
];
$db
->
exec_UPDATEquery
(
'pages_language_overlay'
,
$where
,
[
'title'
=>
$result
->
fetch_row
()[
0
]]);
$where
=
'uid = '
.
(
int
)
$parentId
;
$db
->
exec_UPDATEquery
(
'pages'
,
$where
,
[
'title'
=>
date
(
'Y-m-d'
,
$row
[
'datetime'
])
.
' - '
.
$row
[
'title'
]]
);
}
else
{
// finally translate the page title if necessary
if
(
isset
(
$this
->
languageMap
[(
int
)
$row
[
'sys_language_uid'
]])
&&
$this
->
languageMap
[(
int
)
$row
[
'sys_language_uid'
]]
>
0
)
{
$where
=
'pid = '
.
(
int
)
$parentId
.
' AND sys_language_uid = '
.
$this
->
languageMap
[(
int
)
$row
[
'sys_language_uid'
]];
}
else
{
$where
=
'pid = '
.
(
int
)
$parentId
.
' AND sys_language_uid = '
.
(
int
)
$row
[
'sys_language_uid'
];
}
}
$db
->
exec_UPDATEquery
(
'pages_language_overlay'
,
$where
,
[
'title'
=>
date
(
'Y-m-d'
,
$row
[
'datetime'
])
.
' - '
.
$row
[
'title'
]]
);
}
/**
...
...
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