Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Classes/ContentDefender/Xclasses/CommandMapHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/

use B13\Container\ContentDefender\ContainerColumnConfigurationService;
use B13\Container\Hooks\Datahandler\DatahandlerProcess;
use IchHabRecht\ContentDefender\Hooks\CmdmapDataHandlerHook;
use IchHabRecht\ContentDefender\Repository\ContentRepository;
use TYPO3\CMS\Core\DataHandling\DataHandler;
Expand Down Expand Up @@ -89,6 +90,12 @@ public function processCmdmap_beforeStart(DataHandler $dataHandler): void

protected function isRecordAllowedByRestriction(array $columnConfiguration, array $record): bool
{
if (isset($record['tx_container_parent']) &&
$record['tx_container_parent'] > 0 &&
(GeneralUtility::makeInstance(DatahandlerProcess::class))->isContainerInProcess($record['tx_container_parent'])
) {
return true;
}
if (isset($this->mapping[$record['uid']])) {
$columnConfiguration = $this->containerColumnConfigurationService->override(
$columnConfiguration,
Expand All @@ -101,6 +108,12 @@ protected function isRecordAllowedByRestriction(array $columnConfiguration, arra

protected function isRecordAllowedByItemsCount(array $columnConfiguration, array $record): bool
{
if (isset($record['tx_container_parent']) &&
$record['tx_container_parent'] > 0 &&
(GeneralUtility::makeInstance(DatahandlerProcess::class))->isContainerInProcess($record['tx_container_parent'])
) {
return true;
}
if (isset($this->mapping[$record['uid']])) {
return true;
}
Expand Down
13 changes: 13 additions & 0 deletions Classes/ContentDefender/Xclasses/DatamapHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/

use B13\Container\ContentDefender\ContainerColumnConfigurationService;
use B13\Container\Hooks\Datahandler\DatahandlerProcess;
use IchHabRecht\ContentDefender\Hooks\DatamapDataHandlerHook;
use IchHabRecht\ContentDefender\Repository\ContentRepository;
use TYPO3\CMS\Core\DataHandling\DataHandler;
Expand Down Expand Up @@ -90,6 +91,13 @@ public function processDatamap_beforeStart(DataHandler $dataHandler): void

protected function isRecordAllowedByRestriction(array $columnConfiguration, array $record): bool
{
if (
isset($record['tx_container_parent']) &&
$record['tx_container_parent'] > 0 &&
(GeneralUtility::makeInstance(DatahandlerProcess::class))->isContainerInProcess((int)$record['tx_container_parent'])
) {
return true;
}
if (isset($this->mapping[$record['uid']])) {
$columnConfiguration = $this->containerColumnConfigurationService->override(
$columnConfiguration,
Expand All @@ -108,6 +116,11 @@ protected function isRecordAllowedByRestriction(array $columnConfiguration, arra

protected function isRecordAllowedByItemsCount(array $columnConfiguration, array $record): bool
{
if (isset($record['tx_container_parent']) &&
$record['tx_container_parent'] > 0 &&
(GeneralUtility::makeInstance(DatahandlerProcess::class))->isContainerInProcess((int)$record['tx_container_parent'])) {
return true;
}
if (isset($this->mapping[$record['uid']])) {
return true;
}
Expand Down
2 changes: 2 additions & 0 deletions Classes/Hooks/Datahandler/CommandMapPostProcessingHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ protected function copyOrMoveChildren(int $origUid, int $newId, int $containerId
try {
// when moving or copy a container into other language the other language is returned
$container = $this->containerFactory->buildContainer($origUid);
(GeneralUtility::makeInstance(DatahandlerProcess::class))->startContainerProcess($origUid);
$children = [];
$colPosVals = $container->getChildrenColPos();
foreach ($colPosVals as $colPos) {
Expand Down Expand Up @@ -104,6 +105,7 @@ protected function copyOrMoveChildren(int $origUid, int $newId, int $containerId
$localDataHandler->start([], $cmd, $dataHandler->BE_USER);
$localDataHandler->process_cmdmap();
}
(GeneralUtility::makeInstance(DatahandlerProcess::class))->endContainerProcess($origUid);
} catch (Exception $e) {
// nothing todo
}
Expand Down
39 changes: 39 additions & 0 deletions Classes/Hooks/Datahandler/DatahandlerProcess.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace B13\Container\Hooks\Datahandler;

/*
* This file is part of TYPO3 CMS-based extension "container" by b13.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*/

use TYPO3\CMS\Core\SingletonInterface;

class DatahandlerProcess implements SingletonInterface
{
protected $containerInProcess = [];

public function isContainerInProcess(int $containerId): bool
{
return in_array($containerId, $this->containerInProcess, true);
}

public function startContainerProcess(int $containerId): void
{
if (!in_array($containerId, $this->containerInProcess, true)) {
$this->containerInProcess[] = $containerId;
}
}

public function endContainerProcess(int $containerId): void
{
if (in_array($containerId, $this->containerInProcess, true)) {
$this->containerInProcess = array_diff([$containerId], $this->containerInProcess);
}
}
}
29 changes: 29 additions & 0 deletions Tests/Functional/Datahandler/ContentDefender/CopyContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,33 @@ public function copyContainerIntoOtherContainerWithSameColPosCopiesAlsoChildEven
self::assertSame($row['uid'], (int)$child['tx_container_parent'], 'child is not copied into copied container');
self::assertSame(200, (int)$row['colPos'], 'child is not copied into container colPos');
}

/**
* @test
* @group content_defender
*/
public function copyContainerWithRestrictionsIgnoresContentDefender(): void
{
$this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/container/Tests/Functional/Datahandler/ContentDefender/Fixtures/copy_container_with_restrictions.csv');
$cmdmap = [
'tt_content' => [
11 => [
'copy' => [
'action' => 'paste',
'target' => 2,
'update' => [
'colPos' => 0,
],
],
],
],
];

$this->dataHandler->start([], $cmdmap, $this->backendUser);
$this->dataHandler->process_cmdmap();
$container = $this->fetchOneRecord('t3_origuid', 11);
$row = $this->fetchOneRecord('t3_origuid', 13);
self::assertSame($container['uid'], (int)$row['tx_container_parent'], 'element is not copied into container');
self::assertSame(201, (int)$row['colPos'], 'element is not copied into container colPos');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"pages"
,"uid","pid"
,2,0
"tt_content"
,"uid","pid","colPos","sorting","CType","tx_container_parent"
,11,2,0,128,"b13-2cols-with-header-container",0
,12,2,200,256,"header",11
,13,2,201,512,"bullets",11