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

Support checking the registry for table prefixed queries #1161

Merged
merged 4 commits into from
Nov 9, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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] = $result = preg_replace('/^' . preg_quote(static::getTable(), '/') . '\./', '', $arrColumn[0]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the $result = part supposed to be there?


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
8 changes: 8 additions & 0 deletions src/Resources/contao/models/FilesModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ public static function findByUuid($strUuid, array $arrOptions=array())
$strUuid = \StringUtil::uuidToBin($strUuid);
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to

public static function findPublishedFallbackByHostname($strHost, array $arrOptions=array())
{
// Try to load from the registry (see #8544)
if (empty($arrOptions))
{
$objModel = \Model\Registry::getInstance()->fetch(static::$strTable, $strHost, 'contao.dns-fallback');
if ($objModel !== null)
{
return $objModel;
}
}
$t = static::$strTable;
$arrColumns = array("$t.dns=? AND $t.fallback='1'");
if (isset($arrOptions['ignoreFePreview']) || !BE_USER_LOGGED_IN)
{
$time = \Date::floorToMinute();
$arrColumns[] = "($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'" . ($time + 60) . "') AND $t.published='1'";
}
return static::findOneBy($arrColumns, $strHost, $arrOptions);
}
we should add a empty($arrOptions) check here, shouldn't we?


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

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

Expand Down