Commit cf2a78ba authored by Fabio Stegmeyer's avatar Fabio Stegmeyer

[TASK] make sure migration wizard has all available languages

parent d401023d
<?php
namespace TYPO3\Languagevisibility\Exception;
/***************************************************************
* Copyright notice
*
* (c) 2007 AOE media (dev@aoemedia.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 2 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!
***************************************************************/
/**
*
* @author Daniel Poetzinger <poetzinger@aoemedia.de>
* @coauthor Tolleiv Nietsch <nietsch@aoemedia.de>
* @coauthor Timo Schmidt <schmidt@aoemedia.de>
*/
class InvalidRowException extends \Exception {
}
......@@ -10,9 +10,13 @@ use TYPO3\CMS\Core\Registry;
use TYPO3\CMS\Install\Updates\UpgradeWizardInterface;
use TYPO3\Languagevisibility\Repository\VisibilityFlagRepository;
use TYPO3\Languagevisibility\Service\VisibilityService;
use TYPO3\CMS\Core\Exception;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
/**
* Class VisibilitySettingsMigrationWizard
*
* @package TYPO3\Languagevisibility\Updates
*/
class VisibilitySettingsMigrationWizard implements UpgradeWizardInterface {
/**
......@@ -60,14 +64,21 @@ class VisibilitySettingsMigrationWizard implements UpgradeWizardInterface {
$this->visibilityFlagRepository = GeneralUtility::makeInstance(VisibilityFlagRepository::class);
$siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
$sites = $siteFinder->getAllSites();
try {
$site = $siteFinder->getSiteByPageId(0);
} catch (\Exception $e) {
return FALSE;
$availableLanguages = [];
// make sure we get ALL the languages
foreach($sites as $site){
$availableLanguagesFromSites = $site->getAllLanguages();
foreach($availableLanguagesFromSites as $availableLanguage){
if(!isset($availableLanguages[$availableLanguage->getLanguageId()])){
$availableLanguages[$availableLanguage->getLanguageId()] = $availableLanguage;
}
}
}
$availableLanguages = $site->getAllLanguages();
unset($sites);
// go through all configured tables
foreach ($GLOBALS['TCA'] as $table => $config) {
......@@ -79,99 +90,94 @@ class VisibilitySettingsMigrationWizard implements UpgradeWizardInterface {
$transOrigPointerField = $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'];
try {
$uids = $this->getDefaultLanguageUids($table);
$uids = $this->getDefaultLanguageUids($table);
foreach ($uids as $uidRow) {
$uid = $uidRow['uid'];
foreach ($uids as $uidRow) {
$uid = $uidRow['uid'];
if ($uid > 0) {
if ($uid > 0) {
$row = $this->getRecord($table, $uid);
$defaultLanguageRecordUid = $uid;
$row = $this->getRecord($table, $uid);
$defaultLanguageRecordUid = $uid;
$localVisibilitySettings = @unserialize(
$row['tx_languagevisibility_visibility'], ['allowed_classes' => FALSE]
);
$localVisibilitySettings = @unserialize(
$row['tx_languagevisibility_visibility'], ['allowed_classes' => FALSE]
);
$translations = $this->getTranslations(
$table, $transOrigPointerField, $defaultLanguageRecordUid
);
$translations = $this->getTranslations(
$table, $transOrigPointerField, $defaultLanguageRecordUid
foreach ($availableLanguages as $language) {
$lid = $language->getLanguageId();
$queryBuilderVisibilityFlags = GeneralUtility::makeInstance(
ConnectionPool::class
)->getQueryBuilderForTable(
'tx_languagevisibility_visibility_flag'
);
foreach ($availableLanguages as $language) {
$lid = $language->getLanguageId();
if (isset($translations[$lid])) {
$translation = $translations[$lid];
$queryBuilderVisibilityFlags = GeneralUtility::makeInstance(
ConnectionPool::class
)->getQueryBuilderForTable(
'tx_languagevisibility_visibility_flag'
$overlayVisibilityArray = @unserialize(
$translation['tx_languagevisibility_visibility'], ['allowed_classes' => FALSE]
);
if (isset($translations[$lid])) {
$translation = $translations[$lid];
$overlayVisibilityArray = @unserialize(
$translation['tx_languagevisibility_visibility'], ['allowed_classes' => FALSE]
);
$overlayVisibility = $overlayVisibilityArray[$lid];
$localVisibility = $localVisibilitySettings[$lid];
$overlayVisibility = $overlayVisibilityArray[$lid];
// determine visibility setting - taken from getLocalVisibilitySetting previously
if ($overlayVisibility === 'no+' || $localVisibility === 'no+') {
$visibilitySetting = 'no+';
} elseif ($overlayVisibility === 'no') {
$visibilitySetting = $overlayVisibility;
} else {
$visibilitySetting = (string) $localVisibility;
}
$localVisibility = $localVisibilitySettings[$lid];
// determine visibility setting - taken from getLocalVisibilitySetting previously
if ($overlayVisibility === 'no+' || $localVisibility === 'no+') {
$visibilitySetting = 'no+';
} elseif ($overlayVisibility === 'no') {
$visibilitySetting = $overlayVisibility;
} else {
$visibilitySetting = $localVisibilitySettings[$lid];
$visibilitySetting = (string) $localVisibility;
}
if ($visibilitySetting) {
} else {
$visibilitySetting = $localVisibilitySettings[$lid];
}
// the pid should always be the default language page
if ($table === 'pages') {
if ($lid > 0) {
$pid = $defaultLanguageRecordUid;
} else {
$pid = $uid;
}
} else {
$pid = $row['pid'];
}
if ($visibilitySetting) {
// the record_uid should always be the default language record
// the pid should always be the default language page
if ($table === 'pages') {
if ($lid > 0) {
$recordUid = $table . '_' . $defaultLanguageRecordUid;
$pid = $defaultLanguageRecordUid;
} else {
$recordUid = $table . '_' . $uid;
$pid = $uid;
}
} else {
$pid = $row['pid'];
}
$queryBuilderVisibilityFlags
->insert('tx_languagevisibility_visibility_flag')
->values(
[
'pid' => $pid,
'flag' => $visibilitySetting,
'record_table' => $table,
'record_uid' => $recordUid,
'record_language_uid' => $lid,
'tstamp' => time(),
'crdate' => time(),
]
)
->execute();
// the record_uid should always be the default language record
if ($lid > 0) {
$recordUid = $table . '_' . $defaultLanguageRecordUid;
} else {
$recordUid = $table . '_' . $uid;
}
$queryBuilderVisibilityFlags
->insert('tx_languagevisibility_visibility_flag')
->values(
[
'pid' => $pid,
'flag' => $visibilitySetting,
'record_table' => $table,
'record_uid' => $recordUid,
'record_language_uid' => $lid,
'tstamp' => time(),
'crdate' => time(),
]
)
->execute();
}
}
}
} catch (Exception $exception) {
continue;
}
}
}
......@@ -300,7 +306,7 @@ class VisibilitySettingsMigrationWizard implements UpgradeWizardInterface {
* @param $uid
* @return array
*/
protected function getTranslations($table, $field, $uid) {
protected function getTranslations($table, $field, $uid): array {
//make sure the query-builder is fresh
$queryBuilder = GeneralUtility::makeInstance(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment