Skip to content

Commit

Permalink
Check the registry for table prefixed queries (see #1161).
Browse files Browse the repository at this point in the history
Description
-----------

-

Commits
-------

a3b6814 Merge branch 'hotfix/4.4.7'
5071bd2 Support checking the registry for table prefixed queries
0a9f49a Fixed FilesModel::findByUuid() did not check model registry
828a11b Cleanup
  • Loading branch information
Toflar authored and leofeyer committed Nov 9, 2017
1 parent 324720e commit 6309d04
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/Resources/contao/library/Contao/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -1054,14 +1054,20 @@ protected static function find(array $arrOptions)
{
$arrColumn = (array) $arrOptions['column'];

if (count($arrColumn) == 1 && ($arrColumn[0] == static::$strPk || in_array($arrColumn[0], static::getUniqueFields())))
if (count($arrColumn) == 1)
{
$varKey = is_array($arrOptions['value']) ? $arrOptions['value'][0] : $arrOptions['value'];
$objModel = \Model\Registry::getInstance()->fetch(static::$strTable, $varKey, $arrColumn[0]);
// Support table prefixes
$arrColumn[0] = preg_replace('/^' . preg_quote(static::getTable(), '/') . '\./', '', $arrColumn[0]);

if ($objModel !== null)
if ($arrColumn[0] == static::$strPk || in_array($arrColumn[0], static::getUniqueFields()))
{
return $objModel;
$varKey = is_array($arrOptions['value']) ? $arrOptions['value'][0] : $arrOptions['value'];
$objModel = \Model\Registry::getInstance()->fetch(static::$strTable, $varKey, $arrColumn[0]);

if ($objModel !== null)
{
return $objModel;
}
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/Resources/contao/models/FilesModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,17 @@ public static function findByUuid($strUuid, array $arrOptions=array())
$strUuid = \StringUtil::uuidToBin($strUuid);
}

if (empty($arrOptions))
{
// Check in model registry (does not work by default due to UNHEX())
$objModel = \Model\Registry::getInstance()->fetch(static::$strTable, $strUuid, 'uuid');

if ($objModel !== null)
{
return $objModel;
}
}

return static::findOneBy(array("$t.uuid=UNHEX(?)"), bin2hex($strUuid), $arrOptions);
}

Expand Down

0 comments on commit 6309d04

Please sign in to comment.