Project

General

Profile

Bug #88054 » PageRepository.php

Danilo Caccialanza, 2020-05-28 11:08

 
<?php
/**
*
*
*
* This program 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.
*
* This program 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace TICH\TichPatch\Rewrites\Core\Frontend\Page;

use PDO;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\EndTimeRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\FrontendGroupRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\FrontendWorkspaceRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\StartTimeRestriction;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Versioning\VersionState;

class PageRepository extends \TYPO3\CMS\Frontend\Page\PageRepository
{
/** @var \TICH\TichPatch\Utility\GeneralUtility */
private static $_instance = null;

/**
* Checks if record is a move-placeholder
* (t3ver_state==VersionState::MOVE_PLACEHOLDER) and if so it will set $row to be
* the pointed-to live record (and return TRUE) Used from versionOL
*
* @param string $table Table name
* @param array $row Row (passed by reference) - only online records...
*
* @return bool TRUE if overlay is made.
* @see BackendUtility::movePlhOl()
*/
public function movePlhOL($table, &$row)
{

if (!$this->isBugfixActive()) {
return parent::movePlhOL($table, $row);
}

if (!empty($GLOBALS['TCA'][$table]['ctrl']['versioningWS'])
&& (int)VersionState::cast($row['t3ver_state'])->equals(VersionState::MOVE_PLACEHOLDER)
) {
// If t3ver_move_id is not found, then find it (but we like best if it is here)
if (!isset($row['t3ver_move_id'])) {
$moveIDRec = $this->getRawRecord($table, $row['uid'], 't3ver_move_id', true);
$moveID = $moveIDRec['t3ver_move_id'];
} else {
$moveID = $row['t3ver_move_id'];
}

// Find pointed-to record.
if ($moveID) {

/** @var QueryBuilder $queryBuilder */
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);

//WF: start patch
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(FrontendWorkspaceRestriction::class))
->add(GeneralUtility::makeInstance(StartTimeRestriction::class))
->add(GeneralUtility::makeInstance(EndTimeRestriction::class))
->add(GeneralUtility::makeInstance(FrontendGroupRestriction::class));

//WF: end patch (replaced FrontendRestrictionContainer with single restrictions)
//$queryBuilder->setRestrictions(GeneralUtility::makeInstance(FrontendRestrictionContainer::class));

$select = $queryBuilder->select(...array_keys($this->purgeComputedProperties($row)))
->from($table)
->where(
$queryBuilder->expr()->eq(
'uid',
$queryBuilder->createNamedParameter($moveID, PDO::PARAM_INT)
)
);

$origRow = $select
->setMaxResults(1)
->execute()
->fetch();

if ($origRow) {
$row = $origRow;
return true;
}
}
}
return false;
}


private function isBugfixActive()
{
return $this->getUtil()->isPreviewFixPatchActive();
}

/**
* Return instance
*
* @return \TICH\TichPatch\Utility\GeneralUtility
*/
private function getUtil()
{
if (self::$_instance == null) {
self::$_instance = GeneralUtility::makeInstance(\TICH\TichPatch\Utility\GeneralUtility::class);
}
return self::$_instance;
}
}
(3-3/3)