[BUGFIX] Check correctly for allowed localization action 89/46789/2
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Thu, 18 Feb 2016 11:47:03 +0000 (12:47 +0100)
committerAndreas Fernandez <typo3@scripting-base.de>
Tue, 23 Feb 2016 09:52:17 +0000 (10:52 +0100)
The localization wizard currently disallows creating copies if a column
has elements. There are now two flags which influence the allowed
actions. The wizard now checks whether there are translations or
standalone content elements and negates one of the flags.

Change-Id: Ief40d311959943f2f7e901b80e4b29931f2894d2
Resolves: #73538
Releases: master, 7.6
Reviewed-on: https://review.typo3.org/46789
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Reviewed-by: Ralf Merz <info@merzilla.de>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
typo3/sysext/backend/Classes/Controller/Page/LocalizationController.php
typo3/sysext/backend/Classes/View/PageLayoutView.php
typo3/sysext/backend/Resources/Public/JavaScript/Localization.js

index d26b132..c0f87c6 100644 (file)
@@ -133,14 +133,14 @@ class LocalizationController
     public function getRecordLocalizeSummary(ServerRequestInterface $request, ResponseInterface $response)
     {
         $params = $request->getQueryParams();
-        if (!isset($params['pageId'], $params['colPos'], $params['languageId'])) {
+        if (!isset($params['pageId'], $params['colPos'], $params['destLanguageId'], $params['languageId'])) {
             $response = $response->withStatus(500);
             return $response;
         }
 
         $records = [];
         $databaseConnection = $this->getDatabaseConnection();
-        $res = $this->getRecordsToCopyDatabaseResult($params['pageId'], $params['colPos'], $params['languageId'], '*');
+        $res = $this->getRecordsToCopyDatabaseResult($params['pageId'], $params['colPos'], $params['destLanguageId'], $params['languageId'], '*');
         while ($row = $databaseConnection->sql_fetch_assoc($res)) {
             $records[] = [
                 'icon' => $this->iconFactory->getIconForRecord('tt_content', $row, Icon::SIZE_SMALL)->render(),
@@ -259,18 +259,38 @@ class LocalizationController
      *
      * @param int $pageId
      * @param int $colPos
+     * @param int $destLanguageId
      * @param int $languageId
      * @param string $fields
      * @return bool|\mysqli_result|object
      */
-    protected function getRecordsToCopyDatabaseResult($pageId, $colPos, $languageId, $fields = '*')
+    protected function getRecordsToCopyDatabaseResult($pageId, $colPos, $destLanguageId, $languageId, $fields = '*')
     {
-        return $this->getDatabaseConnection()->exec_SELECTquery(
+        $db = $this->getDatabaseConnection();
+
+        // Get original uid of existing elements triggered language / colpos
+        $originalUids = $db->exec_SELECTgetRows(
+            't3_origuid',
+            'tt_content',
+            'sys_language_uid=' . (int)$destLanguageId
+                . ' AND tt_content.colPos = ' . (int)$colPos
+                . ' AND tt_content.pid=' . (int)$pageId
+                . BackendUtility::deleteClause('tt_content')
+                . BackendUtility::versioningPlaceholderClause('tt_content'),
+            '',
+            '',
+            '',
+            't3_origuid'
+        );
+        $originalUidList = $db->cleanIntList(implode(',', array_keys($originalUids)));
+
+        return $db->exec_SELECTquery(
             $fields,
             'tt_content',
             'tt_content.sys_language_uid=' . (int)$languageId
             . ' AND tt_content.colPos = ' . (int)$colPos
             . ' AND tt_content.pid=' . (int)$pageId
+            . ' AND tt_content.uid NOT IN (' . $originalUidList . ')'
             . BackendUtility::deleteClause('tt_content')
             . BackendUtility::versioningPlaceholderClause('tt_content'),
             '',
index 9e2c1b0..f841936 100644 (file)
@@ -1798,6 +1798,24 @@ class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRe
         }
         $theNewButton = '';
 
+        $allowCopy = true;
+        $allowTranslate = true;
+        if (!empty($this->languageHasTranslationsCache[$lP])) {
+            if (isset($this->languageHasTranslationsCache[$lP]['hasStandAloneContent'])) {
+                $allowTranslate = false;
+            }
+            if (isset($this->languageHasTranslationsCache[$lP]['hasTranslations'])) {
+                $allowCopy = false;
+            }
+        }
+
+        foreach ($this->contentElementCache[$lP][$colPos] as $record) {
+            $key = array_search($record['t3_origuid'], $defLanguageCount);
+            if ($key !== false) {
+                unset($defLanguageCount[$key]);
+            }
+        }
+
         if (!empty($defLanguageCount)) {
             $theNewButton =
                 '<input'
@@ -1806,6 +1824,8 @@ class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRe
                     . ' disabled'
                     . ' value="' . htmlspecialchars($this->getLanguageService()->getLL('newPageContent_translate', true)) . '"'
                     . ' data-has-elements="' . (int)!empty($this->contentElementCache[$lP][$colPos]) . '"'
+                    . ' data-allow-copy="' . (int)$allowCopy . '"'
+                    . ' data-allow-translate="' . (int)$allowTranslate . '"'
                     . ' data-table="tt_content"'
                     . ' data-page-id="' . (int)GeneralUtility::_GP('id') . '"'
                     . ' data-language-id="' . $lP . '"'
index c26f566..221e958 100644 (file)
@@ -74,29 +74,37 @@ define([
 
                $(document).on('click', Localization.identifier.triggerButton, function() {
                        var $triggerButton = $(this),
+                               actions = [],
                                modalContent =
                                        '<div id="localization-carousel" class="carousel slide" data-ride="carousel" data-interval="false">'
                                                + '<div class="carousel-inner" role="listbox">'
                                                        + '<div class="item active">'
-                                                               + '<div data-toggle="buttons">'
-                                                                       + '<div class="row">'
-                                                                               + '<div class="btn-group col-sm-3">' + Localization.actions.translate[0].outerHTML + '</div>'
-                                                                               + '<div class="col-sm-9">'
-                                                                                       + '<p class="t3js-helptext t3js-helptext-translate text-muted">' + TYPO3.lang['localize.educate.translate'] + '</p>'
-                                                                               + '</div>'
-                                                                       + '</div>';
-
-                       if ($triggerButton.data('hasElements') === 0) {
-                               modalContent +=
-                                       '<hr>'
-                                       + '<div class="row">'
+                                                               + '<div data-toggle="buttons">';
+
+                       if ($triggerButton.data('allowTranslate')) {
+                               actions.push(
+                                       '<div class="row">'
+                                               + '<div class="btn-group col-sm-3">' + Localization.actions.translate[0].outerHTML + '</div>'
+                                               + '<div class="col-sm-9">'
+                                                       + '<p class="t3js-helptext t3js-helptext-translate text-muted">' + TYPO3.lang['localize.educate.translate'] + '</p>'
+                                               + '</div>'
+                                       + '</div>'
+                               );
+                       }
+
+                       if ($triggerButton.data('allowCopy')) {
+                               actions.push(
+                                       '<div class="row">'
                                                + '<div class="col-sm-3 btn-group">' + Localization.actions.copy[0].outerHTML + '</div>'
                                                + '<div class="col-sm-9">'
                                                        + '<p class="t3js-helptext t3js-helptext-copy text-muted">' + TYPO3.lang['localize.educate.copy'] + '</p>'
                                                + '</div>'
-                                       + '</div>';
+                                       + '</div>'
+                               );
                        }
 
+                       modalContent += actions.join('<hr>');
+
                        modalContent +=         '</div>'
                                                        + '</div>'
                                                        + '<div class="item">'
@@ -248,7 +256,8 @@ define([
 
                                                Localization.getSummary(
                                                        $triggerButton.data('pageId'),
-                                                       $triggerButton.data('colposId')
+                                                       $triggerButton.data('colposId'),
+                                                       $triggerButton.data('languageId')
                                                ).done(function(result) {
                                                        var $summary = $('<div />', {class: 'row'});
                                                        Localization.records = [];
@@ -331,14 +340,16 @@ define([
                 *
                 * @param {Integer} pageId
                 * @param {Integer} colPos
+                * @param {Integer} languageId
                 * @return {Promise}
                 */
-               Localization.getSummary = function(pageId, colPos) {
+               Localization.getSummary = function(pageId, colPos, languageId) {
                        return $.ajax({
                                url: TYPO3.settings.ajaxUrls['records_localize_summary'],
                                data: {
                                        pageId: pageId,
                                        colPos: colPos,
+                                       destLanguageId: languageId,
                                        languageId: Localization.settings.language
                                }
                        });