BUGFIX Limiting all SQL queries going through Translatable->augmentSQL() to the Locale of the current object (if set), otherwise falling back to default locale. This fixes lots of problems with the Versioned extension in combination with Translatable, for example showing and comparing versions in the CMS sidebar (see #3886)

BUGFIX Removing the appended querying for NULL or empty Locale values in Translatable->augmentSQL() - this should no longer be necessary as we set default locales to all records through Translatable->requireDefaultRecords()

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@75826 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2009-05-01 03:18:40 +00:00
parent fdeacb4d07
commit 4965352bc3

View File

@ -451,11 +451,14 @@ class Translatable extends DataObjectDecorator {
* Use {@link $enable_lang_filter} to temporarily disable this "auto-filtering".
*/
function augmentSQL(SQLQuery &$query) {
$lang = Translatable::current_locale();
// If the record is saved (and not a singleton), and has a locale,
// limit the current call to its locale. This fixes a lot of problems
// with other extensions like Versioned
$locale = ($this->owner->ID && $this->owner->Locale) ? $this->owner->Locale : Translatable::current_locale();
$baseTable = ClassInfo::baseDataClass($this->owner->class);
$where = $query->where;
if(
$lang
$locale
// unless the filter has been temporarily disabled
&& self::$enable_lang_filter
// DataObject::get_by_id() should work independently of language
@ -467,11 +470,7 @@ class Translatable extends DataObjectDecorator {
&& !preg_match('/("|\'|`)Locale("|\'|`)/', $query->getFilter())
//&& !$query->filtersOnFK()
) {
$qry = "\"Locale\" = '$lang'";
if(self::$default_locale == self::current_locale()) {
$qry .= " OR \"Locale\" = '' ";
$qry .= " OR \"Locale\" IS NULL ";
}
$qry = sprintf('"%s"."Locale" = \'%s\'', $baseTable, $locale);
$query->where[] = $qry;
}
}