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
fca7883e
Commit
fca7883e
authored
6 years ago
by
Torsten Oppermann
Browse files
Options
Downloads
Patches
Plain Diff
[TASk] Implemented pagy copying, working on content translations
parent
97109bc7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!6
Feature news migration
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Classes/Command/MigrateNewsCommandController.php
+50
-16
50 additions, 16 deletions
Classes/Command/MigrateNewsCommandController.php
Classes/Domain/Repository/NewsRepository.php
+23
-3
23 additions, 3 deletions
Classes/Domain/Repository/NewsRepository.php
with
73 additions
and
19 deletions
Classes/Command/MigrateNewsCommandController.php
+
50
−
16
View file @
fca7883e
...
...
@@ -28,10 +28,13 @@ 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
;
/**
...
...
@@ -58,13 +61,16 @@ class MigrateNewsCommandController extends CommandController {
/**
* @param int $copyPageId
* @param string $copyPageId
* @throws IllegalObjectTypeException
* @throws UnknownObjectException
*/
public
function
runMigrateNewsCommand
(
$copyPageId
)
{
public
function
runMigrateNewsCommand
(
$copyPageId
,
$categoryPids
=
'340'
)
{
/** @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
,
''
,
''
);
$result
=
$db
->
exec_SELECTquery
(
'*'
,
'tx_news_domain_model_news'
,
$where
,
''
,
''
,
'50'
);
$localDataHandler
=
GeneralUtility
::
makeInstance
(
DataHandler
::
class
);
$beUser
=
$this
->
simulateBackendUser
();
...
...
@@ -80,32 +86,60 @@ class MigrateNewsCommandController extends CommandController {
while
(
$row
=
$result
->
fetch_assoc
())
{
$resultArray
[]
=
$row
;
$localDataHandler
->
start
([],
$localCommandMap
,
$beUser
);
$localDataHandler
->
bypassAccessCheckForRecords
=
TRUE
;
$localDataHandler
->
checkModifyAccessList
(
'pages'
);
$localDataHandler
->
process_cmdmap
();
// if no l10n_parent exists, create a copy of the page
if
((
int
)
$row
[
'l10n_parent'
]
===
0
)
{
$localDataHandler
->
start
([],
$localCommandMap
,
$beUser
);
$localDataHandler
->
bypassAccessCheckForRecords
=
TRUE
;
$localDataHandler
->
checkModifyAccessList
(
'pages'
);
$localDataHandler
->
process_cmdmap
();
// get the id of the new object
$newPageId
=
$localDataHandler
->
copyMappingArray
[
'pages'
][
$copyPageId
];
// get the id of the new object
$newPageId
=
$localDataHandler
->
copyMappingArray
[
'pages'
][
$copyPageId
];
/** @var $querySettings \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings */
$querySettings
=
$this
->
objectManager
->
get
(
Typo3QuerySettings
::
class
);
$querySettings
->
setIgnoreEnableFields
(
TRUE
);
/** @var News $newsPage */
$newsPage
=
$this
->
newsRepository
->
findByUidIgnoreEnableFields
(
$newPageId
);
$this
->
persistenceManager
->
persistAll
();
$this
->
newsRepository
->
setDefaultQuerySettings
(
$querySettings
);
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'
]);
/** @var News $newsPage */
$newsPage
=
$this
->
newsRepository
->
findByUid
(
$newPageId
);
$this
->
newsRepository
->
update
(
$newsPage
);
$this
->
persistenceManager
->
persistAll
();
// update content element from the new page
$where
=
'uid = '
.
$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
;
}
}
/**
* Updates content element of a news translation
*
* @param array $row
*/
private
function
updateTranslation
(
array
$row
)
{
/** @var DatabaseConnection $db */
$db
=
$GLOBALS
[
'TYPO3_DB'
];
// update content element from the new page
$where
=
'pid = '
.
$row
[
'l10n_parent'
];
$db
->
exec_UPDATEquery
(
'tt_content'
,
$where
,
[
'bodytext'
=>
$row
[
'bodytext'
]]);
}
/**
* Simulate Backend User for DataHandler
*
* @return FrontendBackendUserAuthentication
*/
p
ublic
function
simulateBackendUser
()
{
p
rivate
function
simulateBackendUser
()
{
/** @var \TYPO3\CMS\Backend\FrontendBackendUserAuthentication $BE_USER */
$BE_USER
=
GeneralUtility
::
makeInstance
(
FrontendBackendUserAuthentication
::
class
);
$BE_USER
->
setBeUserByName
(
'admin'
);
...
...
This diff is collapsed.
Click to expand it.
Classes/Domain/Repository/NewsRepository.php
+
23
−
3
View file @
fca7883e
...
...
@@ -215,9 +215,11 @@ class NewsRepository extends AbstractRepository {
$onlyHighlighted
=
FALSE
,
array
$categoryIds
=
NULL
,
$hideNeverHighlightedNews
=
FALSE
,
$sortBy
=
'date'
,
array
$tagIds
=
NULL
,
$startTime
=
0
,
$endTime
=
0
):
int
{
return
$this
->
getCount
(
$this
->
getQueryForLastUpdatedOrHighlightedNewsByCategories
(
0
,
$onlyHighlighted
,
$categoryIds
,
0
,
$hideNeverHighlightedNews
,
$sortBy
,
$tagIds
,
$startTime
,
$endTime
));
return
$this
->
getCount
(
$this
->
getQueryForLastUpdatedOrHighlightedNewsByCategories
(
0
,
$onlyHighlighted
,
$categoryIds
,
0
,
$hideNeverHighlightedNews
,
$sortBy
,
$tagIds
,
$startTime
,
$endTime
)
);
}
/**
...
...
@@ -452,4 +454,22 @@ class NewsRepository extends AbstractRepository {
return
$this
->
getCount
(
$query
);
}
/**
* Find news record by uid, but with ignoring enable fields
*
* @param int $uid
* @return object
*/
public
function
findByUidIgnoreEnableFields
(
$uid
)
{
$query
=
$this
->
createQuery
();
/** @var $querySettings \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings */
$querySettings
=
$query
->
getQuerySettings
();
$querySettings
->
setIgnoreEnableFields
(
TRUE
);
$querySettings
->
setRespectStoragePage
(
FALSE
);
$query
->
setQuerySettings
(
$querySettings
);
$query
->
matching
(
$query
->
equals
(
'uid'
,
$uid
));
return
$query
->
execute
()
->
getFirst
();
}
}
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