Skip to content

Commit

Permalink
[TASK] Remove sys_file.deleted flag and it's usage
Browse files Browse the repository at this point in the history
This also fixes the 'Uncaught TYPO3 Exception #1317178604
No file found for given UID.' that appears when some sys_file
entries have a deleted flag set by mistake.

Resolves: #51562
Releases: 6.2, 6.1, 6.0
Change-Id: Id23636d2732f3562b8a155025656b26041c9a4e2
Reviewed-on: https://review.typo3.org/23567
Reviewed-by: Frans Saris
Tested-by: Frans Saris
Reviewed-by: Wouter Wolters
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
  • Loading branch information
baschny authored and neufeind committed Sep 11, 2013
1 parent 92e5e6c commit fcc250f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 27 deletions.
26 changes: 23 additions & 3 deletions typo3/sysext/core/Classes/Resource/AbstractRepository.php
Expand Up @@ -133,10 +133,11 @@ public function getRemovedObjects() {
*/
public function findAll() {
$itemList = array();
$whereClause = 'deleted = 0';
$whereClause = '1=1';
if ($this->type != '') {
$whereClause .= ' AND ' . $this->typeField . ' = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($this->type, $this->table);
$whereClause .= ' AND ' . $this->typeField . ' = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($this->type, $this->table) . ' ';
}
$whereClause .= $this->getWhereClauseForEnabledFields();
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->table, $whereClause);
while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$itemList[] = $this->createDomainObject($row);
Expand Down Expand Up @@ -189,13 +190,32 @@ public function findByUid($uid) {
if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($uid)) {
throw new \InvalidArgumentException('uid has to be integer.', 1316779798);
}
$row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', $this->table, 'uid=' . intval($uid) . ' AND deleted=0');
$row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', $this->table, 'uid=' . intval($uid) . $this->getWhereClauseForEnabledFields());
if (empty($row) || !is_array($row)) {
throw new \RuntimeException('Could not find row with uid "' . $uid . '" in table ' . $this->table, 1314354065);
}
return $this->createDomainObject($row);
}

/**
* get the WHERE clause for the enabled fields of this TCA table
* depending on the context
*
* @return string the additional where clause, something like " AND deleted=0 AND hidden=0"
*/
protected function getWhereClauseForEnabledFields() {
if ($this->getEnvironmentMode() === 'FE') {
// frontend context
$whereClause = $GLOBALS['TSFE']->sys_page->enableFields($this->table);
$whereClause .= $GLOBALS['TSFE']->sys_page->deleteClause($this->table);
} else {
// backend context
$whereClause = \TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields($this->table);
$whereClause .= \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($this->table);
}
return $whereClause;
}

/**
* Sets the property names to order the result by per default.
* Expected like this:
Expand Down
2 changes: 1 addition & 1 deletion typo3/sysext/core/Classes/Resource/ResourceFactory.php
Expand Up @@ -338,7 +338,7 @@ public function getFileObject($uid, array $fileData = array()) {
// Fetches data in case $fileData is empty
if (empty($fileData)) {
/** @var $GLOBALS['TYPO3_DB'] \TYPO3\CMS\Core\Database\DatabaseConnection */
$fileData = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', 'sys_file', 'uid=' . intval($uid) . ' AND deleted=0');
$fileData = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', 'sys_file', 'uid=' . intval($uid));
if (!is_array($fileData)) {
throw new \TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException('No file found for given UID.', 1317178604);
}
Expand Down
2 changes: 0 additions & 2 deletions typo3/sysext/core/Classes/Resource/Service/IndexerService.php
Expand Up @@ -97,7 +97,6 @@ public function indexFile(\TYPO3\CMS\Core\Resource\File $fileObject, $updateObje
// If the file is already indexed, then the file information will
// be updated on the existing record
if ($fileObject->isIndexed()) {
$fileInfo['deleted'] = 0;
$fileInfo['missing'] = 0;
$GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_file', sprintf('uid = %d', $fileObject->getUid()), $fileInfo);
} else {
Expand All @@ -110,7 +109,6 @@ public function indexFile(\TYPO3\CMS\Core\Resource\File $fileObject, $updateObje
if (!$otherFile->exists()) {
// @todo: create a log entry
$movedFile = TRUE;
$fileInfo['deleted'] = 0;
$fileInfo['missing'] = 0;
$otherFile->updateProperties($fileInfo);
$this->getRepository()->update($otherFile);
Expand Down
19 changes: 0 additions & 19 deletions typo3/sysext/core/Classes/Resource/StorageRepository.php
Expand Up @@ -199,25 +199,6 @@ protected function createDomainObject(array $databaseRow) {
return $this->factory->getStorageObject($databaseRow['uid'], $databaseRow);
}

/**
* get the WHERE clause for the enabled fields of this TCA table
* depending on the context
*
* @return string the additional where clause, something like " AND deleted=0 AND hidden=0"
*/
protected function getWhereClauseForEnabledFields() {
if ($this->getEnvironmentMode() === 'FE') {
// frontend context
$whereClause = $GLOBALS['TSFE']->sys_page->enableFields($this->table);
$whereClause .= $GLOBALS['TSFE']->sys_page->deleteClause($this->table);
} else {
// backend context
$whereClause = \TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields($this->table);
$whereClause .= \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($this->table);
}
return $whereClause;
}

/**
* Function to return the current TYPO3_MODE.
* This function can be mocked in unit tests to be able to test frontend behaviour.
Expand Down
1 change: 0 additions & 1 deletion typo3/sysext/core/Configuration/TCA/sys_file.php
Expand Up @@ -12,7 +12,6 @@
'versioningWS' => TRUE,
'origUid' => 't3_origuid',
'default_sortby' => 'ORDER BY crdate DESC',
'delete' => 'deleted',
'dividers2tabs' => TRUE,
'typeicon_column' => 'type',
'typeicon_classes' => array(
Expand Down
1 change: 0 additions & 1 deletion typo3/sysext/core/ext_tables.sql
Expand Up @@ -284,7 +284,6 @@ CREATE TABLE sys_file (
tstamp int(11) DEFAULT '0' NOT NULL,
crdate int(11) DEFAULT '0' NOT NULL,
cruser_id int(11) DEFAULT '0' NOT NULL,
deleted tinyint(4) DEFAULT '0' NOT NULL,
missing tinyint(4) DEFAULT '0' NOT NULL,

# Versioning fields
Expand Down

0 comments on commit fcc250f

Please sign in to comment.