-
Notifications
You must be signed in to change notification settings - Fork 25
Description
To reproduce:
Add a content element containing a image and add two images, save, set one image to hidden, save again, set second image to hidden and save -> the exception "There is something broken with the File References. Consider updating the Reference Index." will be thrown.
Cause:
The reference(s) are not found, because of there hidden states, which constraint is not removed inside the Fab\Vidi\Service\DataService::getRecord method.
Possible Solution:
Add a third parameter "withHidden = false" to the Fab\Vidi\Service\DataService::getRecord method, and add a remove to this restriction if set:
/**
* @param string $tableName
* @param array $demand
* @param bool $withHidden
* @return array
*/
public function getRecord(string $tableName, array $demand = [], $withHidden = false): array
{
/** @var QueryBuilder $queryBuilder */
$queryBuilder = $this->getQueryBuilder($tableName);
if ($withHidden) {
$queryBuilder->getRestrictions()->removeByType(HiddenRestriction::class);
}
$queryBuilder
->select('*')
->from($tableName);
$this->addDemandConstraints($demand, $queryBuilder);
$record = $queryBuilder->execute()->fetch();
return is_array($record)
? $record
: [];
}Additional add true as third parameter to the call inside the findFileByFileReference method:
/**
* Retrieve the File identifier.
*
* @param $fileReferenceIdentifier
* @return int
* @throws \Exception
*/
protected function findFileByFileReference($fileReferenceIdentifier)
{
$record = $this->getDataService()->getRecord(
'sys_file_reference',
[
'uid' => $fileReferenceIdentifier
],
true
);
if (empty($record)) {
throw new \Exception('There is something broken with the File References. Consider updating the Reference Index.', 1408619796);
}
$fileIdentifier = $record['uid_local'];
return $fileIdentifier;
}Maybe also other places using getRecord should set the third parameter to true, but I can't assess it. In the end its also good to remove the hidden restriction in all cases, because EXT:media operates only in the backend.
[EDIT]
I just realized that the getRecord method is part of EXT:vidi and not EXT:media, which is also used by EXT:vidi_frontend. So removing the hidden restriction at all is maybe not the best solution.