Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Localization in flux:grid columns #1331

Closed
wants to merge 1 commit into from
Closed
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
36 changes: 36 additions & 0 deletions Classes/Backend/Controller/LocalizationController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
namespace FluidTYPO3\Flux\Backend\Controller;

/*
* This file is part of the FluidTYPO3/Flux project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/


use FluidTYPO3\Flux\Backend\Domain\Repository\LocalizationRepository;
use FluidTYPO3\Flux\Utility\CompatibilityRegistry;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* LocalizationController handles the AJAX requests for record localization
*/
class LocalizationController extends \TYPO3\CMS\Backend\Controller\Page\LocalizationController
{
/**
* @var LocalizationRepository
*/
protected $localizationRepository;

/**
* Constructor
*/
public function __construct()
{
parent::__construct();

// Overwrite the localizationRepository to the flux related one
$this->localizationRepository = GeneralUtility::makeInstance(CompatibilityRegistry::get(\FluidTYPO3\Flux\Backend\Domain\Repository\LocalizationRepository::class));
}
}
83 changes: 83 additions & 0 deletions Classes/Backend/Domain/Repository/LegacyLocalizationRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
namespace FluidTYPO3\Flux\Backend\Domain\Repository;

/*
* This file is part of the FluidTYPO3/Flux project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/


use FluidTYPO3\Flux\Service\ContentService;
use FluidTYPO3\Flux\Utility\CompatibilityRegistry;

/**
* Repository for record localizations legacy version for TYPO3 7.6
*/
class LegacyLocalizationRepository extends LocalizationRepository
{
/**
* Get records for copy process
* We must use a legacy class, because the result of this method
* is in TYPO3 7.6 a mysqli_result object and in TYPO3 8 it's a \Doctrine\DBAL\Driver\Statement
*
* @param int $pageId
* @param int $colPos
* @param int $destLanguageId
* @param int $languageId
* @param string $fields
*
* @return bool|\mysqli_result|object
* @throws \InvalidArgumentException
*/
public function getRecordsToCopyDatabaseResult($pageId, $colPos, $destLanguageId, $languageId, $fields = '*')
{
if ($colPos < ContentService::COLPOS_FLUXCONTENT) {
return parent::getRecordsToCopyDatabaseResult($pageId, $colPos, $destLanguageId, $languageId, $fields);
}

// here starts the flux related code
$db = $this->getDatabaseConnection();

list($fluxParent, $fluxColumn) = $this->contentService->getTargetAreaStoredInSession($colPos);
$fluxColumn = '\'' . $this->getDatabaseConnection()->quoteStr($fluxColumn, 'tt_content') . '\'';
$fluxParent = (integer) $fluxParent;
$pageId = (integer) $pageId;

$record = $db->exec_SELECTgetSingleRow('*','tt_content','uid = ' . $fluxParent . $this->getExcludeQueryPart());
$fluxParentParent = (integer) $record[CompatibilityRegistry::get(ContentService::LANGUAGE_SOURCE_FIELD)];
// Get original uid of existing elements triggered language / colpos
$originalUids = $db->exec_SELECTgetRows(
't3_origuid',
'tt_content',
'sys_language_uid=' . (integer) $destLanguageId
. ' AND tt_content.colPos = ' . ContentService::COLPOS_FLUXCONTENT
. ' AND tt_content.tx_flux_parent = ' . $fluxParent
. ' AND tt_content.tx_flux_column = ' .$fluxColumn
. ' AND tt_content.pid=' . $pageId
. $this->getExcludeQueryPart(),
'',
'',
'',
't3_origuid'
);
$originalUidList = $db->cleanIntList(implode(',', array_keys($originalUids)));

$res = $db->exec_SELECTquery(
$fields,
'tt_content',
'tt_content.sys_language_uid=' . (integer) $languageId
. ' AND tt_content.colPos = ' . ContentService::COLPOS_FLUXCONTENT
. ' AND tt_content.tx_flux_parent = ' . $fluxParentParent
. ' AND tt_content.tx_flux_column = ' .$fluxColumn
. ' AND tt_content.pid=' . $pageId
. ' AND tt_content.uid NOT IN (' . $originalUidList . ')'
. $this->getExcludeQueryPart(),
'',
'tt_content.sorting'
);

return $res;
}
}
258 changes: 258 additions & 0 deletions Classes/Backend/Domain/Repository/LocalizationRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
<?php
namespace FluidTYPO3\Flux\Backend\Domain\Repository;

/*
* This file is part of the FluidTYPO3/Flux project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/


use FluidTYPO3\Flux\Service\ContentService;
use FluidTYPO3\Flux\Utility\CompatibilityRegistry;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;

/**
* Repository for record localizations
*/
class LocalizationRepository extends \TYPO3\CMS\Backend\Domain\Repository\Localization\LocalizationRepository
{
/**
* @var ContentService
*/
protected $contentService;

public function __construct()
{
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$this->contentService = $objectManager->get(ContentService::class);
}

/**
* Fetch the language from which the records of a colPos in a certain language were initially localized
*
* @param int $pageId
* @param int $colPos
* @param int $localizedLanguage
*
* @return array|false
*/
public function fetchOriginLanguage($pageId, $colPos, $localizedLanguage)
{
if ($colPos <= ContentService::COLPOS_FLUXCONTENT) {
parent::fetchOriginLanguage($pageId, $colPos, $localizedLanguage);
}

// here starts the flux related code
list($fluxParent, $fluxColumn) = $this->contentService->getTargetAreaStoredInSession($colPos);
$db = $this->getDatabaseConnection();

$record = $db->exec_SELECTgetSingleRow(
'tt_content_orig.sys_language_uid',
'tt_content,tt_content AS tt_content_orig,sys_language',
'tt_content.colPos = ' . ContentService::COLPOS_FLUXCONTENT
. ' AND tt_content.tx_flux_parent = ' . (integer)$fluxParent
. ' AND tt_content.tx_flux_column = \'' . $this->getDatabaseConnection()->quoteStr($fluxColumn,
'tt_content') . '\''
. ' AND tt_content.pid = ' . (int)$pageId
. ' AND tt_content.sys_language_uid = ' . (int)$localizedLanguage
. ' AND tt_content.' . CompatibilityRegistry::get(ContentService::LANGUAGE_SOURCE_FIELD) . ' = tt_content_orig.uid'
. ' AND tt_content_orig.sys_language_uid=sys_language.uid'
. $this->getExcludeQueryPart()
. $this->getAllowedLanguagesForBackendUser(),
'tt_content_orig.sys_language_uid'
);

return $record;
}

/**
* @param int $pageId
* @param int $colPos
* @param int $languageId
*
* @return int
*/
public function getLocalizedRecordCount($pageId, $colPos, $languageId)
{
if ($colPos <= ContentService::COLPOS_FLUXCONTENT) {
return parent::getLocalizedRecordCount($pageId, $colPos, $languageId);
}

// here starts the flux related code
list($fluxParent, $fluxColumn) = $this->contentService->getTargetAreaStoredInSession($colPos);
$db = $this->getDatabaseConnection();

$record = $db->exec_SELECTgetSingleRow('*', 'tt_content',
'uid = ' . (integer)$fluxParent . $this->getExcludeQueryPart() . $this->getAllowedLanguagesForBackendUser());

$rows = false;
if ($record !== null) {

$rows = (int)$db->exec_SELECTcountRows(
'uid',
'tt_content',
'tt_content.sys_language_uid=' . (integer)$languageId
. ' AND tt_content.colPos = ' . ContentService::COLPOS_FLUXCONTENT
. ' AND tt_content.tx_flux_parent = ' . (integer)$fluxParent
. ' AND tt_content.tx_flux_column = \'' . $this->getDatabaseConnection()->quoteStr($fluxColumn,
'tt_content') . '\''
. ' AND tt_content.pid=' . (integer)$pageId
. ' AND tt_content.' . CompatibilityRegistry::get(ContentService::LANGUAGE_SOURCE_FIELD) . ' <> 0'
. $this->getExcludeQueryPart()
);
}
return $rows;
}

/**
* Fetch all available languages
*
* @param int $pageId
* @param int $colPos
* @param int $languageId
*
* @return array
* @throws \InvalidArgumentException
*/
public function fetchAvailableLanguages($pageId, $colPos, $languageId)
{
if ($colPos <= ContentService::COLPOS_FLUXCONTENT) {
return parent::fetchAvailableLanguages($pageId, $colPos, $languageId);
}

// here starts the flux related code
list($fluxParent, $fluxColumn) = $this->contentService->getTargetAreaStoredInSession($colPos);
$result = $this->getDatabaseConnection()->exec_SELECTgetRows(
'sys_language.uid',
'tt_content,sys_language',
'tt_content.sys_language_uid=sys_language.uid'
. ' AND tt_content.colPos = ' . ContentService::COLPOS_FLUXCONTENT
. ' AND tt_content.tx_flux_parent = ' . (integer)$fluxParent
. ' AND tt_content.tx_flux_column = \'' . $this->getDatabaseConnection()->quoteStr($fluxColumn, 'tt_content') . '\''
. ' AND tt_content.pid = ' . (int)$pageId
. ' AND sys_language.uid <> ' . (int)$languageId
. $this->getExcludeQueryPart()
. $this->getAllowedLanguagesForBackendUser(),
'sys_language.uid',
'sys_language.title'
);

return $result;
}

/**
* /**
* Get records for copy process
*
* @param int $pageId
* @param int $colPos
* @param int $destLanguageId
* @param int $languageId
* @param string $fields
*
* @return \Doctrine\DBAL\Driver\Statement
* @throws \InvalidArgumentException
*/
public function getRecordsToCopyDatabaseResult($pageId, $colPos, $destLanguageId, $languageId, $fields = '*')
{
if ($colPos <= ContentService::COLPOS_FLUXCONTENT) {
return parent::getRecordsToCopyDatabaseResult($pageId, $colPos, $destLanguageId, $languageId, $fields);
}

// here starts the flux related code
$db = $this->getDatabaseConnection();

list($fluxParent, $fluxColumn) = $this->contentService->getTargetAreaStoredInSession($colPos);

$record = $db->exec_SELECTgetSingleRow('*','tt_content','uid = ' . (integer) $fluxParent);
$fluxParentParent = $record[CompatibilityRegistry::get(ContentService::LANGUAGE_SOURCE_FIELD)];

$originalUids = [];

// Get original uid of existing elements triggered language / colpos
$queryBuilder = $this->getQueryBuilderWithWorkspaceRestriction('tt_content');

$originalUidsStatement = $queryBuilder
->select(CompatibilityRegistry::get(ContentService::LANGUAGE_SOURCE_FIELD))
->from('tt_content')
->where(
$queryBuilder->expr()->eq(
'sys_language_uid',
$queryBuilder->createNamedParameter($destLanguageId, \PDO::PARAM_INT)
),
$queryBuilder->expr()->eq(
'tt_content.colPos',
$queryBuilder->createNamedParameter(ContentService::COLPOS_FLUXCONTENT, \PDO::PARAM_INT)
),
$queryBuilder->expr()->eq(
'tt_content.tx_flux_parent',
$queryBuilder->createNamedParameter($fluxParent, \PDO::PARAM_INT)
),
$queryBuilder->expr()->eq(
'tt_content.tx_flux_column',
$queryBuilder->createNamedParameter($fluxColumn, \PDO::PARAM_STR)
),
$queryBuilder->expr()->eq(
'tt_content.pid',
$queryBuilder->createNamedParameter($pageId, \PDO::PARAM_INT)
)
)
->execute();

while ($origUid = $originalUidsStatement->fetchColumn(0)) {
$originalUids[] = (int)$origUid;
}

$queryBuilder->select(...GeneralUtility::trimExplode(',', $fields, true))
->from('tt_content')
->where(
$queryBuilder->expr()->eq(
'tt_content.sys_language_uid',
$queryBuilder->createNamedParameter($languageId, \PDO::PARAM_INT)
),
$queryBuilder->expr()->eq(
'tt_content.colPos',
$queryBuilder->createNamedParameter(ContentService::COLPOS_FLUXCONTENT, \PDO::PARAM_INT)
),
$queryBuilder->expr()->eq(
'tt_content.tx_flux_parent',
$queryBuilder->createNamedParameter($fluxParentParent, \PDO::PARAM_INT)
),
$queryBuilder->expr()->eq(
'tt_content.tx_flux_column',
$queryBuilder->createNamedParameter($fluxColumn, \PDO::PARAM_STR)
),
$queryBuilder->expr()->eq(
'tt_content.pid',
$queryBuilder->createNamedParameter($pageId, \PDO::PARAM_INT)
)
)
->orderBy('tt_content.sorting');

if (!empty($originalUids)) {
$queryBuilder
->andWhere(
$queryBuilder->expr()->notIn(
'tt_content.uid',
$queryBuilder->createNamedParameter($originalUids, Connection::PARAM_INT_ARRAY)
)
);
}

return $queryBuilder->execute();
}

/**
* Returns the database connection
*
* @return \TYPO3\CMS\Core\Database\DatabaseConnection
*/
protected function getDatabaseConnection()
{
return $GLOBALS['TYPO3_DB'];
}
}
Loading