本文整理汇总了PHP中TYPO3\CMS\Core\Database\DatabaseConnection::exec_DELETEquery方法的典型用法代码示例。如果您正苦于以下问题:PHP DatabaseConnection::exec_DELETEquery方法的具体用法?PHP DatabaseConnection::exec_DELETEquery怎么用?PHP DatabaseConnection::exec_DELETEquery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TYPO3\CMS\Core\Database\DatabaseConnection
的用法示例。
在下文中一共展示了DatabaseConnection::exec_DELETEquery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: removeRow
/**
* Deletes a row in the storage
*
* @param string $tableName The database table name
* @param array $where An array of where array('fieldname' => value).
* @param bool $isRelation TRUE if we are currently manipulating a relation table, FALSE by default
* @return bool
*/
public function removeRow($tableName, array $where, $isRelation = FALSE)
{
$deleteSuccessful = $this->databaseHandle->exec_DELETEquery($tableName, $this->resolveWhereStatement($where, $tableName));
$this->checkSqlErrors();
if (!$isRelation && isset($where['uid'])) {
$this->clearPageCache($tableName, $where['uid']);
}
return $deleteSuccessful;
}
示例2: array
/**
* Indexes a specific post.
* @param array $conf The calling plugin's configuration vars. Not actually used.
* @param $post_array
* @internal param int $post_id The UID of the post to be indexed.
* @return void
*/
function ind_post($conf, $post_array)
{
// Delete old records in the index table regarding this post.
$this->databaseHandle->exec_DELETEquery('tx_mmforum_wordmatch', "post_id='" . $post_array['uid'] . "'");
// If post is deleted, do not index again...
if ($post_array['deleted'] == 0) {
// Get post content
$content = $this->get_posttext($post_array['uid']);
// Retrieve all words in the post content as array
$wordArray = $this->wordArray($conf, $content);
// Load topic information
$topic_array = $this->topic_information($post_array['topic_id']);
$res = $this->databaseHandle->exec_SELECTquery('f.grouprights_read as f_read, c.grouprights_read as c_read', 'tx_mmforum_forums f, tx_mmforum_forums c', 'f.uid="' . $topic_array['forum_id'] . '" AND c.uid = f.parentID');
$arr = $this->databaseHandle->sql_fetch_assoc($res);
$f_groups = GeneralUtility::intExplode(',', $arr['f_read']);
$c_groups = GeneralUtility::intExplode(',', $arr['c_read']);
#$groups = array_merge($f_groups,$c_groups);
$rFGroups = array();
foreach ($f_groups as $group) {
if ($group > 0) {
$rFGroups[] = $group;
}
}
$sFGroups = implode(',', $rFGroups);
$rCGroups = array();
foreach ($c_groups as $group) {
if ($group > 0) {
$rCGroups[] = $group;
}
}
$sCGroups = implode(',', $rCGroups);
// Compose data for word matches
$matchparams['post_id'] = $post_array['uid'];
$matchparams['topic_id'] = $post_array['topic_id'];
$matchparams['forum_id'] = $topic_array['forum_id'];
$matchparams['solved'] = $topic_array['solved'];
$matchparams['topic_title'] = $topic_array['topic_title'];
$matchparams['topic_views'] = $topic_array['topic_views'];
$matchparams['topic_replies'] = $topic_array['topic_replies'];
$matchparams['post_crdate'] = $post_array['crdate'];
$matchparams['post_cruser'] = $post_array['cruser_id'];
$matchparams['reqUserGroups_f'] = $sFGroups;
$matchparams['reqUserGroups_c'] = $sCGroups;
// Insert words and word matches into data base. Very time consuming.
foreach ($wordArray as $value) {
$word_id = $this->wordAdd($value);
// Insert word into database and get UID
$this->wortMatchAdd($word_id, $matchparams, true);
// Write word match into database
}
}
$this->write_post_ind_date($post_array['uid']);
// Update post indexing date
}
示例3: deleteRecords
/**
* if an image was removed from the select box, this method deletes the relating
* image record from the DB
*/
private function deleteRecords()
{
$fileNames = explode(',', $this->collection['images']);
// remove imagerecords which are not used anymore
foreach ($this->images as $filename => $image) {
if (array_search($filename, $fileNames) === false) {
$this->db->exec_DELETEquery('tx_gorillary_images', "image='{$filename}' AND collection='" . $this->collection['uid'] . "'");
//unset ($this->images[$filename]);
}
}
}
示例4: getUser
/**
* getUser
*
* @param array $user
* @param \Hybrid_User_Profile $socialUser
* @param \Portrino\PxHybridAuth\Service\SocialLoginAuthenticationService $pObj
*
* @throws \Exception
*/
public function getUser(&$user, $socialUser, $pObj)
{
$this->extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['px_hybrid_auth']);
$this->database = $this->getDatabaseConnection();
if (!isset($this->extConf['auto_fe_user_creation.']['storagePid'])) {
throw new \Exception('[px_hybrid_auth]: No storagePid for new fe_user records given! Please configure it in the extension configuration', 1445939601);
}
if (!$user) {
$autoCreatedUser = $this->createFrontendUserRecordFromSocialUser($socialUser, intval($this->extConf['auto_fe_user_creation.']['storagePid']));
if ($autoCreatedUser) {
$identity = $this->addIdentityToFrontendUser($autoCreatedUser, $pObj->getServiceProvider(), $socialUser->identifier);
if ($identity) {
// overwrite the user with call by reference
$user = $autoCreatedUser;
} else {
// delete the auto created user
$this->database->exec_DELETEquery('fe_users', 'uid=' . intval($autoCreatedUser['uid']));
}
}
}
}
示例5: dbDelete
/**
* Db delete object
*
* @param int $uid Uid
* @param Tx_Commerce_Dao_BasicDaoObject $object Object
*
* @return void
*/
protected function dbDelete($uid, Tx_Commerce_Dao_BasicDaoObject &$object)
{
$dbWhere = 'uid = ' . (int) $uid;
// execute query
$this->database->exec_DELETEquery($this->dbTable, $dbWhere);
// any errors
$error = $this->database->sql_error();
if (!empty($error)) {
$this->addError(array($error, $this->database->DELETEquery($this->dbTable, $dbWhere)));
}
// remove object itself
$object->destroy();
}
示例6: intval
/**
*
* Deletes a single posts.
* This method deletes a single post and all associated objects (alerts, ratings,
* search index entries etc.).
*
* @author Martin Helmich <m.helmich@mittwald.de>
* @version 2009-12-20
* @param int $postId The UID of the post that is to be deleted.
* @param boolean $noUpdate Set to TRUE, in order to suspend updating of
* internal counters.
* @return void
*/
function delete_post($postId, $noUpdate = false)
{
$arr = $this->databaseHandle->sql_fetch_assoc($this->databaseHandle->exec_SELECTquery('*', 'tx_mmforum_posts', 'uid=' . intval($postId)));
$uA = array('deleted' => 1, 'tstamp' => $GLOBALS['EXEC_TIME']);
$this->databaseHandle->exec_UPDATEquery('tx_mmforum_posts', $uA, 'uid=' . intval($postId));
$this->databaseHandle->exec_UPDATEquery('tx_mmforum_posts_text', $uA, 'post_id=' . intval($postId));
$this->databaseHandle->exec_UPDATEquery('tx_mmforum_post_alert', $uA, 'post_id=' . intval($postId));
$this->databaseHandle->exec_UPDATEquery('tx_mmforum_attachments', $uA, 'post_id=' . intval($postId));
$this->databaseHandle->exec_DELETEquery('tx_mmforum_wordmatch', 'post_id=' . intval($postId) . '');
if (ExtensionManagementUtility::isLoaded('ratings')) {
$this->databaseHandle->exec_DELETEquery('tx_ratings_data', $uA, 'reference="tx_mmforum_posts_' . intval($postId) . '"');
}
if (!$noUpdate) {
$this->updateTopicPostCount($arr['topic_id']);
$this->updateForumPostCount($arr['forum_id']);
$this->updateUserPostCount($arr['poster_id']);
} else {
$this->updateQueue_addTopic($arr['topic_id']);
$this->updateQueue_addForum($arr['forum_id']);
$this->updateQueue_addUser($arr['poster_id']);
}
}
示例7: insertDB
/**
* Insert into database
* Does not check permissions but expects them to be verified on beforehand
*
* @param string $table Record table name
* @param string $id "NEW...." uid string
* @param array $fieldArray Array of field=>value pairs to insert. FIELDS MUST MATCH the database FIELDS. No check is done. "pid" must point to the destination of the record!
* @param bool $newVersion Set to TRUE if new version is created.
* @param int $suggestedUid Suggested UID value for the inserted record. See the array $this->suggestedInsertUids; Admin-only feature
* @param bool $dontSetNewIdIndex If TRUE, the ->substNEWwithIDs array is not updated. Only useful in very rare circumstances!
* @return int|NULL Returns ID on success.
*/
public function insertDB($table, $id, $fieldArray, $newVersion = false, $suggestedUid = 0, $dontSetNewIdIndex = false)
{
if (is_array($fieldArray) && is_array($GLOBALS['TCA'][$table]) && isset($fieldArray['pid'])) {
// Do NOT insert the UID field, ever!
unset($fieldArray['uid']);
if (!empty($fieldArray)) {
// Check for "suggestedUid".
// This feature is used by the import functionality to force a new record to have a certain UID value.
// This is only recommended for use when the destination server is a passive mirror of another server.
// As a security measure this feature is available only for Admin Users (for now)
$suggestedUid = (int) $suggestedUid;
if ($this->BE_USER->isAdmin() && $suggestedUid && $this->suggestedInsertUids[$table . ':' . $suggestedUid]) {
// When the value of ->suggestedInsertUids[...] is "DELETE" it will try to remove the previous record
if ($this->suggestedInsertUids[$table . ':' . $suggestedUid] === 'DELETE') {
// DELETE:
$this->databaseConnection->exec_DELETEquery($table, 'uid=' . (int) $suggestedUid);
}
$fieldArray['uid'] = $suggestedUid;
}
$fieldArray = $this->insertUpdateDB_preprocessBasedOnFieldType($table, $fieldArray);
// Execute the INSERT query:
$this->databaseConnection->exec_INSERTquery($table, $fieldArray);
// If succees, do...:
if (!$this->databaseConnection->sql_error()) {
// Set mapping for NEW... -> real uid:
// the NEW_id now holds the 'NEW....' -id
$NEW_id = $id;
$id = $this->databaseConnection->sql_insert_id();
if (!$dontSetNewIdIndex) {
$this->substNEWwithIDs[$NEW_id] = $id;
$this->substNEWwithIDs_table[$NEW_id] = $table;
}
$newRow = array();
// Checking the record is properly saved and writing to log
if ($this->enableLogging && $this->checkStoredRecords) {
$newRow = $this->checkStoredRecord($table, $id, $fieldArray, 1);
}
// Update reference index:
$this->updateRefIndex($table, $id);
if ($newVersion) {
if ($this->enableLogging) {
$propArr = $this->getRecordPropertiesFromRow($table, $newRow);
$this->log($table, $id, 1, 0, 0, 'New version created of table \'%s\', uid \'%s\'. UID of new version is \'%s\'', 10, array($table, $fieldArray['t3ver_oid'], $id), $propArr['event_pid'], $NEW_id);
}
} else {
if ($this->enableLogging) {
$propArr = $this->getRecordPropertiesFromRow($table, $newRow);
$page_propArr = $this->getRecordProperties('pages', $propArr['pid']);
$this->log($table, $id, 1, 0, 0, 'Record \'%s\' (%s) was inserted on page \'%s\' (%s)', 10, array($propArr['header'], $table . ':' . $id, $page_propArr['header'], $newRow['pid']), $newRow['pid'], $NEW_id);
}
// Clear cache for relevant pages:
$this->registerRecordIdForPageCacheClearing($table, $id);
}
return $id;
} elseif ($this->enableLogging) {
$this->log($table, $id, 1, 0, 2, 'SQL error: \'%s\' (%s)', 12, array($this->databaseConnection->sql_error(), $table . ':' . $id));
}
}
}
return null;
}
示例8: cleanupNonces
/**
* Removes old nonces
*
* @return void
*/
public function cleanupNonces()
{
$where = sprintf('crdate<%d', time() - self::NONCE_STORAGE_TIME);
$this->databaseConnection->exec_DELETEquery(self::NONCE_TABLE_NAME, $where);
}
示例9: clearUrlCacheForPage
/**
* Empties the URL cache for one page.
*
* @param int $pageId
* @return void
*/
public function clearUrlCacheForPage($pageId)
{
$this->databaseConnection->sql_query('DELETE FROM tx_realurl_uniqalias_cache_map WHERE url_cache_id IN (SELECT cache_id FROM tx_realurl_urlcache WHERE page_id=' . (int) $pageId . ')');
$this->databaseConnection->exec_DELETEquery('tx_realurl_urlcache', 'page_id=' . (int) $pageId);
}
示例10: CLI_deleteProcessesMarkedDeleted
/**
* Delete processes marked as deleted
*
* @return void
*/
public function CLI_deleteProcessesMarkedDeleted()
{
$this->db->exec_DELETEquery('tx_crawler_process', 'deleted = 1');
}
示例11: edit
/**
* Displays a list of a user's email subscriptions.
* Performs also actions like editing or deleting subscriptions.
* @param \tx_mmforum_base $forumObj
* @return string
*/
static function edit(\tx_mmforum_base $forumObj)
{
$content = '';
$feUserId = intval($GLOBALS['TSFE']->fe_user->user['uid']);
// can be
// "topic" - only topic subscriptions
// "forum" - only forum subscriptions
// "all" - both of them (default)
$displayMode = 'all';
if ($forumObj->conf['havealook.']['displayOnlyTopics']) {
$displayMode = 'topic';
}
if (isset($forumObj->piVars['displayMode'])) {
$displayMode = $forumObj->piVars['displayMode'];
}
if ($feUserId) {
// Delete a single subscription (through the link at every subscription)
if ($forumObj->piVars['deltid']) {
$deleleTopicId = intval($forumObj->piVars['deltid']);
if ($forumObj->piVars['delmode'] == 'topic') {
$this->databaseHandle->exec_DELETEquery('tx_mmforum_topicmail', 'user_id = ' . $feUserId . ' AND topic_id = ' . $deleleTopicId . $forumObj->getStoragePIDQuery());
} else {
$this->databaseHandle->exec_DELETEquery('tx_mmforum_forummail', 'user_id = ' . $feUserId . ' AND forum_id = ' . $deleleTopicId . $forumObj->getStoragePIDQuery());
}
unset($forumObj->piVars['deltid']);
}
// Delete several subscriptions (through the checkboxes)
if ($forumObj->piVars['havealook_action'] == 'delete') {
foreach ((array) $forumObj->piVars['fav_delete']['topic'] as $deleleTopicId) {
$this->databaseHandle->exec_DELETEquery('tx_mmforum_topicmail', 'user_id = ' . $feUserId . ' AND topic_id = ' . intval($deleleTopicId) . $forumObj->getStoragePIDQuery());
}
foreach ((array) $forumObj->piVars['fav_delete']['forum'] as $deleleTopicId) {
$this->databaseHandle->exec_DELETEquery('tx_mmforum_forummail', 'user_id = ' . $feUserId . ' AND forum_id = ' . intval($deleleTopicId) . $forumObj->getStoragePIDQuery());
}
unset($forumObj->piVars['havealook_action']);
}
// Determination of sorting mode
$orderBy = $forumObj->piVars['order'] ? $forumObj->piVars['order'] : 'added';
// rendering the settings
$templateFile = $forumObj->cObj->fileResource($forumObj->conf['template.']['havealook']);
$template = $forumObj->cObj->getSubpart($templateFile, '###HAVEALOOK_SETTINGS###');
$marker = array('###ACTION###' => $forumObj->escapeURL($forumObj->pi_linkTP_keepPIvars_url()), '###ORDER_LPDATE###' => $orderBy == 'lpdate' ? 'selected="selected"' : '', '###ORDER_CAT###' => $orderBy == 'cat' ? 'selected="selected"' : '', '###ORDER_ADDED###' => $orderBy == 'added' ? 'selected="selected"' : '', '###ORDER_ALPHAB###' => $orderBy == 'alphab' ? 'selected="selected"' : '', '###LABEL_ORDERBY###' => $forumObj->pi_getLL('favorites.orderBy'), '###LABEL_ORDER_LPDATE###' => $forumObj->pi_getLL('favorites.orderBy.lpdate'), '###LABEL_ORDER_CAT###' => $forumObj->pi_getLL('favorites.orderBy.cat'), '###LABEL_ORDER_ADDED###' => $forumObj->pi_getLL('favorites.orderBy.added'), '###LABEL_ORDER_ALPHAB###' => $forumObj->pi_getLL('favorites.orderBy.alphab'));
// Include hook to modify the output of the settings
if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['mm_forum']['havealook']['listsettings'])) {
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['mm_forum']['havealook']['listsettings'] as $_classRef) {
$_procObj =& GeneralUtility::getUserObj($_classRef);
$marker = $_procObj->havealook_listsettings($marker, $forumObj);
}
}
$content = $forumObj->cObj->substituteMarkerArray($template, $marker);
// rendering the head part
$template = $forumObj->cObj->getSubpart($templateFile, '###HAVEALOOK_BEGIN###');
$marker = array('###ACTION###' => $forumObj->escapeURL($forumObj->pi_linkTP_keepPIvars_url()), '###LABEL_HAVEALOOK###' => $forumObj->pi_getLL('havealook.title'), '###LABEL_OPTIONS###' => $forumObj->pi_getLL('favorites.options'), '###LABEL_TOPICNAME###' => $forumObj->pi_getLL('topic.title'), '###LABEL_CONFIRMMULTIPLE###' => $forumObj->pi_getLL('havealook.confirmMultiple'));
$content .= $forumObj->cObj->substituteMarkerArray($template, $marker);
switch ($orderBy) {
case 'lpdate':
$order = 'item_lastpost_uid DESC';
break;
case 'cat':
$order = 'cat_order ASC, forum_order ASC, item_lastpost_uid DESC';
break;
case 'added':
$order = 'mail_uid DESC';
break;
case 'alphab':
default:
$order = 'item_title ASC';
break;
}
$sqlTopic = 'SELECT' . ' t.topic_title AS item_title,' . ' t.uid AS item_uid,' . ' t.topic_last_post_id AS item_lastpost_uid,' . ' t.solved AS item_solved,' . ' t.topic_is AS item_prefix,' . ' m.uid AS mail_uid,' . ' f.forum_name AS forum_title,' . ' f.uid AS forum_uid,' . ' f.forum_last_post_id AS forum_lastpost_id,' . ' f.sorting AS forum_order,' . ' c.forum_name AS cat_title,' . ' c.uid AS cat_uid,' . ' c.sorting AS cat_order,' . ' "topic" AS notify_mode ' . 'FROM' . ' tx_mmforum_topicmail m' . ' LEFT JOIN tx_mmforum_topics t ON m.topic_id = t.uid ' . ' LEFT JOIN tx_mmforum_forums f ON t.forum_id = f.uid ' . ' LEFT JOIN tx_mmforum_forums c ON f.parentID = c.uid ' . 'WHERE' . ' m.user_id = ' . $feUserId . ' AND ' . ' m.deleted = 0 AND' . ' t.deleted = 0 AND' . ' f.deleted = 0 AND' . ' c.deleted = 0 ' . $forumObj->getMayRead_forum_query('f') . $forumObj->getMayRead_forum_query('c');
$sqlForum = 'SELECT' . ' f.forum_name AS item_title,' . ' f.uid AS item_uid,' . ' f.forum_last_post_id AS item_lastpost_uid,' . ' 0 AS item_solved,' . ' "" AS item_prefix,' . ' m.uid AS mail_uid,' . ' f.forum_name AS forum_title,' . ' f.uid AS forum_uid,' . ' f.forum_last_post_id AS forum_lastpost_uid,' . ' f.sorting AS forum_order,' . ' c.forum_name AS cat_title,' . ' c.uid AS cat_uid,' . ' c.sorting AS cat_order,' . ' "forum" AS notify_mode ' . 'FROM' . ' tx_mmforum_forummail m' . ' LEFT JOIN tx_mmforum_forums f ON m.forum_id = f.uid ' . ' LEFT JOIN tx_mmforum_forums c ON (f.parentID = c.uid OR (f.parentID = 0 AND f.uid = c.uid)) ' . 'WHERE' . ' m.user_id = ' . $feUserId . ' AND ' . ' m.deleted = 0 AND ' . ' f.deleted = 0 AND ' . ' c.deleted = 0 ' . $forumObj->getMayRead_forum_query('f') . $forumObj->getMayRead_forum_query('c');
if ($displayMode == 'topic') {
$sql = $sqlTopic;
} else {
if ($displayMode == 'forum') {
$sql = $sqlForum;
} else {
$sql = '(' . $sqlTopic . ') UNION (' . $sqlForum . ')';
}
}
$sql .= 'ORDER BY ' . $order;
$res = $this->databaseHandle->sql_query($sql);
if ($this->databaseHandle->sql_num_rows($res) == 0) {
$template = $forumObj->cObj->getSubpart($templateFile, '###LIST_HAVEALOOK_EMPTY###');
$content .= $forumObj->cObj->substituteMarker($template, '###LLL_HAVEALOOK_EMPTY###', $forumObj->pi_getLL('havealook.empty'));
} else {
$template = $forumObj->cObj->getSubpart($templateFile, '###LIST_HAVEALOOK###');
// go through every found subscription
while ($row = $this->databaseHandle->sql_fetch_assoc($res)) {
if ($row['notify_mode'] == 'topic') {
$linkParams[$forumObj->prefixId] = array('action' => 'list_post', 'tid' => $row['item_uid']);
$marker['###TOPICICON###'] = $forumObj->getTopicIcon($row['item_uid']);
} else {
$linkParams[$forumObj->prefixId] = array('action' => 'list_prefix', 'fid' => $row['item_uid']);
//.........这里部分代码省略.........
示例12: removeProcessFromProcesslist
/**
* Remove a process from processlist
*
* @param string $processId Unique process Id.
*
* @return void
*/
private function removeProcessFromProcesslist($processId)
{
$this->db->exec_DELETEquery('tx_crawler_process', 'process_id = ' . $this->db->fullQuoteStr($processId, 'tx_crawler_process'));
}
示例13: removeUrlDataEntriesWithIgnoredParameters
/**
* Removes entries with parameters that should be ignored.
*/
protected function removeUrlDataEntriesWithIgnoredParameters()
{
$this->databaseConnection->exec_DELETEquery('tx_realurl_urlcache', 'original_url RLIKE \'(^|&)(utm_[a-z]+|pk_campaign|pk_kwd)=\'');
}
示例14: removeCacheValue
/**
* Removes a cache variable.
*
* @author Martin Helmich <m.helmich@mittwald.de>
* @version 2008-06-22
* @param string $key The key of the cache variable.
* @return boolean TRUE on success, otherwise FALSE
*/
function removeCacheValue($key)
{
$res = $this->databaseHandle->exec_DELETEquery('tx_mmforum_cache', 'cache_key=' . $this->databaseHandle->fullQuoteStr($key, 'tx_mmforum_cache'));
return $res ? true : false;
}
示例15: purge
public function purge($simulate)
{
$this->output->info('Purge deleted');
$this->purgeDeleted('sys_file_reference', $simulate);
$this->db->exec_DELETEquery('sys_file_reference', 'tablenames = \'\' OR fieldname = \'\'');
$delete = new PreparedStatement('DELETE FROM sys_file_reference WHERE uid = ?', 'sys_file_reference');
$this->output->info('Purge references pointing to deleted records');
$res = $this->db->exec_SELECTquery('*', 'sys_file_reference', '');
$pageTools = new PageRepository();
$pageTools->init(FALSE);
while ($row = $this->db->sql_fetch_assoc($res)) {
$cnt = $this->db->exec_SELECTcountRows('uid', $row['tablenames'], 'uid = ' . $row['uid_foreign'] . $pageTools->enableFields($row['tablenames']));
if (!$cnt) {
if ($simulate) {
$this->output->info('Would delete reference ' . $row['uid']);
} else {
$delete->execute(array($row['uid']));
$this->output->info('Deleted reference ' . $row['uid']);
}
}
}
$delete->free();
$this->output->info('Purge sys_file records with no references');
$delete = new PreparedStatement('DELETE FROM sys_file WHERE uid = ?', 'sys_file');
$res = $this->db->exec_SELECTquery('uid', 'sys_file', 'uid NOT IN (select uid_local from sys_file_reference group by uid_local)');
while ($row = $this->db->sql_fetch_assoc($res)) {
if ($simulate) {
$this->output->info('Would delete file record %s', array($row['uid']));
} else {
$delete->execute(array($row['uid']));
$this->output->info('Deleted file record <b>%s</b>', array($row['uid']));
}
}
$this->output->info('Purge actual files with no record');
$prefixRegex = '/^' . preg_quote(PATH_site, '/') . '(fileadmin|uploads)/';
$files = new \RegexIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(PATH_site, RecursiveDirectoryIterator::SKIP_DOTS | RecursiveDirectoryIterator::UNIX_PATHS), RecursiveIteratorIterator::LEAVES_ONLY | RecursiveIteratorIterator::CHILD_FIRST), $prefixRegex);
$exists = new PreparedStatement('SELECT uid FROM sys_file WHERE identifier = ?', 'sys_file');
$fileSize = 0;
foreach ($files as $file) {
$filename = (string) $file;
if (!is_file($filename)) {
continue;
}
$fileId = preg_replace($prefixRegex, '', $filename);
$exists->execute(array($fileId));
$result = $exists->fetchAll();
if (empty($result[0]['uid'])) {
$fileSize += filesize($filename);
if ($simulate) {
$this->output->info('<i>Would delete file %s</i>', array($filename));
} else {
unlink($filename);
$this->output->info('Delete file %s', array($filename));
}
}
}
$size = GeneralUtility::formatSize($fileSize);
if ($simulate) {
$this->output->info('Would delete %s of files', array($size));
$this->output->info('Would truncate table sys_file_processedfile');
} else {
$this->output->info('Deleted %s of files', array($size));
$this->db->exec_TRUNCATEquery('sys_file_processedfile');
$this->output->info('Truncated table sys_file_processedfile');
}
}