/** * Checks a special situation while inserting CEs if elements have been deleted * before. See bug #3042 */ public function test_insertElement_bug3042_part1() { global $TYPO3_DB, $BE_USER; $tce = t3lib_div::makeInstance('t3lib_TCEmain'); $tce->stripslashes_values = 0; $BE_USER->setWorkspace(-1); $this->fixture_createTestPage(); $this->fixture_createTestPageDSTO(); // Create 3 new content elements: $elementUids = array(); for ($i = 0; $i < 3; $i++) { $row = $this->fixture_getContentElementRow_TEXT(); $row['bodytext'] = 'insert test element #' . ($i + 1); $destinationPointer = array('table' => 'pages', 'uid' => $this->testPageUID, 'sheet' => 'sDEF', 'sLang' => 'lDEF', 'field' => 'field_content', 'vLang' => 'vDEF', 'position' => $i); $elementUids[$i + 1] = $this->apiObj->insertElement($destinationPointer, $row); } // Delete the second content element by calling TCEmain instead of using the TemplaVoila API. // We pass the UID of the CE with the content (overlayed UID), not the UID of the placeholder // record because that exposes the bug. $tce = t3lib_div::makeInstance('t3lib_TCEmain'); $tce->stripslashes_values = 0; $cmdMap = array('tt_content' => array(t3lib_beFunc::wsMapId('tt_content', $elementUids[2]) => array('delete' => 1))); $tce->start(array(), $cmdMap); $tce->process_cmdmap(); // Now insert an element after the second: $row = $this->fixture_getContentElementRow_TEXT(); $row['bodytext'] = 'insert test element #4'; $destinationPointer = array('table' => 'pages', 'uid' => $this->testPageUID, 'sheet' => 'sDEF', 'sLang' => 'lDEF', 'field' => 'field_content', 'vLang' => 'vDEF', 'position' => 2); $elementUids[4] = $this->apiObj->insertElement($destinationPointer, $row); self::assertTrue($elementUids[4] !== FALSE, 'Bug 3042 part one - Inserting a new element was not successful, insertElement() returned FALSE'); // Check if the new record has been inserted correctly behind the second one: $testPageRecord = t3lib_beFunc::getRecordWSOL('pages', $this->testPageUID, 'tx_templavoila_flex,uid,pid,t3ver_swapmode'); $flexform = simplexml_load_string($testPageRecord['tx_templavoila_flex']); $xpathResArr = $flexform->xpath("//data/sheet[@index='sDEF']/language[@index='lDEF']/field[@index='field_content']/value[@index='vDEF']"); self::assertEquals((string) $xpathResArr[0], $elementUids[1] . ',' . $elementUids[3] . ',' . $elementUids[4], 'insertElement_bug3042 - The pages reference list of the elements I created and deleted is not as expected!'); }
/** * Updates the XML structure with the new list of references to tt_content records. * * @param array $referencesArr: The array of tt_content uids (references list) to store in the record * @param array $destinationPointer: Flexform pointer to the location where the references list should be stored. * @return void * @access protected */ function flexform_storeElementReferencesListInRecord($referencesArr, $destinationPointer) { if ($this->debug) { t3lib_div::devLog('API: flexform_storeElementReferencesListInRecord()', 'templavoila', 0, array('referencesArr' => $referencesArr, 'destinationPointer' => $destinationPointer)); } $dataArr = array(); $uid = t3lib_beFunc::wsMapId($destinationPointer['table'], $destinationPointer['uid']); $dataArr[$destinationPointer['table']][$uid]['tx_templavoila_flex']['data'][$destinationPointer['sheet']][$destinationPointer['sLang']][$destinationPointer['field']][$destinationPointer['vLang']] = implode(',', $referencesArr); $flagWasSet = $this->getTCEmainRunningFlag(); $this->setTCEmainRunningFlag(TRUE); $tce = t3lib_div::makeInstance('t3lib_TCEmain'); $tce->stripslashes_values = 0; $tce->start($dataArr, array()); $tce->process_datamap(); if (!$flagWasSet) { $this->setTCEmainRunningFlag(FALSE); } }
/** * Updates the XML structure with the new list of references to tt_content records. * * @param array $referencesArr: The array of tt_content uids (references list) to store in the record * @param array $destinationPointer: Flexform pointer to the location where the references list should be stored. * @return void * @access protected */ function flexform_storeElementReferencesListInRecord($referencesArr, $destinationPointer) { if ($this->debug) { t3lib_div::devLog('API: flexform_storeElementReferencesListInRecord()', 'templavoila', 0, array('referencesArr' => $referencesArr, 'destinationPointer' => $destinationPointer)); } $dataArr = array(); $uid = t3lib_beFunc::wsMapId($destinationPointer['table'], $destinationPointer['uid']); $containerHasWorkspaceVersion = FALSE; if ($uid != $destinationPointer['uid']) { $containerHasWorkspaceVersion = TRUE; } $dataArr[$destinationPointer['table']][$uid]['tx_templavoila_flex']['data'][$destinationPointer['sheet']][$destinationPointer['sLang']][$destinationPointer['field']][$destinationPointer['vLang']] = implode(',', $referencesArr); $flagWasSet = $this->getTCEmainRunningFlag(); $this->setTCEmainRunningFlag(TRUE); $tce = t3lib_div::makeInstance('t3lib_TCEmain'); $tce->stripslashes_values = 0; $tce->start($dataArr, array()); /** * Set workspace to 0 because: * 1) we want shadow-records to be placed in the Live-Workspace * 2) there's no need to create a new version of the parent-record * 3) try to avoid issues if the same list is modified in different workspaces at the same time */ if ($this->modifyReferencesInLiveWS && !$containerHasWorkspaceVersion) { if ($tce->BE_USER->groupData['allowed_languages']) { //force access to default language - since references needs to be stored in default langauage always $tce->BE_USER->groupData['allowed_languages'] .= ',0'; } $tce->BE_USER->workspace = 0; } $tce->process_datamap(); if (!$flagWasSet) { $this->setTCEmainRunningFlag(FALSE); } }