Skip to content

Commit

Permalink
Merge pull request #1 from OpenSourceInternational/raw-page-dublicator
Browse files Browse the repository at this point in the history
[TASK] FS#48007 > Added page raw duplicator
  • Loading branch information
orion828 authored Jul 13, 2020
2 parents c04d352 + c3a18eb commit c1549e2
Show file tree
Hide file tree
Showing 9 changed files with 863 additions and 34 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
All notable changes to this extension will be documented in this file.

## [0.8.0] - 2020-07-13
### Added
- Pages raw duplicator

## [0.7.2] - 2020-06-22
### Fixed
- Do not display translations of pages in the list of available models
Expand Down
61 changes: 33 additions & 28 deletions Classes/Duplication/Process/PagesDuplicationProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Romm\SiteFactory\Duplication\Process;

use TYPO3\CMS\Backend\Tree\TreeNode;
use Romm\SiteFactory\Duplication\Raw\PageRawDuplicator;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use Romm\SiteFactory\Utility\PaetreeCommandsUtility;
use Romm\SiteFactory\Duplication\AbstractDuplicationProcess;
Expand All @@ -40,25 +41,25 @@ public function run()
$copyDestination = intval($this->getDuplicationData('copyDestination'));

// Testing if the values and $copyDestination is valid.

$connection = GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionForTable('pages');
$query = $connection->createQueryBuilder();
$query->getRestrictions()->removeAll();
$query->addSelectLiteral('uid')
->from('pages')
->where('deleted = 0 AND uid = ' . intval($copyDestination));
$testCopyDestination = $query->execute()->fetchAll();

if ($testCopyDestination === false) {
$this->addError(
'duplication_process.pages_duplication.error.wrong_destination_uid',
1431372959,
['d' => $copyDestination]
);

return;
}
// We don't need to check it because we must be able to copy in root.
// $connection = GeneralUtility::makeInstance(ConnectionPool::class)
// ->getConnectionForTable('pages');
// $query = $connection->createQueryBuilder();
// $query->getRestrictions()->removeAll();
// $query->addSelectLiteral('uid')
// ->from('pages')
// ->where('deleted = 0 AND uid = ' . intval($copyDestination));
// $testCopyDestination = $query->execute()->fetchAll();

// if ($testCopyDestination === false) {
// $this->addError(
// 'duplication_process.pages_duplication.error.wrong_destination_uid',
// 1431372959,
// ['d' => $copyDestination]
// );
//
// return;
// }

// Calling duplication process.
$duplicatedPageUid = $this->copyNodeToDestination($modelPageUid, $copyDestination);
Expand Down Expand Up @@ -93,15 +94,19 @@ private function copyNodeToDestination($nodeUid, $destinationUid)
$GLOBALS['BE_USER']->uc['copyLevels'] = 100;
$GLOBALS['BE_USER']->workspace = 0;

$nodeData = new \stdClass();
$nodeData->serializeClassName = TreeNode::class;
$nodeData->id = $nodeUid;
$nodeData->type = 'pages';

/** @var TreeNode $node */
$node = GeneralUtility::makeInstance(TreeNode::class, (array)$nodeData);

$duplicatedPageUid = PaetreeCommandsUtility::copyNode($node, $destinationUid);
if ($this->extensionConfiguration['useRawPageDuplicator']) {
$duplicator = $this->objectManager->get(PageRawDuplicator::class);
$duplicatedPageUid = $duplicator->copy($nodeUid, $destinationUid);
} else {
$nodeData = new \stdClass();
$nodeData->serializeClassName = TreeNode::class;
$nodeData->id = $nodeUid;
$nodeData->type = 'pages';

/** @var TreeNode $node */
$node = GeneralUtility::makeInstance(TreeNode::class, (array)$nodeData);
$duplicatedPageUid = PaetreeCommandsUtility::copyNode($node, $destinationUid);
}

//emable copied node
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
Expand Down
Loading

0 comments on commit c1549e2

Please sign in to comment.