Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataHandlerHook method findFileByFileReference throw exception if a file reference is marked as hidden #211

Open
mediaessenz opened this issue Jul 10, 2020 · 0 comments

Comments

@mediaessenz
Copy link

mediaessenz commented Jul 10, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant