/**
  * Marks all unreferenced element records as deleted with a recursion level of 99
  *
  * @return int Number of records deleted
  */
 public function markDeletedUnreferencedElementsRecords($markAsNegativeColPos = FALSE)
 {
     $pids = $this->sharedHelper->getPageIds();
     $allReferencedElementsArr = array();
     foreach ($pids as $pid) {
         $pageRecord = $this->sharedHelper->getPage($pid);
         if (!empty($pageRecord)) {
             $contentTree = $this->sharedHelper->getTemplavoilaAPIObj()->getContentTree('pages', $pageRecord, FALSE);
             $referencedElementsArrAsKeys = $contentTree['contentElementUsage'];
             if (!empty($referencedElementsArrAsKeys)) {
                 $referencedElementsArr = array_keys($referencedElementsArrAsKeys);
                 $allReferencedElementsArr = array_merge($allReferencedElementsArr, $referencedElementsArr);
             }
         }
     }
     $allReferencedElementsArr = array_unique($allReferencedElementsArr);
     $allRecordUids = $this->getUnreferencedElementsRecords($allReferencedElementsArr);
     $countRecords = count($allRecordUids);
     if ($markAsNegativeColPos) {
         $this->markNegativeColPos($allRecordUids);
     } else {
         $this->markDeleted($allRecordUids);
     }
     return $countRecords;
 }
 /**
  * @param int $pageUid
  * @param int $geElementUid
  * @param array $childElement
  */
 protected function updateInGeAllLangElements($pageUid, $geElementUid, $childElement)
 {
     $pageUid = (int) $pageUid;
     $geElementUid = (int) $geElementUid;
     $childElementUid = (int) $childElement['uid'];
     if ($childElement['sys_language_uid'] < 0 && $this->allLanguageRecordsInGeToShortcut) {
         $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tt_content', 'uid=' . $childElementUid, array('sys_language_uid' => 0));
         $pageLanguages = $this->sharedHelper->getAvailablePageTranslations($pageUid);
         foreach ($pageLanguages as $langUid) {
             $langUid = (int) $langUid;
             if ($langUid > 0) {
                 $localizedGridElement = $this->getLocalizedGridElement($geElementUid, $langUid);
                 $localizedGridElementUid = (int) $localizedGridElement['uid'];
                 if ($localizedGridElementUid > 0) {
                     $translationContentElement = $childElement;
                     $translationContentElement['tx_gridelements_container'] = $localizedGridElementUid;
                     $translationContentElement['CType'] = 'shortcut';
                     $translationContentElement['records'] = 'tt_content_' . $childElementUid;
                     $newUid = (int) $this->addTranslationContentElement($translationContentElement, $langUid, $childElementUid);
                     if ($newUid > 0) {
                         $this->refIndex->updateRefIndexTable('tt_content', $newUid);
                     }
                 }
             }
         }
     }
 }
 /**
  * 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);
             }
         }
     }
 }
 /**
  * Migrates all content elements for the FCE with the given uid to the selected column positions
  *
  * @param array $contentElement
  * @param array $formdata
  * @return int Number of Content elements updated
  */
 public function migrateContentElementsForFce($contentElement, $formdata)
 {
     $fieldMapping = $this->sharedHelper->getFieldMappingArray($formdata, 'tv_col_', 'ge_col_');
     $tvContentArray = $this->sharedHelper->getTvContentArrayForContent($contentElement['uid']);
     $translationParentUid = (int) $contentElement['l18n_parent'];
     $sysLanguageUid = (int) $contentElement['sys_language_uid'];
     $pageUid = (int) $contentElement['pid'];
     $count = 0;
     $sorting = 0;
     foreach ($tvContentArray as $key => $contentUidString) {
         if (array_key_exists($key, $fieldMapping) && $contentUidString != '') {
             $contentUids = explode(',', $contentUidString);
             foreach ($contentUids as $contentUid) {
                 $contentUid = (int) $contentUid;
                 $myContentElement = NULL;
                 $myContentElement = $this->sharedHelper->getContentElement($contentUid);
                 $containerUid = (int) $contentElement['uid'];
                 if ($translationParentUid > 0 && $sysLanguageUid > 0) {
                     $myCeTranslationParentUid = (int) $myContentElement['uid'];
                     if ($myCeTranslationParentUid > 0) {
                         $tmpMyContentElement = $this->sharedHelper->getTranslationForContentElementAndLanguage($myCeTranslationParentUid, $sysLanguageUid);
                         $tmpMyContentUid = (int) $tmpMyContentElement['uid'];
                         if ($tmpMyContentUid > 0) {
                             $contentUid = $tmpMyContentUid;
                             $myContentElement = $tmpMyContentElement;
                         } else {
                             $containerUid = $translationParentUid;
                         }
                     } else {
                         $containerUid = $translationParentUid;
                     }
                 } else {
                     $myContentElement = $this->sharedHelper->getContentElement($contentUid);
                 }
                 if (intval($myContentElement['pid']) === $pageUid) {
                     $this->sharedHelper->updateContentElementForGe($contentUid, $containerUid, $fieldMapping[$key], $sorting);
                 }
                 $sorting += 25;
                 $count++;
                 $this->sharedHelper->fixContentElementLocalizationDiffSources($contentUid);
                 $this->refIndex->updateRefIndexTable('tt_content', $contentUid);
             }
         }
     }
     return $count;
 }
 /**
  * Sets the backend layout uid for the page with the given uid if the value of the TV template matches
  * the uid of the given uidTvTemplate
  *
  * @param int $pageUid
  * @param int $UidTvTemplate
  * @param int $uidBeLayout
  * @return int Number of page templates updated
  */
 public function updatePageTemplate($pageUid, $UidTvTemplate, $uidBeLayout)
 {
     $pageRecord = $this->sharedHelper->getPage($pageUid);
     $updateFields = array();
     $count = 0;
     if ($pageRecord['tx_templavoila_to'] > 0 && $pageRecord['tx_templavoila_to'] == $UidTvTemplate) {
         $updateFields['backend_layout'] = $uidBeLayout;
     }
     if ($pageRecord['tx_templavoila_next_to'] > 0 && $pageRecord['tx_templavoila_next_to'] == $UidTvTemplate) {
         $updateFields['backend_layout_next_level'] = $uidBeLayout;
     }
     if (count($updateFields) > 0) {
         $GLOBALS['TYPO3_DB']->exec_UPDATEquery('pages', 'uid=' . intval($pageUid), $updateFields);
         $count++;
     }
     return $count;
 }
 /**
  * @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;
 }
 /**
  * Action for fix sorting
  *
  * @param array $formdata
  * @return void
  */
 public function fixSortingAction($formdata)
 {
     $this->sharedHelper->setUnlimitedTimeout();
     $numUpdated = 0;
     if ($formdata['fixOptions'] == 'singlePage') {
         $numUpdated = $this->fixSortingHelper->fixSortingForPage($formdata['pageUid']);
     } else {
         $pageUids = $this->sharedHelper->getPageIds();
         foreach ($pageUids as $pageUid) {
             $numUpdated += $this->fixSortingHelper->fixSortingForPage($pageUid);
         }
     }
     $this->view->assign('numUpdated', $numUpdated);
 }