Skip to content
Snippets Groups Projects
Commit b689e245 authored by Torsten Oppermann's avatar Torsten Oppermann
Browse files

[TASk] First draft of command controller

parent ae08347b
No related branches found
No related tags found
1 merge request!6Feature news migration
<?php
namespace SGalinski\SgNews\Command;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (https://www.sgalinski.de)
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use SGalinski\SgNews\Domain\Model\News;
use SGalinski\SgNews\Service\DataHandler;
use TYPO3\CMS\Backend\FrontendBackendUserAuthentication;
use TYPO3\CMS\Core\Database\DatabaseConnection;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\CommandController;
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
/**
* Command controller, that migrates data from tx_news to sg_news
*/
class MigrateNewsCommandController extends CommandController {
/**
* @var bool
*/
protected $requestAdminPermissions = TRUE;
/**
* @var \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager
* @inject
*/
protected $persistenceManager;
/**
* @var \SGalinski\SgNews\Domain\Repository\NewsRepository
* @inject
*/
protected $newsRepository;
/**
* @param int $copyPageId
*/
public function runMigrateNewsCommand($copyPageId) {
/** @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, '', '');
$localDataHandler = GeneralUtility::makeInstance(DataHandler::class);
$beUser = $this->simulateBackendUser();
$localCommandMap = [
'pages' => [
$copyPageId => [
'copy' => 340
]
]
];
$resultArray = [];
while ($row = $result->fetch_assoc()) {
$resultArray[] = $row;
$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];
/** @var $querySettings \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings */
$querySettings = $this->objectManager->get(Typo3QuerySettings::class);
$querySettings->setIgnoreEnableFields(TRUE);
$this->persistenceManager->persistAll();
$this->newsRepository->setDefaultQuerySettings($querySettings);
/** @var News $newsPage */
$newsPage = $this->newsRepository->findByUid($newPageId);
return;
}
}
/**
* Simulate Backend User for DataHandler
*/
public function simulateBackendUser() {
/** @var \TYPO3\CMS\Backend\FrontendBackendUserAuthentication $BE_USER */
$BE_USER = GeneralUtility::makeInstance(FrontendBackendUserAuthentication::class);
$BE_USER->setBeUserByName('admin');
if ($BE_USER->user['uid']) {
$BE_USER->fetchGroupData();
}
$BE_USER->uc_default['copyLevels'] = '9999';
$BE_USER->uc = $BE_USER->uc_default;
$GLOBALS['PAGES_TYPES'][254]['allowedTables'] = '*';
return $BE_USER;
}
}
......@@ -98,4 +98,9 @@ if(!is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawHeaderHook'] = [];
}
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawHeaderHook'][] =
\SGalinski\SgNews\Hooks\PageLayoutController::class . '->addNewsModuleLink';
\ No newline at end of file
\SGalinski\SgNews\Hooks\PageLayoutController::class . '->addNewsModuleLink';
// register command controllers
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] =
'SGalinski\SgNews\Command\MigrateNewsCommandController';
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment