/** * 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(); } } }
/** * Release version from this workspace (and into "Live" workspace but as an offline version). * * @param string $table Table name * @param int $id Record UID * @param bool $flush If set, will completely delete element * @param DataHandler $tcemainObj TCEmain object * @return void */ protected function version_clearWSID($table, $id, $flush = FALSE, DataHandler $tcemainObj) { if ($errorCode = $tcemainObj->BE_USER->workspaceCannotEditOfflineVersion($table, $id)) { $tcemainObj->newlog('Attempt to reset workspace for record failed: ' . $errorCode, 1); return; } if (!$tcemainObj->checkRecordUpdateAccess($table, $id)) { $tcemainObj->newlog('Attempt to reset workspace for record failed because you do not have edit access', 1); return; } $liveRec = BackendUtility::getLiveVersionOfRecord($table, $id, 'uid,t3ver_state'); if (!$liveRec) { return; } // Clear workspace ID: $updateData = array('t3ver_wsid' => 0, 't3ver_tstamp' => $GLOBALS['EXEC_TIME']); $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid=' . (int) $id, $updateData); // Clear workspace ID for live version AND DELETE IT as well because it is a new record! if (VersionState::cast($liveRec['t3ver_state'])->equals(VersionState::NEW_PLACEHOLDER) || VersionState::cast($liveRec['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) { $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid=' . (int) $liveRec['uid'], $updateData); // THIS assumes that the record was placeholder ONLY for ONE record (namely $id) $tcemainObj->deleteEl($table, $liveRec['uid'], TRUE); } // If "deleted" flag is set for the version that got released // it doesn't make sense to keep that "placeholder" anymore and we delete it completly. $wsRec = BackendUtility::getRecord($table, $id); if ($flush || (VersionState::cast($wsRec['t3ver_state'])->equals(VersionState::NEW_PLACEHOLDER) || VersionState::cast($wsRec['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER))) { $tcemainObj->deleteEl($table, $id, TRUE, TRUE); } // Remove the move-placeholder if found for live record. if ((int) $GLOBALS['TCA'][$table]['ctrl']['versioningWS'] >= 2) { if ($plhRec = BackendUtility::getMovePlaceholder($table, $liveRec['uid'], 'uid')) { $tcemainObj->deleteEl($table, $plhRec['uid'], TRUE, TRUE); } } }
/** * Release version from this workspace (and into "Live" workspace but as an offline version). * * @param string $table Table name * @param int $id Record UID * @param bool $flush If set, will completely delete element * @param DataHandler $dataHandler DataHandler object * @return void */ protected function version_clearWSID($table, $id, $flush = false, DataHandler $dataHandler) { if ($errorCode = $dataHandler->BE_USER->workspaceCannotEditOfflineVersion($table, $id)) { $dataHandler->newlog('Attempt to reset workspace for record failed: ' . $errorCode, 1); return; } if (!$dataHandler->checkRecordUpdateAccess($table, $id)) { $dataHandler->newlog('Attempt to reset workspace for record failed because you do not have edit access', 1); return; } $liveRec = BackendUtility::getLiveVersionOfRecord($table, $id, 'uid,t3ver_state'); if (!$liveRec) { return; } // Clear workspace ID: $updateData = ['t3ver_wsid' => 0, 't3ver_tstamp' => $GLOBALS['EXEC_TIME']]; $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table); $connection->update($table, $updateData, ['uid' => (int) $id]); // Clear workspace ID for live version AND DELETE IT as well because it is a new record! if (VersionState::cast($liveRec['t3ver_state'])->equals(VersionState::NEW_PLACEHOLDER) || VersionState::cast($liveRec['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) { $connection->update($table, $updateData, ['uid' => (int) $liveRec['uid']]); // THIS assumes that the record was placeholder ONLY for ONE record (namely $id) $dataHandler->deleteEl($table, $liveRec['uid'], true); } // If "deleted" flag is set for the version that got released // it doesn't make sense to keep that "placeholder" anymore and we delete it completly. $wsRec = BackendUtility::getRecord($table, $id); if ($flush || (VersionState::cast($wsRec['t3ver_state'])->equals(VersionState::NEW_PLACEHOLDER) || VersionState::cast($wsRec['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER))) { $dataHandler->deleteEl($table, $id, true, true); } // Remove the move-placeholder if found for live record. if (BackendUtility::isTableWorkspaceEnabled($table)) { if ($plhRec = BackendUtility::getMovePlaceholder($table, $liveRec['uid'], 'uid')) { $dataHandler->deleteEl($table, $plhRec['uid'], true, true); } } }