/** * Copies a column into another column on the same or different table. * Fails if the columns don't exist in either table. * * @param string $table * @param string $sourceField * @param string $destinationField * @throws \Exception */ protected function copyField($table, $sourceField, $destinationField) { $this->expectColumns($table, array($sourceField, $destinationField), "Can't copy {$sourceField} to {$destinationField} in {$table}"); $this->db->exec_UPDATEquery($table, '', array($destinationField => $sourceField), array($destinationField)); $this->success("Copied field in table {$table} from {$sourceField} to {$destinationField}"); return; }
/** * Updates an already existing board record and stores it into the database. * * @author Martin Helmich <*****@*****.**> * @version 2008-05-16 * @return void */ function save_editForum() { $res = $this->databaseHandle->exec_SELECTquery('*', 'tx_mmforum_forums', 'uid=' . intval($this->param['fid'])); $ctg = $this->databaseHandle->sql_fetch_assoc($res); $updateArray = array('tstamp' => $GLOBALS['EXEC_TIME'], 'hidden' => $this->param['forum']['hidden'], 'forum_name' => trim($this->param['forum']['title']), 'forum_desc' => trim($this->param['forum']['desc']), 'grouprights_read' => $this->param['forum']['authRead'], 'grouprights_write' => $this->param['forum']['authWrite'], 'grouprights_mod' => $this->param['forum']['authMod']); if (strlen($updateArray['forum_name']) == 0) { return array('title' => '<div class="mm_forum-fatalerror">' . $this->getLL('error.noTitle') . '</div>'); } if ($this->param['forum']['order'] == 'first') { $updateArray['sorting'] = 0; if ($ctg['sorting'] != 0) { $this->globalIncSorting(0, 1, $this->param['forum']['parentID']); } } elseif ($this->param['forum']['order'] == 'last') { $updateArray['sorting'] = $this->getMaxSorting() + 1; } else { if ($this->param['forum']['order'] != $ctg['sorting']) { $this->globalIncSorting($this->param['forum']['order'], 2, $this->param['forum']['parentID']); } $updateArray['sorting'] = $this->param['forum']['order']; } $this->databaseHandle->exec_UPDATEquery('tx_mmforum_forums', 'uid=' . intval($this->param['fid']), $updateArray); if ($updateArray['grouprights_read'] != $ctg['grouprights_read']) { $this->delete_forumIndex($ctg['uid']); } }
/** * Release a process and the required resources * * @param mixed $releaseIds string with a single process-id or array with multiple process-ids * @param boolean $withinLock show whether the DB-actions are included within an existing lock * @return boolean */ function CLI_releaseProcesses($releaseIds, $withinLock = false) { if (!is_array($releaseIds)) { $releaseIds = array($releaseIds); } if (!count($releaseIds) > 0) { return false; //nothing to release } if (!$withinLock) { $this->db->sql_query('BEGIN'); } // some kind of 2nd chance algo - this way you need at least 2 processes to have a real cleanup // this ensures that a single process can't mess up the entire process table // mark all processes as deleted which have no "waiting" queue-entires and which are not active $this->db->exec_UPDATEquery('tx_crawler_queue', 'process_id IN (SELECT process_id FROM tx_crawler_process WHERE active=0 AND deleted=0)', array('process_scheduled' => 0, 'process_id' => '')); $this->db->exec_UPDATEquery('tx_crawler_process', 'active=0 AND deleted=0 AND NOT EXISTS ( SELECT * FROM tx_crawler_queue WHERE tx_crawler_queue.process_id = tx_crawler_process.process_id AND tx_crawler_queue.exec_time = 0 )', array('deleted' => '1', 'system_process_id' => 0)); // mark all requested processes as non-active $this->db->exec_UPDATEquery('tx_crawler_process', 'process_id IN (\'' . implode('\',\'', $releaseIds) . '\') AND deleted=0', array('active' => '0')); $this->db->exec_UPDATEquery('tx_crawler_queue', 'exec_time=0 AND process_id IN ("' . implode('","', $releaseIds) . '")', array('process_scheduled' => 0, 'process_id' => '')); if (!$withinLock) { $this->db->sql_query('COMMIT'); } return true; }
/** * Save query in action * * @param int $uid * @return int */ public function saveQueryInAction($uid) { if (ExtensionManagementUtility::isLoaded('sys_action')) { $keyArr = explode(',', $this->storeList); $saveArr = array(); foreach ($keyArr as $k) { $saveArr[$k] = $GLOBALS['SOBE']->MOD_SETTINGS[$k]; } $qOK = 0; // Show query if ($saveArr['queryTable']) { /** @var \TYPO3\CMS\Core\Database\QueryGenerator */ $qGen = GeneralUtility::makeInstance(QueryGenerator::class); $qGen->init('queryConfig', $saveArr['queryTable']); $qGen->makeSelectorTable($saveArr); $qGen->enablePrefix = 1; $qString = $qGen->getQuery($qGen->queryConfig); $qCount = $this->databaseConnection->SELECTquery('count(*)', $qGen->table, $qString . BackendUtility::deleteClause($qGen->table)); $qSelect = $qGen->getSelectQuery($qString); $res = @$this->databaseConnection->sql_query($qCount); if (!$this->databaseConnection->sql_error()) { $this->databaseConnection->sql_free_result($res); $dA = array(); $dA['t2_data'] = serialize(array('qC' => $saveArr, 'qCount' => $qCount, 'qSelect' => $qSelect, 'qString' => $qString)); $this->databaseConnection->exec_UPDATEquery('sys_action', 'uid=' . (int) $uid, $dA); $qOK = 1; } } return $qOK; } return null; }
/** * Performs the database update. * * @param array $dbQueries queries done in this update * @param mixed $customMessages custom messages * @return boolean TRUE on success, FALSE on error */ public function performUpdate(array &$dbQueries, &$customMessages) { $this->init(); if (!PATH_site) { throw new \Exception('PATH_site was undefined.'); } $fileadminDirectory = rtrim($GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'], '/'); $targetDirectory = '/_migrated/RTE/'; $fullTargetDirectory = PATH_site . $fileadminDirectory . $targetDirectory; // Create the directory, if necessary if (!is_dir($fullTargetDirectory)) { \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($fullTargetDirectory); } $oldRecords = $this->findMagicImagesInOldLocation(); foreach ($oldRecords as $refRecord) { // Is usually uploads/RTE_magicC_123423324.png.png $sourceFileName = $refRecord['ref_string']; // Absolute path/filename $fullSourceFileName = PATH_site . $refRecord['ref_string']; $targetFileName = $targetDirectory . \TYPO3\CMS\Core\Utility\PathUtility::basename($refRecord['ref_string']); // Full directory $fullTargetFileName = $fullTargetDirectory . \TYPO3\CMS\Core\Utility\PathUtility::basename($refRecord['ref_string']); // maybe the file has been moved previously if (!file_exists($fullTargetFileName)) { // If the source file does not exist, we should just continue, but leave a message in the docs; // ideally, the user would be informed after the update as well. if (!file_exists(PATH_site . $sourceFileName)) { $this->logger->notice('File ' . $sourceFileName . ' does not exist. Reference was not migrated.', array()); $format = 'File \'%s\' does not exist. Referencing field: %s.%d.%s. The reference was not migrated.'; $message = sprintf($format, $sourceFileName, $refRecord['tablename'], $refRecord['recuid'], $refRecord['field']); $customMessages .= PHP_EOL . $message; continue; } rename($fullSourceFileName, $fullTargetFileName); } // Get the File object $file = $this->storage->getFile($targetFileName); if ($file instanceof \TYPO3\CMS\Core\Resource\File) { // And now update the referencing field $targetFieldName = $refRecord['field']; $targetRecord = $this->db->exec_SELECTgetSingleRow('uid, ' . $targetFieldName, $refRecord['tablename'], 'uid=' . (int) $refRecord['recuid']); if ($targetRecord) { // Replace the old filename with the new one, and add data-* attributes used by the RTE $searchString = 'src="' . $sourceFileName . '"'; $replacementString = 'src="' . $fileadminDirectory . $targetFileName . '"'; $replacementString .= ' data-htmlarea-file-uid="' . $file->getUid() . '"'; $replacementString .= ' data-htmlarea-file-table="sys_file"'; $targetRecord[$targetFieldName] = str_replace($searchString, $replacementString, $targetRecord[$targetFieldName]); // Update the record $this->db->exec_UPDATEquery($refRecord['tablename'], 'uid=' . (int) $refRecord['recuid'], array($targetFieldName => $targetRecord[$targetFieldName])); $queries[] = str_replace(LF, ' ', $this->db->debug_lastBuiltQuery); // Finally, update the sys_refindex table as well $this->db->exec_UPDATEquery('sys_refindex', 'hash=' . $this->db->fullQuoteStr($refRecord['hash'], 'sys_refindex'), array('ref_table' => 'sys_file', 'softref_key' => 'rtehtmlarea_images', 'ref_uid' => $file->getUid(), 'ref_string' => $fileadminDirectory . $targetFileName)); $queries[] = str_replace(LF, ' ', $this->db->debug_lastBuiltQuery); } } } return TRUE; }
/** * Relative filemounts are transformed to relate to our fileadmin/ storage * and their path is modified to be a valid resource location * * @return void */ protected function migrateRelativeFilemounts() { $relativeFilemounts = $this->db->exec_SELECTgetRows('*', 'sys_filemounts', 'base = 1' . BackendUtility::deleteClause('sys_filemounts')); foreach ($relativeFilemounts as $filemount) { $this->db->exec_UPDATEquery('sys_filemounts', 'uid=' . (int) $filemount['uid'], array('base' => $this->storage->getUid(), 'path' => '/' . ltrim($filemount['path'], '/'))); $this->sqlQueries[] = $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery; } }
/** * * Updates a topics's post count. * * @author Martin Helmich <*****@*****.**> * @version 2007-07-21 * @param int $topic_uid The UID of the topic whose post count is to be * updated * @param string $orderBy The column name of the tx_mmforum_posts table * used for ordering posts (see * http://forge.typo3.org/issues/show/3520 for * for more information). * @return void */ function updateTopicPostCount($topic_uid, $orderBy = 'post_time') { $topic_uid = intval($topic_uid); $res = $this->databaseHandle->exec_SELECTquery('uid', 'tx_mmforum_posts', 'topic_id=' . $topic_uid . ' AND deleted=0' . $this->getPidQuery(), '', $orderBy . ' DESC'); list($last_post_id) = $this->databaseHandle->sql_fetch_row($res); $postcount = $this->databaseHandle->sql_num_rows($res); $updateArray = array('tstamp' => $GLOBALS['EXEC_TIME'], 'topic_last_post_id' => $last_post_id, 'topic_replies' => $postcount - 1); $this->databaseHandle->exec_UPDATEquery('tx_mmforum_topics', 'uid=' . $topic_uid, $updateArray); }
/** * Updates an existing file object in the database * * @param ProcessedFile $processedFile * @return void */ public function update($processedFile) { if ($processedFile->isPersisted()) { $uid = (int) $processedFile->getUid(); $updateFields = $this->cleanUnavailableColumns($processedFile->toArray()); $updateFields['tstamp'] = time(); $this->databaseConnection->exec_UPDATEquery($this->table, 'uid=' . (int) $uid, $updateFields); } }
/** * @test * @return void */ public function canLoadADummyCollectionFromDatabaseAfterRemoveOneRelation() { // Remove one relation $fakeName = array('tablenames' => $this->getUniqueId('name')); $this->database->exec_UPDATEquery('sys_category_record_mm', 'uid_foreign = 1', $fakeName); // Check the number of records $collection = \TYPO3\CMS\Core\Category\Collection\CategoryCollection::load($this->categoryUid, true, $this->tableName); $this->assertEquals($this->numberOfRecords - 1, $collection->count()); }
/** * Sets the entry to cache. * * @param UrlCacheEntry $cacheEntry * @return void */ public function putUrlToCache(UrlCacheEntry $cacheEntry) { $data = array('original_url' => $cacheEntry->getOriginalUrl(), 'page_id' => $cacheEntry->getPageId(), 'request_variables' => json_encode($cacheEntry->getRequestVariables()), 'rootpage_id' => $cacheEntry->getRootPageId(), 'speaking_url' => $cacheEntry->getSpeakingUrl()); if ($cacheEntry->getCacheId()) { $this->databaseConnection->exec_UPDATEquery('tx_realurl_urlcache', 'uid=' . $this->databaseConnection->fullQuoteStr($cacheEntry->getCacheId(), 'tx_realurl_urlcache'), $data); } else { $this->databaseConnection->exec_INSERTquery('tx_realurl_urlcache', $data); $cacheEntry->setCacheId($this->databaseConnection->sql_insert_id()); } }
/** * updates the IRRE data in the feedimport record, so that image records are * displayed correctly beneith the image select box */ private function updateFeedImportRecord() { $feedImportUid = $this->feedImport['uid']; $imgUids = array(); foreach ($this->images as $fileName => $image) { $imgUids[] = $image['uid']; } $updateRecord = array('image_records' => implode(',', $imgUids), 'tstamp' => time()); $this->db->exec_UPDATEquery('tx_gorillary_feedimports', "uid='{$feedImportUid}'", $updateRecord); }
/** * Sets current_version = 1 for all extensions where the extension version is maximal. * * For performance reasons, the "native" TYPO3_DB is used here directly. * * @param int $repositoryUid * @return void */ protected function markExtensionWithMaximumVersionAsCurrent($repositoryUid) { $uidsOfCurrentVersion = $this->fetchMaximalVersionsForAllExtensions($repositoryUid); // some DBMS limit the amount of expressions, apply the update in chunks $chunks = array_chunk($uidsOfCurrentVersion, self::CHUNK_SIZE); $chunkCount = count($chunks); for ($i = 0; $i < $chunkCount; ++$i) { $this->databaseConnection->exec_UPDATEquery(self::TABLE_NAME, 'uid IN (' . implode(',', $chunks[$i]) . ')', array('current_version' => 1)); } }
/** * updates the IRRE data in the collection record, so that image records are * displayed correctly beneith the image select box */ private function updateCollectionRecord() { $collectionId = $this->collection['uid']; $imgUids = array(); $fileNames = $this->collection['images']; $fileNames = explode(',', $fileNames); foreach ($fileNames as $filename) { $imgUids[] = $this->images[$filename]['uid']; } $updateRecord = array('image_records' => implode(',', $imgUids), 'tstamp' => time()); $this->db->exec_UPDATEquery('tx_gorillary_collections', "uid='{$collectionId}'", $updateRecord); }
/** * Update categories in flexforms * * @param string $pluginName * @param array $oldNewCategoryUidMapping * @param string $flexformField name of the flexform's field to look for * @return void */ protected function updateFlexformCategories($pluginName, $oldNewCategoryUidMapping, $flexformField) { $count = 0; $title = 'Update flexforms categories (' . $pluginName . ':' . $flexformField . ')'; $res = $this->databaseConnection->exec_SELECTquery('uid, pi_flexform', 'tt_content', 'CType=\'list\' AND list_type=\'' . $pluginName . '\' AND deleted=0'); /** @var \TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools $flexformTools */ $flexformTools = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\FlexForm\\FlexFormTools'); while ($row = $this->databaseConnection->sql_fetch_assoc($res)) { $status = null; $xmlArray = GeneralUtility::xml2array($row['pi_flexform']); if (!is_array($xmlArray) || !isset($xmlArray['data'])) { $status = FlashMessage::ERROR; $message = 'Flexform data of plugin "' . $pluginName . '" not found.'; } elseif (!isset($xmlArray['data']['sDEF']['lDEF'])) { $status = FlashMessage::WARNING; $message = 'Flexform data of record tt_content:' . $row['uid'] . ' did not contain sheet: sDEF'; } elseif (isset($xmlArray[$flexformField . '_updated'])) { $status = FlashMessage::NOTICE; $message = 'Flexform data of record tt_content:' . $row['uid'] . ' is already updated for ' . $flexformField . '. No update needed...'; } else { // Some flexforms may have displayCond if (isset($xmlArray['data']['sDEF']['lDEF'][$flexformField]['vDEF'])) { $updated = false; $oldCategories = GeneralUtility::trimExplode(',', $xmlArray['data']['sDEF']['lDEF'][$flexformField]['vDEF'], true); if (!empty($oldCategories)) { $newCategories = array(); foreach ($oldCategories as $uid) { if (isset($oldNewCategoryUidMapping[$uid])) { $newCategories[] = $oldNewCategoryUidMapping[$uid]; $updated = true; } else { $status = FlashMessage::WARNING; $message = 'The category ' . $uid . ' of record tt_content:' . $row['uid'] . ' was not found in sys_category records. Maybe the category was deleted before the migration? Please check manually...'; } } if ($updated) { $count++; $xmlArray[$flexformField . '_updated'] = 1; $xmlArray['data']['sDEF']['lDEF'][$flexformField]['vDEF'] = implode(',', $newCategories); $this->databaseConnection->exec_UPDATEquery('tt_content', 'uid=' . $row['uid'], array('pi_flexform' => $flexformTools->flexArray2Xml($xmlArray))); } } } } if ($status !== null) { $this->messageArray[] = array($status, $title, $message); } } $status = FlashMessage::INFO; $message = 'Updated ' . $count . ' tt_content flexforms for "' . $pluginName . ':' . $flexformField . '"'; $this->messageArray[] = array($status, $title, $message); }
/** * */ protected function migrateTtContentPlugins() { $contentElements = $this->databaseConnection->exec_SELECTgetRows('*', 'tt_content', '1=1'); foreach ($contentElements as $contentElement) { foreach ($this->legacyTtContentListTypes as $legacyTtContentListType) { $newTtContentListType = str_replace('mmforum_', 'typo3forum_', $legacyTtContentListType); if ($contentElement['list_type'] === $legacyTtContentListType) { $contentElement['list_type'] = $newTtContentListType; $this->databaseConnection->exec_UPDATEquery('tt_content', 'uid = ' . (int) $contentElement['uid'], $contentElement); } } } }
/** * Updates a relation row in the storage. * * @param string $tableName The database relation table name * @param array $fieldValues The row to be updated * @throws \InvalidArgumentException * @return bool */ public function updateRelationTableRow($tableName, array $fieldValues) { if (!isset($fieldValues['uid_local']) && !isset($fieldValues['uid_foreign'])) { throw new \InvalidArgumentException('The given fieldValues must contain a value for "uid_local" and "uid_foreign".', 1360500126); } $where['uid_local'] = (int) $fieldValues['uid_local']; $where['uid_foreign'] = (int) $fieldValues['uid_foreign']; unset($fieldValues['uid_local']); unset($fieldValues['uid_foreign']); $updateSuccessful = $this->databaseHandle->exec_UPDATEquery($tableName, $this->resolveWhereStatement($where, $tableName), $fieldValues); $this->checkSqlErrors(); return $updateSuccessful; }
/** * Db update object * * @param int $uid Uid * @param Tx_Commerce_Dao_BasicDaoObject $object Object * * @return void */ protected function dbUpdate($uid, Tx_Commerce_Dao_BasicDaoObject &$object) { $dbTable = $this->dbTable; $dbWhere = 'uid = ' . (int) $uid; $dbModel = $this->parser->parseObjectToModel($object); // execute query $this->database->exec_UPDATEquery($dbTable, $dbWhere, $dbModel); // any errors $error = $this->database->sql_error(); if (!empty($error)) { $this->addError(array($error, $this->database->UPDATEquery($dbTable, $dbWhere, $dbModel), '$dbModel' => $dbModel)); } }
/** * Update the current_version field after update * For performance reason "native" TYPO3_DB is * used here directly. * * @param integer $repositoryUid * @return integer */ public function insertLastVersion($repositoryUid = 1) { $groupedRows = $this->databaseConnection->exec_SELECTgetRows('extension_key, max(integer_version) as maxintversion', 'tx_extensionmanager_domain_model_extension', 'repository=' . intval($repositoryUid), 'extension_key'); $extensions = count($groupedRows); if ($extensions > 0) { // set all to 0 $this->databaseConnection->exec_UPDATEquery('tx_extensionmanager_domain_model_extension', 'current_version=1 AND repository=' . intval($repositoryUid), array('current_version' => 0)); // Find latest version of extensions and set current_version to 1 for these foreach ($groupedRows as $row) { $this->databaseConnection->exec_UPDATEquery('tx_extensionmanager_domain_model_extension', 'extension_key=' . $this->databaseConnection->fullQuoteStr($row['extension_key'], 'tx_extensionmanager_domain_model_extension') . ' AND integer_version=' . intval($row['maxintversion']) . ' AND repository=' . intval($repositoryUid), array('current_version' => 1)); } } return $extensions; }
/** * Migrate locations with relations * * @return void */ protected function migrateLocations() { $locations = $this->fetchLocations(); while ($row = $this->database->sql_fetch_assoc($locations)) { $location = $this->mapFieldsPreImport($row, 'locations'); $table = 'tx_storefinder_domain_model_location'; if ($record = $this->isAlreadyImported($location, $table)) { unset($location['import_id']); $this->database->exec_UPDATEquery($table, 'uid = ' . $record['uid'], $location); $this->records['locations'][$row['uid']] = $location['uid'] = $record['uid']; } else { $this->database->exec_INSERTquery($table, $location); $this->records['locations'][$row['uid']] = $location['uid'] = $this->database->sql_insert_id(); } $this->mapFieldsPostImport($row, $location, 'locations'); $this->migrateFilesToFal($row, $location, $this->fileMapping['locations']['media']); $this->migrateFilesToFal($row, $location, $this->fileMapping['locations']['imageurl']); $this->migrateFilesToFal($row, $location, $this->fileMapping['locations']['icon']); } $this->database->sql_query(' update tx_storefinder_domain_model_location AS l LEFT JOIN ( SELECT uid_foreign, COUNT(*) AS count FROM sys_category_record_mm WHERE tablenames = \'tx_storefinder_domain_model_location\' AND fieldname = \'categories\' GROUP BY uid_foreign ) AS c ON l.uid = c.uid_foreign set l.categories = COALESCE(c.count, 0); '); $this->database->sql_query(' update tx_storefinder_domain_model_location AS l LEFT JOIN ( SELECT uid_local, COUNT(*) AS count FROM tx_storefinder_location_attribute_mm GROUP BY uid_local ) AS a ON l.uid = a.uid_local set l.attributes = COALESCE(a.count, 0); '); $this->database->sql_query(' update tx_storefinder_domain_model_location AS l LEFT JOIN ( SELECT uid_local, COUNT(*) AS count FROM tx_storefinder_location_location_mm GROUP BY uid_local ) AS a ON l.uid = a.uid_local set l.related = COALESCE(a.count, 0); '); $this->messageArray[] = array('message' => count($this->records['locations']) . ' locations migrated'); }
/** * Log the access of the file * * @param integer|null $intFileSize */ protected function logDownload($intFileSize = null) { if ($this->isLoggingEnabled()) { if (is_null($intFileSize)) { $intFileSize = $this->fileSize; } $data_array = array('tstamp' => time(), 'file_name' => $this->file, 'file_size' => $intFileSize, 'user_id' => intval($this->feUserObj->user['uid'])); if (is_null($this->logRowUid)) { $this->databaseConnection->exec_INSERTquery('tx_nawsecuredl_counter', $data_array); $this->logRowUid = $this->databaseConnection->sql_insert_id(); } else { $this->databaseConnection->exec_UPDATEquery('tx_nawsecuredl_counter', '`uid`=' . (int) $this->logRowUid, $data_array); } } }
/** * Sets the entry to cache. * * @param UrlCacheEntry $cacheEntry * @return void */ public function putUrlToCache(UrlCacheEntry $cacheEntry) { $data = array('expire' => $cacheEntry->getExpiration(), 'original_url' => $cacheEntry->getOriginalUrl(), 'page_id' => $cacheEntry->getPageId(), 'request_variables' => json_encode($cacheEntry->getRequestVariables()), 'rootpage_id' => $cacheEntry->getRootPageId(), 'speaking_url' => $cacheEntry->getSpeakingUrl()); if ($cacheEntry->getCacheId()) { $this->databaseConnection->exec_UPDATEquery('tx_realurl_urldata', 'uid=' . $this->databaseConnection->fullQuoteStr($cacheEntry->getCacheId(), 'tx_realurl_urldata'), $data); } else { $this->databaseConnection->sql_query('START TRANSACTION'); if ($this->limitTableRecords('tx_realurl_urldata')) { $this->databaseConnection->sql_query('DELETE FROM tx_realurl_uniqalias_cache_map WHERE url_cache_id NOT IN (SELECT uid FROM tx_realurl_urldata)'); } $this->databaseConnection->exec_INSERTquery('tx_realurl_urldata', $data); $cacheEntry->setCacheId($this->databaseConnection->sql_insert_id()); $this->databaseConnection->sql_query('COMMIT'); } }
/** * Writes changes into database * * @return void */ public function updateDatabase() { if (!is_array($this->data)) { return; } $diff = array_diff_assoc($this->data, $this->origData); foreach ($diff as $key => $value) { if (!isset($this->data[$key])) { unset($diff[$key]); } } if (!empty($diff)) { $this->data['tstamp'] = $diff['tstamp'] = $GLOBALS['EXEC_TIME']; if (intVal($this->data['uid']) > 0) { $this->databaseHandle->exec_UPDATEquery($this->getTableName(), 'uid=' . $this->getUid(), $diff); } else { $this->data['crdate'] = $diff['crdate'] = $GLOBALS['EXEC_TIME']; $this->databaseHandle->exec_INSERTquery($this->getTableName(), $diff); $this->setUid($this->databaseHandle->sql_insert_id()); $this->data['uid'] = $this->getUid(); } $this->origData = $this->data; } }
/** * * Moves a forum downwards. * * @access private * @param Integer $forumUid The UID of the forum that is to be moved. * @return void|bool */ function moveForumDown($forumUid) { $forumData = $this->p->getBoardData($forumUid); if (!$this->checkActionAllowance($forumData['parentID'] == 0 ? 'category' : 'forum', 'order')) { $this->flashmessage = $this->l('access-error'); return FALSE; } $res = $this->databaseHandle->exec_SELECTquery('uid, sorting', 'tx_mmforum_forums', 'deleted=0 AND parentID=' . $forumData['parentID'] . ' AND sorting > ' . $forumData['sorting'], '', 'sorting ASC', 1); if ($this->databaseHandle->sql_num_rows($res) == 0) { return; } list($lowerUid, $lowerSorting) = $this->databaseHandle->sql_fetch_row($res); $this->databaseHandle->exec_UPDATEquery('tx_mmforum_forums', 'uid=' . $forumData['uid'], array('sorting' => $lowerSorting, 'tstamp' => $GLOBALS['EXEC_TIME'])); $this->databaseHandle->exec_UPDATEquery('tx_mmforum_forums', 'uid=' . $lowerUid, array('sorting' => $forumData['sorting'], 'tstamp' => $GLOBALS['EXEC_TIME'])); }
/** * Update records * * @param array $postRecord * @param string $textBeforeDivider * @param array $firstImageRecord */ protected function updatePostRecord($postRecord, $textBeforeDivider, $firstImageRecord) { $data = array('preview_text' => $textBeforeDivider); if ($firstImageRecord !== NULL) { $fileObjectArray = $this->getFileRepository()->findByRelation('tt_content', 'image', $firstImageRecord['uid']); if (is_array($fileObjectArray) && count($fileObjectArray) > 0) { // Get the first file $fileObject = reset($fileObjectArray); $data['preview_image'] = 1; $this->createPostSysFileReference($fileObject, $postRecord); } } // Update post $this->databaseConnection->exec_UPDATEquery('tx_t3blog_post', 'uid=' . (int) $postRecord['uid'] . $this->getNonPreviewWhereClause(), $data); $this->logDatabaseExec(); }
/** * Creates a frontend user based on the data of the social user * * @param array $user * @param string $provider * @param string $identifier * * @return array|FALSE the created identity record or false if it is not possible */ protected function addIdentityToFrontendUser($user, $provider, $identifier) { $result = false; $identityClassName = 'Portrino\\PxHybridAuth\\Domain\\Model\\Identity\\' . $provider . 'Identity'; if (class_exists($identityClassName) && defined($identityClassName . '::EXTBASE_TYPE')) { $extbaseType = constant($identityClassName . '::EXTBASE_TYPE'); $this->database->exec_INSERTquery('tx_pxhybridauth_domain_model_identity', ['pid' => $user['pid'], 'tx_extbase_type' => $extbaseType, 'identifier' => $identifier, 'fe_user' => $user['uid'], 'hidden' => 0, 'deleted' => 0, 'tstamp' => time(), 'crdate' => time()]); $id = $this->database->sql_insert_id(); $where = 'uid=' . intval($id); $result = $this->database->exec_SELECTgetSingleRow('*', 'tx_pxhybridauth_domain_model_identity', $where); if ($result) { $this->database->exec_UPDATEquery('fe_users', 'uid=' . intval($user['uid']), ['tx_pxhybridauth_identities' => 1]); } } return $result; }
/** * Function to handle record actions for children of translated grid containers * * @param array $containerUpdateArray * * @return void */ public function checkAndUpdateTranslatedChildren($containerUpdateArray = array()) { if (is_array($containerUpdateArray) && count($containerUpdateArray > 0)) { foreach ($containerUpdateArray as $containerUid => $newElement) { $translatedContainers = $this->databaseConnection->exec_SELECTgetRows('uid,sys_language_uid', 'tt_content', 'l18n_parent = ' . (int) $containerUid . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('tt_content')); if (count($translatedContainers) > 0) { foreach ($translatedContainers as $languageArray) { $targetContainer = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordWSOL('tt_content', $languageArray['uid']); $fieldArray['tx_gridelements_container'] = $targetContainer['uid']; $where = 'tx_gridelements_container = ' . (int) $containerUid . ' AND sys_language_uid = ' . (int) $targetContainer['sys_language_uid']; $this->databaseConnection->exec_UPDATEquery('tt_content', $where, $fieldArray, 'tx_gridelements_container'); $this->getTceMain()->updateRefIndex('tt_content', (int) $targetContainer['uid']); } } } } }
/** * Update existing record * * @return int uid of updated record */ protected function update() { // find existing record in database $searchterm = $this->databaseConnection->fullQuoteStr($this->getProperty($this->getUniqueField()), $this->getTable()); $res = $this->databaseConnection->exec_SELECTquery('uid', $this->getTable(), $this->getUniqueField() . ' = ' . $searchterm . ' and deleted = 0 ' . $this->getAdditionalWhereClause(), '', '', 1); if ($res) { $row = $this->databaseConnection->sql_fetch_assoc($res); } // if there is no existing entry, insert new one if (empty($row['uid'])) { return $this->insert(); } // update existing entry (only if mode is not "none") if ($this->getMode() !== 'none') { $this->databaseConnection->exec_UPDATEquery($this->getTable(), 'uid = ' . (int) $row['uid'], $this->getProperties()); } return $row['uid']; }
/** * Saves a value for a user for this field. * This function stores a value for this field for a specific user. * Depending on the field type, the value is stored either into the * fe_users table directly, or into the tx_mmforum_userfields_contents * table. * * @param int $userId The UID of the user for whom the value is to be * added. * @param string $value The value that is to be stored into this field. * @param int $pid The page UID of the data storage page. Submitting * this value as a parameter is just a dirty workaround. * @return void * * @author Martin Helmich <*****@*****.**> * @version 2009-02-16 */ function setForUser($userId, $value, $pid = 0) { /* If the userfield uses an existing field from the fe_users * table, generate an UPDATE query to edit the fe_user record. */ if ($this->isUsingExistingField()) { $updateArray = array('tstamp' => $GLOBALS['EXEC_TIME'], $this->getLinkedUserField() => trim($value)); $this->databaseHandle->exec_UPDATEquery('fe_users', 'uid=' . intval($userId), $updateArray); /* If the userfield does NOT use a field from the fe_users table * and there is already a value present in the tx_mmforum_userfields_contents * table, overwrite this value now. */ } elseif ($this->isSetForUser($userId)) { $updateArray = array('tstamp' => $GLOBALS['EXEC_TIME'], 'field_value' => $value); $this->databaseHandle->exec_UPDATEquery('tx_mmforum_userfields_contents', 'user_id=' . intval($userId) . ' AND field_id=' . intval($this->getUID()) . ' AND deleted=0', $updateArray); /* If there is no value set for this user, then create a tx_mmforum_userfields_contents * record now. */ } else { $insertArray = array('pid' => $pid, 'tstamp' => $GLOBALS['EXEC_TIME'], 'crdate' => $GLOBALS['EXEC_TIME'], 'user_id' => $userId, 'field_id' => $this->getUID(), 'field_value' => $value); $this->databaseHandle->exec_INSERTquery('tx_mmforum_userfields_contents', $insertArray); } }
/** * Update be_groups with tx_mooxnews_categorymounts set * * @param string $table * @param array $oldNewCategoryUidMapping */ protected function updateCategoryPermissionFields($table, array $oldNewCategoryUidMapping) { $updatedRecords = 0; $rows = $this->databaseConnection->exec_SELECTgetRows('uid, category_perms, tx_mooxnews_categorymounts', $table, "tx_mooxnews_categorymounts != ''"); foreach ($rows as $row) { $oldUids = GeneralUtility::trimExplode(',', $row['tx_mooxnews_categorymounts']); $newUids = $row['category_perms'] ? GeneralUtility::trimExplode(',', $row['category_perms']) : array(); foreach ($oldUids as $oldUid) { if (!empty($oldNewCategoryUidMapping[$oldUid])) { $newUids[] = $oldNewCategoryUidMapping[$oldUid]; } } $newCategoryPerms = implode(',', array_unique($newUids)); if ($newCategoryPerms !== $row['category_perms']) { $this->databaseConnection->exec_UPDATEquery($table, 'uid=' . $row['uid'], array('category_perms' => $newCategoryPerms)); $updatedRecords++; } } $message = 'Updated ' . $updatedRecords . ' "' . $table . '" records'; $status = FlashMessage::INFO; $title = ''; $this->messageArray[] = array($status, $title, $message); }
/** * Perform update * * @param array &$dbQueries Queries done in this update * @param mixed &$customMessages Custom messages * @return boolean Whether the updated was made or not */ public function performUpdate(array &$dbQueries, &$customMessages) { $rows = $this->db->exec_SELECTgetRows('uid,pi_flexform', $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'], 'CType = ' . $this->db->fullQuoteStr('media', $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']) . ' AND pi_flexform LIKE ' . $this->db->fullQuoteStr('%<sheet index="sDEF">%', $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'])); /** @var $flexformTools \TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools */ $flexformTools = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\FlexForm\\FlexFormTools'); foreach ($rows as $row) { $flexFormXML = $row['pi_flexform']; $data = \TYPO3\CMS\Core\Utility\GeneralUtility::xml2array($flexFormXML); $sDEF = $data['data']['sDEF']['lDEF']; unset($data['data']['sDEF']); $type = $sDEF['mmType']['vDEF']; $data['data']['sGeneral'] = array('lDEF' => array('mmType' => array('vDEF' => $type))); $width = $sDEF['mmWidth']['vDEF']; if ($width) { $data['data']['sGeneral']['lDEF']['mmWidth'] = array('vDEF' => (int) $width); } $height = $sDEF['mmHeight']['vDEF']; if ($height) { $data['data']['sGeneral']['lDEF']['mmHeight'] = array('vDEF' => (int) $height); } switch ($type) { case 'video': $data['data']['sVideo'] = array('lDEF' => array('mmFile' => array('vDEF' => $sDEF['mmFile']['vDEF']))); break; case 'audio': $data['data']['sAudio'] = array('lDEF' => array('mmAudioFallback' => array('vDEF' => $sDEF['mmFile']['vDEF']))); break; default: continue; } $newXML = $flexformTools->flexArray2Xml($data, TRUE); $newXML = str_replace('encoding=""', 'encoding="utf-8"', $newXML); $this->db->exec_UPDATEquery($GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'], 'uid = ' . $row['uid'], array('pi_flexform' => $newXML)); } return TRUE; }