/**
  * Entry method for use as TCEMain "inline" field filter
  *
  * @param array $parameters
  * @param \TYPO3\CMS\Core\DataHandling\DataHandler $tceMain
  * @return array
  */
 public function filterInlineChildren(array $parameters, \TYPO3\CMS\Core\DataHandling\DataHandler $tceMain)
 {
     $values = $parameters['values'];
     if ($parameters['allowedFileExtensions']) {
         $this->setAllowedFileExtensions($parameters['allowedFileExtensions']);
     }
     if ($parameters['disallowedFileExtensions']) {
         $this->setDisallowedFileExtensions($parameters['disallowedFileExtensions']);
     }
     $cleanValues = array();
     if (is_array($values)) {
         foreach ($values as $value) {
             if (empty($value)) {
                 continue;
             }
             $parts = \TYPO3\CMS\Core\Utility\GeneralUtility::revExplode('_', $value, 2);
             $fileReferenceUid = $parts[count($parts) - 1];
             $fileReference = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFileReferenceObject($fileReferenceUid);
             $file = $fileReference->getOriginalFile();
             if ($this->isAllowed($file->getName())) {
                 $cleanValues[] = $value;
             } else {
                 // Remove the erroneously created reference record again
                 $tceMain->deleteAction('sys_file_reference', $fileReferenceUid);
             }
         }
     }
     return $cleanValues;
 }
 /**
  * @param array|string $allowed
  * @param array|string $disallowed
  * @param array|string $values
  * @test
  * @dataProvider invalidInlineChildrenFilterParametersDataProvider
  */
 public function areInlineChildrenFilteredWithInvalidParameters($allowed, $disallowed, $values)
 {
     $this->parameters = array('allowedFileExtensions' => $allowed, 'disallowedFileExtensions' => $disallowed, 'values' => $values);
     $this->tceMainMock->expects($this->never())->method('deleteAction');
     $this->fileFactoryMock->expects($this->never())->method('getFileReferenceObject');
     $this->filter->filterInlineChildren($this->parameters, $this->tceMainMock);
 }
Esempio n. 3
0
 /**
  * @param int $id
  */
 public function deleteAction($id)
 {
     $GLOBALS['TYPO3_DB']->exec_DELETEquery('link_cache', 'id = ' . (int) $id);
     $this->dataHandler->start(NULL, NULL);
     $this->dataHandler->clear_cacheCmd('all');
     $this->addFlashMessage('A link has been removed from cache, please reload page where the link is present (not the page itself, but e.g. parent page with this link in menu) in order to generate it again.');
     $this->redirect('list');
 }
 /**
  * Run the delete action
  *
  * @param string      $table
  * @param int         $id
  * @param             $recordToDelete
  * @param             $recordWasDeleted
  * @param DataHandler $dataHandler
  */
 public function processCmdmap_deleteAction($table, $id, $recordToDelete, &$recordWasDeleted, DataHandler $dataHandler)
 {
     $register = Register::getRegister();
     foreach ($register as $key => $configuration) {
         if ($configuration['tableName'] == $table) {
             $indexer = HelperUtility::create('HDNET\\Calendarize\\Service\\IndexerService');
             $dataHandler->deleteEl($table, $id);
             $recordWasDeleted = TRUE;
             $indexer->reindex($key, $table, $id);
         }
     }
 }
 /**
  * @test
  */
 public function getTriggerSelfChangedEventWhenTitleOfPageWasChanged()
 {
     $eventWasFired = false;
     $this->dispatcher->subscribe('Page::Changed::Self', function ($event) use(&$eventWasFired) {
         if ($event instanceof SelfChangedEvent) {
             $eventWasFired = true;
         }
         $eventWasFired = false;
     });
     $this->dataHandler->updateDB();
     $this->dataHandler->process_datamap();
     $this->assertTrue($eventWasFired);
 }
Esempio n. 6
0
 /**
  * Create a new record under the given PID.
  *
  * @param  int  $pid
  * @param  array  $attrs  Set of attributes to add to the record
  * @return  int|null  UID of created record, or null if creation failed
  */
 public function create($pid, $attrs = [])
 {
     $table = $this->getTable();
     $newUid = 'NEW_' . uniqid($table);
     $this->dh->stripslashes_values = 0;
     $this->dh->start([$table => [$newUid => array_merge($attrs, ['pid' => $pid])]], null);
     $this->dh->process_datamap();
     if (isset($this->dh->substNEWwithIDs[$newUid])) {
         return $this->dh->substNEWwithIDs[$newUid];
     } else {
         return null;
     }
 }
Esempio n. 7
0
 /**
  * Proprocess article.
  *
  * @param string $command Command
  * @param int $articleUid Article uid
  *
  * @return void
  */
 protected function preProcessArticle(&$command, &$articleUid)
 {
     if ($command == 'localize') {
         $command = '';
         $this->error('LLL:EXT:commerce/Resources/Private/Language/locallang_be.xml:article.localization');
     } elseif ($command == 'delete') {
         /**
          * Article.
          *
          * @var \CommerceTeam\Commerce\Domain\Model\Article $article
          */
         $article = GeneralUtility::makeInstance('CommerceTeam\\Commerce\\Domain\\Model\\Article', $articleUid);
         $article->loadData();
         /**
          * Product.
          *
          * @var \CommerceTeam\Commerce\Domain\Model\Product $product
          */
         $product = $article->getParentProduct();
         // check if product or if translated the translation parent category
         if (!current($product->getParentCategories())) {
             $product = GeneralUtility::makeInstance('CommerceTeam\\Commerce\\Domain\\Model\\Product', $product->getL18nParent());
         }
         if (!\CommerceTeam\Commerce\Utility\BackendUtility::checkPermissionsOnCategoryContent($product->getParentCategories(), array('editcontent'))) {
             // Log the error
             $this->pObj->log('tx_commerce_articles', $articleUid, 3, 0, 1, 'Attempt to ' . $command . ' record without ' . $command . '-permissions');
             // Set id to 0 (reference!) to prevent delete of the record
             $articleUid = 0;
         }
     }
 }
 /**
  * Gets the page title of the given page id
  *
  * @param int $pageId
  * @return string
  */
 protected function getPageTitle($pageId)
 {
     $cacheId = 'recycler-pagetitle-' . $pageId;
     if ($this->runtimeCache->has($cacheId)) {
         $pageTitle = $this->runtimeCache->get($cacheId);
     } else {
         if ($pageId === 0) {
             $pageTitle = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
         } else {
             $recordInfo = $this->tce->recordInfo('pages', $pageId, 'title');
             $pageTitle = $recordInfo['title'];
         }
         $this->runtimeCache->set($cacheId, $pageTitle);
     }
     return $pageTitle;
 }
 /**
  * @param int $workspaceId
  */
 public function swapWorkspace($workspaceId)
 {
     $commandMap = $this->getWorkspaceService()->getCmdArrayForPublishWS($workspaceId, TRUE);
     $this->createDataHandler();
     $this->dataHandler->start(array(), $commandMap);
     $this->dataHandler->process_cmdmap();
 }
Esempio n. 10
0
 /**
  * @param string $value
  * @param string $expectedValue
  *
  * @dataProvider checkValue_checkReturnsExpectedValuesDataProvider
  * @test
  */
 public function checkValue_checkReturnsExpectedValues($value, $expectedValue)
 {
     $expectedResult = array('value' => $expectedValue);
     $result = array();
     $tcaFieldConfiguration = array('items' => array(array('Item 1', 0), array('Item 2', 0), array('Item 3', 0)));
     $this->assertSame($expectedResult, $this->subject->checkValue_check($result, $value, $tcaFieldConfiguration, array()));
 }
Esempio n. 11
0
 /**
  * Create an (cached) instance of t3lib_TCEmain
  *
  * @return \TYPO3\CMS\Core\DataHandling\DataHandler
  */
 protected function _tce()
 {
     if ($this->_tce === NULL) {
         $this->_tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
         $this->_tce->start(null, null);
     }
     return $this->_tce;
 }
Esempio n. 12
0
 /**
  * @return \TYPO3\CMS\Core\DataHandling\DataHandler
  */
 public function getDataHandler()
 {
     if (!isset($this->dataHandler)) {
         $this->dataHandler = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
         $this->dataHandler->start(null, null);
     }
     return $this->dataHandler;
 }
 /**
  * Redirecting the user after the processing has been done.
  * Might also display error messages directly, if any.
  *
  * @return void
  * @todo Define visibility
  */
 public function finish()
 {
     // Prints errors, if...
     if ($this->prErr) {
         $this->tce->printLogErrorMessages($this->redirect);
     }
     if ($this->redirect && !$this->tce->debug) {
         \TYPO3\CMS\Core\Utility\HttpUtility::redirect($this->redirect);
     }
 }
Esempio n. 14
0
 /**
  * @test
  */
 public function logFormatsDetailMessageWithAdditionalDataInLocalErrorArray()
 {
     $backendUser = $this->getMock('TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication');
     $this->fixture->BE_USER = $backendUser;
     $this->fixture->enableLogging = TRUE;
     $this->fixture->errorLog = array();
     $logDetails = uniqid('details');
     $this->fixture->log('', 23, 0, 42, 1, '%1s' . $logDetails . '%2s', -1, array('foo', 'bar'));
     $expected = 'foo' . $logDetails . 'bar';
     $this->assertStringEndsWith($expected, $this->fixture->errorLog[0]);
 }
 /**
  * Saves a record based on its data array.
  *
  * @param string $table The table name for the record to save.
  * @param integer $uid The UID for the record to save.
  * @return void
  */
 public function doSave($table, $uid)
 {
     $data = $this->TSFE_EDIT['data'];
     if (!empty($data)) {
         $this->initializeTceMain();
         $this->tce->start($data, array());
         $this->tce->process_uploads($_FILES);
         $this->tce->process_datamap();
         // Save the new UID back into TSFE_EDIT
         $newUID = $this->tce->substNEWwithIDs['NEW'];
         if ($newUID) {
             $GLOBALS['BE_USER']->frontendEdit->TSFE_EDIT['newUID'] = $newUID;
         }
     }
 }
Esempio n. 16
0
 /**
  * Function to set the colPos of an element depending on
  * whether it is a child of a parent container or not
  * will set colPos according to availability of the current grid column of an element
  * 0 = no column at all
  * -1 = grid element column
  * -2 = non used elements column
  * changes are applied to the field array of the parent object by reference
  *
  * @param                                             $status
  * @param    string                                   $table      : The name of the table the data should be saved to
  * @param    int                                      $id         : The uid of the page we are currently working on
  * @param    array                                    $fieldArray : The array of fields and values that have been saved to the datamap
  * @param    \TYPO3\CMS\Core\DataHandling\DataHandler $parentObj  : The parent object that triggered this hook
  *
  * @return   void
  */
 public function processDatamap_postProcessFieldArray($status, $table, $id, array &$fieldArray, \TYPO3\CMS\Core\DataHandling\DataHandler $parentObj)
 {
     $cmd = GeneralUtility::_GET('cmd');
     if (count($cmd) && key($cmd) === 'tt_content' && $status === 'new' && strpos($cmd['tt_content'][key($cmd['tt_content'])]['copy'], 'x') !== FALSE && !$parentObj->isImporting) {
         $positionArray = explode('x', $cmd['tt_content'][key($cmd['tt_content'])]['copy']);
         if ($positionArray[0] < 0) {
             $parentPage = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('pid', 'tt_content', 'uid = ' . abs($positionArray[0]));
             if ($parentPage['pid']) {
                 $pid = $parentPage['pid'];
             }
         } else {
             $pid = (int) $positionArray[0];
         }
         $sortNumber = $parentObj->getSortNumber('tt_content', 0, abs($pid));
         $fieldArray['sorting'] = $sortNumber;
     }
 }
 /**
  * @param array $row
  * @param DataHandler $tceMain
  * @return NULL
  */
 public function initializeRecord(array $row, DataHandler $tceMain)
 {
     $id = $row['uid'];
     $newUid = $tceMain->substNEWwithIDs[$id];
     $oldUid = $row['t3_origuid'];
     $languageFieldName = $GLOBALS['TCA']['tt_content']['ctrl']['languageField'];
     $newLanguageUid = NULL;
     if ($oldUid) {
         $oldRecord = $this->loadRecordFromDatabase($oldUid);
         if (FALSE === empty($row[$languageFieldName])) {
             $newLanguageUid = $row[$languageFieldName];
         } elseif (FALSE === empty($oldRecord[$languageFieldName])) {
             $newLanguageUid = $oldRecord[$languageFieldName];
         } else {
             $newLanguageUid = 1;
             // TODO: resolve config.sys_language_uid but WITHOUT using Extbase TS resolution, consider pid of new record
         }
         $clause = "(tx_flux_column LIKE '%:" . $oldUid . "' || tx_flux_parent = '" . $oldUid . "') AND deleted = 0 AND hidden = 0";
         $children = $this->loadRecordsFromDatabase($clause);
         if (1 > count($children)) {
             return NULL;
         }
         // Perform localization on all children, since this is not handled by the TCA field which otherwise cascades changes
         foreach ($children as $child) {
             $area = $child['tx_flux_column'];
             $overrideValues = array('tx_flux_column' => $area, 'tx_flux_parent' => $newUid, $languageFieldName => $newLanguageUid);
             if ($oldRecord[$languageFieldName] !== $newLanguageUid && $oldRecord['pid'] === $row['pid']) {
                 $childUid = $tceMain->localize('tt_content', $child['uid'], $newLanguageUid);
                 $this->updateRecordInDatabase($overrideValues, $childUid);
             }
         }
     }
     return NULL;
 }
Esempio n. 18
0
 /**
  * Clear the system cache
  *
  * @return void
  */
 public function clearSystemCache()
 {
     $this->dataHandler->clear_cacheCmd('system');
 }
 /**
  * Hook for updates in Typo3 backend
  * @param array $incomingFieldArray
  * @param string $table
  * @param integer $id
  * @param \TYPO3\CMS\Core\DataHandling\DataHandler $tcemain
  */
 public function processDatamap_preProcessFieldArray(&$incomingFieldArray, $table, $id, \TYPO3\CMS\Core\DataHandling\DataHandler &$tcemain)
 {
     if (FALSE === $this->needsOverWriteProtection($table)) {
         return;
     }
     // check, if overwrite-protection-fields are set:
     // If they are NOT set, it means, that any other extension maybe called the process_datamap!
     if (false === array_key_exists(self::OVERWRITE_PROTECTION_TILL, $incomingFieldArray) || false === array_key_exists(self::OVERWRITE_PROTECTION_MODE, $incomingFieldArray)) {
         return;
     }
     if (FALSE === $this->hasOverWriteProtection($incomingFieldArray)) {
         $this->removeOverwriteprotection($id, $table);
     } else {
         $protection = strtotime($incomingFieldArray[self::OVERWRITE_PROTECTION_TILL]);
         $mode = $incomingFieldArray[self::OVERWRITE_PROTECTION_MODE];
         $result = $this->getOverwriteprotectionRepository()->findByProtectedUidAndTableName($id, $table);
         if ($result->count() === 0) {
             /* @var $overwriteprotection Tx_AoeDbsequenzer_Domain_Model_Overwriteprotection */
             $overwriteprotection = $this->objectManager->get('Tx_AoeDbsequenzer_Domain_Model_Overwriteprotection');
             $overwriteprotection->setProtectedMode($mode);
             $overwriteprotection->setPid($tcemain->getPID($table, $id));
             $overwriteprotection->setProtectedTablename($table);
             $overwriteprotection->setProtectedUid($id);
             $overwriteprotection->setProtectedTime($protection);
             $this->getOverwriteprotectionRepository()->add($overwriteprotection);
         } else {
             foreach ($result as $overwriteprotection) {
                 /* @var $overwriteprotection Tx_AoeDbsequenzer_Domain_Model_Overwriteprotection */
                 $overwriteprotection->setProtectedMode($mode);
                 $overwriteprotection->setProtectedTime($protection);
                 $this->getOverwriteprotectionRepository()->update($overwriteprotection);
             }
         }
         $this->persistAll();
     }
     unset($incomingFieldArray[self::OVERWRITE_PROTECTION_TILL]);
     unset($incomingFieldArray[self::OVERWRITE_PROTECTION_MODE]);
 }
Esempio n. 20
0
 /**
  * Returning uid of previous localized record, if any, for tables with a "sortby" column
  * Used when new localized records are created so that localized records are sorted in the same order as the default language records
  *
  * This is a port from DataHandler::getPreviousLocalizedRecordUid that respects tx_flux_parent and tx_flux_column!
  *
  * @param integer $uid Uid of default language record
  * @param integer $language Language of localization
  * @param TYPO3\CMS\Core\DataHandling\DataHandler $datahandler
  * @return integer uid of record after which the localized record should be inserted
  */
 protected function getPreviousLocalizedRecordUid($uid, $language, DataHandler $reference)
 {
     $table = 'tt_content';
     $previousLocalizedRecordUid = $uid;
     $sortRow = $GLOBALS['TCA'][$table]['ctrl']['sortby'];
     $select = $sortRow . ',pid,uid,colPos,tx_flux_parent,tx_flux_column';
     // Get the sort value of the default language record
     $row = BackendUtility::getRecord($table, $uid, $select);
     if (is_array($row)) {
         // Find the previous record in default language on the same page
         $where = sprintf('pid=%d AND sys_language_uid=0 AND %s < %d', (int) $row['pid'], $sortRow, (int) $row[$sortRow]);
         // Respect the colPos for content elements
         if ($table === 'tt_content') {
             $where .= sprintf(' AND colPos=%d AND tx_flux_column=\'%s\' AND tx_flux_parent=%d', (int) $row['colPos'], $row['tx_flux_column'], (int) $row['tx_flux_parent']);
         }
         $where .= $reference->deleteClause($table);
         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($select, $table, $where, '', $sortRow . ' DESC', '1');
         // If there is an element, find its localized record in specified localization language
         if ($previousRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
             $previousLocalizedRecord = BackendUtility::getRecordLocalization($table, $previousRow['uid'], $language);
             if (is_array($previousLocalizedRecord[0])) {
                 $previousLocalizedRecordUid = $previousLocalizedRecord[0]['uid'];
             }
         }
         $GLOBALS['TYPO3_DB']->sql_free_result($res);
     }
     return $previousLocalizedRecordUid;
 }
Esempio n. 21
0
 /**
  * @param array $row
  * @param integer $newUid
  * @param integer $oldUid
  * @param integer $newLanguageUid
  * @param string $languageFieldName
  * @param DataHandler $tceMain
  */
 protected function initializeRecordByNewAndOldAndLanguageUids($row, $newUid, $oldUid, $newLanguageUid, $languageFieldName, DataHandler $tceMain)
 {
     if (0 < $newUid && 0 < $oldUid && 0 < $newLanguageUid) {
         $oldRecord = $this->loadRecordFromDatabase($oldUid);
         if ($oldRecord[$languageFieldName] !== $newLanguageUid && $oldRecord['pid'] === $row['pid']) {
             $sortbyFieldName = TRUE === isset($GLOBALS['TCA']['tt_content']['ctrl']['sortby']) ? $GLOBALS['TCA']['tt_content']['ctrl']['sortby'] : 'sorting';
             $overrideValues = array($sortbyFieldName => $tceMain->resorting('tt_content', $row['pid'], $sortbyFieldName, $oldUid));
             $this->updateRecordInDatabase($overrideValues, $newUid);
         }
     }
 }
Esempio n. 22
0
 /**
  * After database product handling
  *
  * @param string $status Status
  * @param string $table Table
  * @param string|int $id Id
  * @param array $fieldArray Field array
  * @param DataHandler $pObj Parent object
  *
  * @return void
  */
 protected function afterDatabaseProduct($status, $table, $id, array $fieldArray, DataHandler $pObj)
 {
     // if fieldArray has been unset, do not save anything, but load dynaflex config
     if (count($fieldArray)) {
         /**
          * Product
          *
          * @var Tx_Commerce_Domain_Model_Product $product
          */
         $product = GeneralUtility::makeInstance('Tx_Commerce_Domain_Model_Product', $id);
         $product->loadData();
         if (isset($fieldArray['categories'])) {
             $catList = $this->belib->getUidListFromList(explode(',', $fieldArray['categories']));
             $catList = $this->belib->extractFieldArray($catList, 'uid_foreign', TRUE);
             // get id of the live placeholder instead if such exists
             $relId = $status != 'new' && $product->getPid() == '-1' ? $product->getT3verOid() : $id;
             $this->belib->saveRelations($relId, $catList, 'tx_commerce_products_categories_mm', TRUE, FALSE);
         }
         // if the live shadow is saved, the product relations have to be saved
         // to the versioned version
         if ($status == 'new' && $fieldArray['pid'] == '-1') {
             $id++;
         }
         $this->saveProductRelations($id, $fieldArray);
     }
     // sometimes the array is unset because only the checkbox "create new article"
     // has been checked if that is the case and we have the rights, create the
     // articles so we check if the product is already created and if we have edit
     // rights on it
     if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($id)) {
         // check permissions
         /**
          * Product
          *
          * @var Tx_Commerce_Domain_Model_Product $product
          */
         $product = GeneralUtility::makeInstance('Tx_Commerce_Domain_Model_Product', $id);
         $parentCategories = $product->getParentCategories();
         // check existing categories
         if (!Tx_Commerce_Utility_BackendUtility::checkPermissionsOnCategoryContent($parentCategories, array('editcontent'))) {
             $pObj->newlog('You dont have the permissions to create a new article.', 1);
         } else {
             // init the article creator
             /**
              * Article creator
              *
              * @var Tx_Commerce_Utility_ArticleCreatorUtility $articleCreator
              */
             $articleCreator = GeneralUtility::makeInstance('Tx_Commerce_Utility_ArticleCreatorUtility');
             $articleCreator->init($id, $this->belib->getProductFolderUid());
             // create new articles
             $articleCreator->createArticles($pObj->datamap[$table][$this->unsubstitutedId ? $this->unsubstitutedId : $id]);
             // update articles if new attributes were added
             $articleCreator->updateArticles();
         }
     }
 }
Esempio n. 23
0
 /**
  * Processes all AJAX calls and returns a JSON formatted string
  *
  * @param ServerRequestInterface $request
  * @param ResponseInterface $response
  * @return ResponseInterface
  */
 public function processAjaxRequest(ServerRequestInterface $request, ResponseInterface $response)
 {
     // do the regular / main logic
     $this->initClipboard();
     $this->main();
     /** @var \TYPO3\CMS\Core\Messaging\FlashMessageService $flashMessageService */
     $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
     $content = ['redirect' => $this->redirect, 'messages' => [], 'hasErrors' => false];
     // Prints errors (= write them to the message queue)
     if ($this->prErr) {
         $content['hasErrors'] = true;
         $this->tce->printLogErrorMessages($this->redirect);
     }
     $messages = $flashMessageService->getMessageQueueByIdentifier()->getAllMessagesAndFlush();
     if (!empty($messages)) {
         foreach ($messages as $message) {
             $content['messages'][] = ['title' => $message->getTitle(), 'message' => $message->getMessage(), 'severity' => $message->getSeverity()];
             if ($message->getSeverity() === AbstractMessage::ERROR) {
                 $content['hasErrors'] = true;
             }
         }
     }
     $response->getBody()->write(json_encode($content));
     return $response;
 }
Esempio n. 24
0
 /**
  * @param mixed $value
  * @param array $configuration
  * @param int|string $expected
  * @test
  * @dataProvider referenceValuesAreCastedDataProvider
  */
 public function referenceValuesAreCasted($value, array $configuration, $expected)
 {
     $this->assertEquals($expected, $this->subject->_call('castReferenceValue', $value, $configuration));
 }
 /**
  * Processes all AJAX calls and returns a JSON formatted string
  *
  * @param array $parameters
  * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxRequestHandler
  */
 public function processAjaxRequest($parameters, AjaxRequestHandler $ajaxRequestHandler)
 {
     // do the regular / main logic
     $this->initClipboard();
     $this->main();
     /** @var \TYPO3\CMS\Core\Messaging\FlashMessageService $flashMessageService */
     $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
     $content = array('redirect' => $this->redirect, 'messages' => array(), 'hasErrors' => FALSE);
     // Prints errors (= write them to the message queue)
     if ($this->prErr) {
         $content['hasErrors'] = TRUE;
         $this->tce->printLogErrorMessages($this->redirect);
     }
     $messages = $flashMessageService->getMessageQueueByIdentifier()->getAllMessagesAndFlush();
     if (!empty($messages)) {
         foreach ($messages as $message) {
             $content['messages'][] = array('title' => $message->getTitle(), 'message' => $message->getMessage(), 'severity' => $message->getSeverity());
             if ($message->getSeverity() === AbstractMessage::ERROR) {
                 $content['hasErrors'] = TRUE;
             }
         }
     }
     $ajaxRequestHandler->setContentFormat('json');
     $ajaxRequestHandler->setContent($content);
 }
Esempio n. 26
0
    /**
     * Process Commandmap hook
     *
     * @since 1.0.0
     *
     * @param string $command The TCEmain operation status, fx. 'update'
     * @param string $table The table TCEmain is currently processing
     * @param string $id The records id (if any)
     * @param integer $value The uid of the element to move this element after.
     *             This value is negative when moving tt_content in page view.
     *             See \TYPO3\CMS\Core\DataHandling\DataHandler::resolvePid for more information.
     * @param boolean $commandIsProcessed
     * @param \TYPO3\CMS\Core\DataHandling\DataHandler $parent : Reference to the parent object
     *
     * @return void
     */
    public function processCmdmap($command, $table, $id, $value, &$commandIsProcessed, $parent)
    {
        if (!in_array($table, array('tt_content'))) {
            return;
        }
        switch ($table) {
            case 'tt_content':
                /** @var \TYPO3\CMS\Dbal\Database\DatabaseConnection $databaseConnection */
                $databaseConnection = $GLOBALS['TYPO3_DB'];
                /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
                $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
                /** @var $flashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
                $flashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
                switch ($command) {
                    case 'copy':
                    case 'move':
                        $res = $databaseConnection->sql_query('
							SELECT
								tt_content.uid, pages.backend_layout, pages.doktype, tt_content.colPos
							FROM
								tt_content
							JOIN
								pages
							ON
								pages.uid = tt_content.pid
							WHERE
								tt_content.uid = ' . abs($value));
                        $pasteAfterFieldArray = $databaseConnection->sql_fetch_assoc($res);
                        if (is_array($pasteAfterFieldArray)) {
                            $GLOBALS['BE_USER']->setAndSaveSessionData('core.yaml_configuration.newColPos', $pasteAfterFieldArray);
                            $originalFieldArray = $parent->recordInfo($table, $id, '*');
                            // If content is moved or copied to another colPos, check
                            // if that is allowed by TSConfig
                            if (isset($pasteAfterFieldArray['colPos']) && isset($originalFieldArray['colPos']) && $pasteAfterFieldArray['colPos'] !== $originalFieldArray['colPos']) {
                                $tsConfig = BackendUtility::getTCEFORM_TSconfig('tt_content', $pasteAfterFieldArray);
                                if ($originalFieldArray['CType'] !== '') {
                                    $keepItems = explode(',', str_replace(' ', '', $tsConfig['CType']['keepItems']));
                                    $removeItems = explode(',', str_replace(' ', '', $tsConfig['CType']['removeItems']));
                                    foreach ($removeItems as $item) {
                                        unset($keepItems[$item]);
                                    }
                                    if (!in_array($originalFieldArray['CType'], $keepItems)) {
                                        if ($GLOBALS['BE_USER']->user['admin'] != 1) {
                                            /** @var \TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage */
                                            $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, 'You are not allowed to place elements of type "' . $originalFieldArray['CType'] . '" in that column. Allowed items: "' . implode(', ', $keepItems) . '".', 'Content of type "' . $originalFieldArray['CType'] . '" not allowed in that column!', FlashMessage::WARNING, true);
                                            $flashMessageQueue->enqueue($flashMessage);
                                            $commandIsProcessed = true;
                                        } else {
                                            /** @var \TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage */
                                            $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, 'You are not allowed to place elements of type "' . $originalFieldArray['CType'] . '" in that column. Allowed items: "' . implode(', ', $keepItems) . '". You are an ' . 'admin so this time I will see it through the fingers . . . but boy oh boy . . . naughty naughty!', 'Content of type "' . $originalFieldArray['CType'] . '" not allowed in that column!', FlashMessage::WARNING, true);
                                            $flashMessageQueue->enqueue($flashMessage);
                                        }
                                    }
                                }
                                if ($originalFieldArray['list_type'] !== '') {
                                    $keepItems = explode(',', str_replace(' ', '', $tsConfig['list_type']['keepItems']));
                                    $removeItems = explode(',', str_replace(' ', '', $tsConfig['list_type']['removeItems']));
                                    foreach ($removeItems as $item) {
                                        unset($keepItems[$item]);
                                    }
                                    if (!in_array($originalFieldArray['list_type'], $keepItems)) {
                                        if ($GLOBALS['BE_USER']->user['admin'] != 1) {
                                            /** @var \TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage */
                                            $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, 'You are not allowed to place elements of type "' . $originalFieldArray['list_type'] . '" in that column. Allowed items: "' . implode(', ', $keepItems) . '".', 'Plugins of type "' . $originalFieldArray['list_type'] . '" not allowed in that column!', FlashMessage::WARNING, true);
                                            $flashMessageQueue->enqueue($flashMessage);
                                            $commandIsProcessed = true;
                                        } else {
                                            /** @var \TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage */
                                            $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, 'You are not allowed to place elements of type "' . $originalFieldArray['list_type'] . '" in that column. Allowed items: "' . implode(', ', $keepItems) . '". You are an ' . 'admin so this time I will see it through the fingers . . . but boy oh boy . . . naughty naughty!', 'Plugins of type "' . $originalFieldArray['list_type'] . '" not allowed in that column!', FlashMessage::WARNING, true);
                                            $flashMessageQueue->enqueue($flashMessage);
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    default:
                }
                break;
        }
    }
Esempio n. 27
0
 /**
  * Creates a move placeholder for workspaces.
  * USE ONLY INTERNALLY
  * Moving placeholder: Can be done because the system sees it as a placeholder for NEW elements like t3ver_state=VersionState::NEW_PLACEHOLDER
  * Moving original: Will either create the placeholder if it doesn't exist or move existing placeholder in workspace.
  *
  * @param string $table Table name to move
  * @param int $uid Record uid to move (online record)
  * @param int $destPid Position to move to: $destPid: >=0 then it points to a page-id on which to insert the record (as the first element). <0 then it points to a uid from its own table after which to insert it (works if
  * @param int $wsUid UID of offline version of online record
  * @param DataHandler $tcemainObj TCEmain object
  * @return void
  * @see moveRecord()
  */
 protected function moveRecord_wsPlaceholders($table, $uid, $destPid, $wsUid, DataHandler $tcemainObj)
 {
     // If a record gets moved after a record that already has a placeholder record
     // then the new placeholder record needs to be after the existing one
     $originalRecordDestinationPid = $destPid;
     if ($destPid < 0) {
         $movePlaceHolder = BackendUtility::getMovePlaceholder($table, abs($destPid), 'uid');
         if ($movePlaceHolder !== FALSE) {
             $destPid = -$movePlaceHolder['uid'];
         }
     }
     if ($plh = BackendUtility::getMovePlaceholder($table, $uid, 'uid')) {
         // If already a placeholder exists, move it:
         $tcemainObj->moveRecord_raw($table, $plh['uid'], $destPid);
     } else {
         // First, we create a placeholder record in the Live workspace that
         // represents the position to where the record is eventually moved to.
         $newVersion_placeholderFieldArray = array();
         // Use property for move placeholders if set (since TYPO3 CMS 6.2)
         if (isset($GLOBALS['TCA'][$table]['ctrl']['shadowColumnsForMovePlaceholders'])) {
             $shadowColumnsForMovePlaceholder = $GLOBALS['TCA'][$table]['ctrl']['shadowColumnsForMovePlaceholders'];
             // Fallback to property for new placeholder (existed long time before TYPO3 CMS 6.2)
         } elseif (isset($GLOBALS['TCA'][$table]['ctrl']['shadowColumnsForNewPlaceholders'])) {
             $shadowColumnsForMovePlaceholder = $GLOBALS['TCA'][$table]['ctrl']['shadowColumnsForNewPlaceholders'];
         }
         // Set values from the versioned record to the move placeholder
         if (!empty($shadowColumnsForMovePlaceholder)) {
             $versionedRecord = BackendUtility::getRecord($table, $wsUid);
             $shadowColumns = GeneralUtility::trimExplode(',', $shadowColumnsForMovePlaceholder, TRUE);
             foreach ($shadowColumns as $shadowColumn) {
                 if (isset($versionedRecord[$shadowColumn])) {
                     $newVersion_placeholderFieldArray[$shadowColumn] = $versionedRecord[$shadowColumn];
                 }
             }
         }
         if ($GLOBALS['TCA'][$table]['ctrl']['crdate']) {
             $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['crdate']] = $GLOBALS['EXEC_TIME'];
         }
         if ($GLOBALS['TCA'][$table]['ctrl']['cruser_id']) {
             $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['cruser_id']] = $tcemainObj->userid;
         }
         if ($GLOBALS['TCA'][$table]['ctrl']['tstamp']) {
             $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['tstamp']] = $GLOBALS['EXEC_TIME'];
         }
         if ($table == 'pages') {
             // Copy page access settings from original page to placeholder
             $perms_clause = $tcemainObj->BE_USER->getPagePermsClause(1);
             $access = BackendUtility::readPageAccess($uid, $perms_clause);
             $newVersion_placeholderFieldArray['perms_userid'] = $access['perms_userid'];
             $newVersion_placeholderFieldArray['perms_groupid'] = $access['perms_groupid'];
             $newVersion_placeholderFieldArray['perms_user'] = $access['perms_user'];
             $newVersion_placeholderFieldArray['perms_group'] = $access['perms_group'];
             $newVersion_placeholderFieldArray['perms_everybody'] = $access['perms_everybody'];
         }
         $newVersion_placeholderFieldArray['t3ver_label'] = 'MovePlaceholder #' . $uid;
         $newVersion_placeholderFieldArray['t3ver_move_id'] = $uid;
         // Setting placeholder state value for temporary record
         $newVersion_placeholderFieldArray['t3ver_state'] = (string) new VersionState(VersionState::MOVE_PLACEHOLDER);
         // Setting workspace - only so display of place holders can filter out those from other workspaces.
         $newVersion_placeholderFieldArray['t3ver_wsid'] = $tcemainObj->BE_USER->workspace;
         $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['label']] = '[MOVE-TO PLACEHOLDER for #' . $uid . ', WS#' . $tcemainObj->BE_USER->workspace . ']';
         // moving localized records requires to keep localization-settings for the placeholder too
         if (array_key_exists('languageField', $GLOBALS['TCA'][$table]['ctrl']) && array_key_exists('transOrigPointerField', $GLOBALS['TCA'][$table]['ctrl'])) {
             $l10nParentRec = BackendUtility::getRecord($table, $uid);
             $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['languageField']] = $l10nParentRec[$GLOBALS['TCA'][$table]['ctrl']['languageField']];
             $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] = $l10nParentRec[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']];
             unset($l10nParentRec);
         }
         // Initially, create at root level.
         $newVersion_placeholderFieldArray['pid'] = 0;
         $id = 'NEW_MOVE_PLH';
         // Saving placeholder as 'original'
         $tcemainObj->insertDB($table, $id, $newVersion_placeholderFieldArray, FALSE);
         // Move the new placeholder from temporary root-level to location:
         $tcemainObj->moveRecord_raw($table, $tcemainObj->substNEWwithIDs[$id], $destPid);
         // Move the workspace-version of the original to be the version of the move-to-placeholder:
         // Setting placeholder state value for version (so it can know it is currently a new version...)
         $updateFields = array('t3ver_state' => (string) new VersionState(VersionState::MOVE_POINTER));
         $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid=' . (int) $wsUid, $updateFields);
     }
     // Check for the localizations of that element and move them as well
     $tcemainObj->moveL10nOverlayRecords($table, $uid, $destPid, $originalRecordDestinationPid);
 }
Esempio n. 28
0
 /**
  * Check if address may get deleted.
  *
  * @param int $uid Uid
  * @param AddressesController|DataHandler $parentObject Parent object
  *
  * @return bool|string
  */
 public static function checkDelete($uid, $parentObject)
 {
     /**
      * Frontend user repository.
      *
      * @var FrontendUserRepository
      */
     $userRepository = GeneralUtility::makeInstance('CommerceTeam\\Commerce\\Domain\\Repository\\FrontendUserRepository');
     $frontendUser = $userRepository->findByAddressId((int) $uid);
     // no errormessage
     $msg = false;
     // check dependencies (selected rows)
     if (!empty($frontendUser)) {
         // errormessage
         if ($parentObject instanceof AddressesController) {
             $msg = $parentObject->pi_getLL('error_deleted_address_is_default');
         }
         if ($parentObject instanceof DataHandler) {
             $msg = self::getLanguageService()->sl('LLL:EXT:commerce/Resources/Private/Language/locallang.xml:error_deleted_address_is_default');
         }
     }
     return $msg;
 }
Esempio n. 29
0
 /**
  * Hooks into TCE Main and watches all record creations and updates. If it
  * detects that the new/updated record belongs to a table configured for
  * indexing through Solr, we add the record to the index queue.
  *
  * @param string $status Status of the current operation, 'new' or 'update'
  * @param string $table The table the record belongs to
  * @param mixed $uid The record's uid, [integer] or [string] (like 'NEW...')
  * @param array $fields The record's data
  * @param DataHandler $tceMain TYPO3 Core Engine parent object
  * @return void
  */
 public function processDatamap_afterDatabaseOperations($status, $table, $uid, array $fields, DataHandler $tceMain)
 {
     $recordTable = $table;
     $recordUid = $uid;
     $recordPageId = 0;
     if ($status == 'new') {
         $recordUid = $tceMain->substNEWwithIDs[$recordUid];
     }
     if (Util::isDraftRecord($table, $recordUid)) {
         // skip workspaces: index only LIVE workspace
         return;
     }
     if ($status == 'update' && !isset($fields['pid'])) {
         $recordPageId = $tceMain->getPID($recordTable, $recordUid);
         if ($recordTable == 'pages' && Util::isRootPage($recordUid)) {
             $recordPageId = $uid;
         }
     } else {
         $recordPageId = $fields['pid'];
     }
     // when a content element changes we need to updated the page instead
     if ($recordTable == 'tt_content') {
         $recordTable = 'pages';
         $recordUid = $recordPageId;
     }
     $this->solrConfiguration = Util::getSolrConfigurationFromPageId($recordPageId);
     $monitoredTables = $this->getMonitoredTables($recordPageId);
     if (in_array($recordTable, $monitoredTables, true)) {
         $record = $this->getRecord($recordTable, $recordUid);
         if (!empty($record)) {
             // only update/insert the item if we actually found a record
             if (Util::isLocalizedRecord($recordTable, $record)) {
                 // if it's a localization overlay, update the original record instead
                 $recordUid = $record[$GLOBALS['TCA'][$recordTable]['ctrl']['transOrigPointerField']];
                 if ($recordTable == 'pages_language_overlay') {
                     $recordTable = 'pages';
                 }
                 $tableEnableFields = implode(', ', $GLOBALS['TCA'][$recordTable]['ctrl']['enablecolumns']);
                 $l10nParentRecord = BackendUtility::getRecord($recordTable, $recordUid, $tableEnableFields, '', false);
                 if (!$this->isEnabledRecord($recordTable, $l10nParentRecord)) {
                     // the l10n parent record must be visible to have it's translation indexed
                     return;
                 }
             }
             // Clear existing index queue items to prevent mount point duplicates.
             if ($recordTable == 'pages') {
                 $this->indexQueue->deleteItem('pages', $recordUid);
             }
             if ($this->isEnabledRecord($recordTable, $record)) {
                 $configurationName = null;
                 if ($recordTable !== 'pages') {
                     $configurationName = $this->getIndexingConfigurationName($recordTable, $recordUid);
                 }
                 $this->indexQueue->updateItem($recordTable, $recordUid, $configurationName);
             }
             if ($recordTable == 'pages') {
                 $this->updateCanonicalPages($recordUid);
                 $this->updateMountPages($recordUid);
                 if ($this->isRecursiveUpdateRequired($recordUid, $fields)) {
                     $treePageIds = $this->getSubPageIds($recordUid);
                     foreach ($treePageIds as $treePageId) {
                         $this->indexQueue->updateItem('pages', $treePageId);
                     }
                 }
             }
         } else {
             // TODO move this part to the garbage collector
             // check if the item should be removed from the index because it no longer matches the conditions
             if ($this->indexQueue->containsItem($recordTable, $recordUid)) {
                 $this->removeFromIndexAndQueue($recordTable, $recordUid);
             }
         }
     }
 }
Esempio n. 30
0
 /**
  * Hook for updates in Typo3 backend
  * @param array $incomingFieldArray
  * @param string $table
  * @param integer $id
  * @param \TYPO3\CMS\Core\DataHandling\DataHandler $tceMain
  * @codingStandardsIgnoreStart
  */
 public function processDatamap_preProcessFieldArray(&$incomingFieldArray, $table, $id, \TYPO3\CMS\Core\DataHandling\DataHandler &$tceMain)
 {
     // @codingStandardsIgnoreEnd
     if (array_key_exists(self::FIELD_BEHAVIOR, $incomingFieldArray) && array_key_exists(self::FIELD_FLAG, $incomingFieldArray)) {
         $pid = $tceMain->getPID($table, $id);
         $this->updateMapping($table, $id, $incomingFieldArray[self::FIELD_FLAG], $pid, $incomingFieldArray[self::FIELD_BEHAVIOR]);
         unset($incomingFieldArray[self::FIELD_BEHAVIOR]);
         unset($incomingFieldArray[self::FIELD_FLAG]);
     }
 }