/**
  * updates sys_refindex for translation content elements
  *
  * @param $contentUid
  */
 protected function updateRefIndexTranslations($contentUid)
 {
     $updateRefIndexTranslations = $this->sharedHelper->getTranslationsForContentElement($contentUid);
     if (!empty($updateRefIndexTranslations)) {
         foreach ($updateRefIndexTranslations as $updateRefIndexTranslation) {
             $updateRefIndexTranslationUid = (int) $updateRefIndexTranslation['uid'];
             if ($updateRefIndexTranslationUid > 0) {
                 $this->refIndex->updateRefIndexTable('tt_content', $updateRefIndexTranslationUid);
             }
         }
     }
 }
 /**
  * @param array $contentArray
  * @param int $pageUid
  * @param int $sorting
  * @return array
  */
 protected function fixSortingForContentArray($contentArray, $pageUid, &$sorting)
 {
     $pageUid = (int) $pageUid;
     $modifiedSortingCeUids = array();
     if (is_array($contentArray)) {
         $contentElementUids = $this->getContentElementUids($contentArray);
         foreach ($contentElementUids as $ceUid) {
             $contentElement = $this->sharedHelper->getContentElement($ceUid);
             $contentTvFlexform = NULL;
             $contentElementPageUid = (int) $contentElement['pid'];
             if ($contentElementPageUid === $pageUid) {
                 $contentTvFlexform = $contentElement['tx_templavoila_flex'];
                 $contentElementUid = (int) $contentElement['uid'];
                 if ($contentElementUid > 0) {
                     $sorting += self::SORTING_OFFSET;
                     $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tt_content', 'uid=' . $contentElementUid, array('sorting' => $sorting));
                     $modifiedSortingCeUids[] = $contentElementUid;
                     $translations = $this->sharedHelper->getTranslationsForContentElement($contentElementUid);
                     if (!empty($translations)) {
                         foreach ($translations as $translation) {
                             $translationUid = $translation['uid'];
                             if ($translationUid > 0) {
                                 $sorting += self::SORTING_OFFSET;
                                 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tt_content', 'uid=' . $translationUid, array('sorting' => $sorting));
                                 $modifiedSortingCeUids[] = $translationUid;
                                 $this->refIndex->updateRefIndexTable('tt_content', $translationUid);
                             }
                         }
                     }
                     $this->refIndex->updateRefIndexTable('tt_content', $contentElementUid);
                     $this->sharedHelper->fixContentElementLocalizationDiffSources($contentElementUid);
                     if (!empty($contentTvFlexform)) {
                         $contentArrayForFce = $this->sharedHelper->getTvContentArrayForContent($contentElementUid);
                         $fceModifiedCeUids = $this->fixSortingForContentArray($contentArrayForFce, $pageUid, $sorting);
                         $modifiedSortingCeUids = array_merge($modifiedSortingCeUids, $fceModifiedCeUids);
                     }
                 }
             }
         }
     }
     return $modifiedSortingCeUids;
 }
 /**
  * Rearranges content and translated content elements to the cloned/modified GridElements
  *
  * @param int $pageUid
  * @return int Amount of updated content elements
  */
 public function rearrangeContentElementsForGridelementsOnPage($pageUid)
 {
     $updated = 0;
     $gridElements = $this->getCeGridElements($pageUid, 0);
     foreach ($gridElements as $contentElementUid) {
         $contentElements = $this->getChildContentElements($contentElementUid);
         foreach ($contentElements as $contentElement) {
             $childElementUid = (int) $contentElement['uid'];
             $translations = $this->sharedHelper->getTranslationsForContentElement($childElementUid);
             if (!empty($translations)) {
                 foreach ($translations as $translatedContentElement) {
                     $localizedGridElement = $this->getLocalizedGridElement($contentElementUid, $translatedContentElement['sys_language_uid']);
                     if ($localizedGridElement) {
                         $origUid = $translatedContentElement['uid'];
                         unset($translatedContentElement['uid']);
                         $translatedContentElement['colPos'] = -1;
                         $translatedContentElement['tx_gridelements_container'] = $localizedGridElement['uid'];
                         $translatedContentElement['tx_gridelements_columns'] = $contentElement['tx_gridelements_columns'];
                         $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tt_content', 'uid=' . $origUid, $translatedContentElement);
                         $updated += 1;
                     }
                 }
             }
             if ($contentElement['sys_language_uid'] > 0) {
                 // Rearrage CE to new localized GEs
                 $localizedGridElement = $this->getLocalizedGridElement($contentElementUid, $contentElement['sys_language_uid']);
                 $origUid = $contentElement['uid'];
                 unset($contentElement['uid']);
                 $contentElement['tx_gridelements_container'] = $localizedGridElement['uid'];
                 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tt_content', 'uid=' . $origUid, $contentElement);
                 $updated += 1;
             }
             $this->updateInGeAllLangElements($pageUid, $contentElementUid, $contentElement);
             $this->sharedHelper->fixContentElementLocalizationDiffSources($childElementUid);
         }
         $this->sharedHelper->fixContentElementLocalizationDiffSources($contentElementUid);
     }
     return $updated;
 }