BUG Use new ORM methods (fixes #42)

This subtly changes the caching behaviour
where get_one() calls are replaced, results
will be no longer cached. There's no built-in core
way to cache DataList results, so for now we accept
that there's less caching due to this internal change.
This commit is contained in:
Ingo Schommer 2012-08-14 11:25:00 +02:00
parent 6d7700f8f6
commit 7d9a802073

View File

@ -315,7 +315,7 @@ class Translatable extends DataExtension implements PermissionProvider {
$orig = Translatable::get_current_locale(); $orig = Translatable::get_current_locale();
Translatable::set_current_locale($locale); Translatable::set_current_locale($locale);
$do = DataObject::get_one($class, $filter, $cache, $orderby); $do = $class::get()->where($filter)->sort($orderby)->First();
Translatable::set_current_locale($orig); Translatable::set_current_locale($orig);
return $do; return $do;
} }
@ -333,13 +333,18 @@ class Translatable extends DataExtension implements PermissionProvider {
* @param string $having A filter to be inserted into the HAVING clause. * @param string $having A filter to be inserted into the HAVING clause.
* @return mixed The objects matching the conditions. * @return mixed The objects matching the conditions.
*/ */
static function get_by_locale($class, $locale, $filter = '', $sort = '', $join = "", $limit = "", $containerClass = "DataList", $having = "") { static function get_by_locale($class, $locale, $filter = '', $sort = '', $join = "", $limit = "") {
if($locale && !i18n::validate_locale($locale)) throw new InvalidArgumentException(sprintf('Invalid locale "%s"', $locale)); if($locale && !i18n::validate_locale($locale)) throw new InvalidArgumentException(sprintf('Invalid locale "%s"', $locale));
$oldLang = self::get_current_locale(); $oldLang = self::get_current_locale();
self::set_current_locale($locale); self::set_current_locale($locale);
$result = DataObject::get($class, $filter, $sort, $join, $limit, $containerClass, $having); $result = $class::get();
if($filter) $result = $result->where($filter);
if($sort) $result = $result->sort($sort);
if($join) $result = $result->leftJoin($join);
if($limit) $result = $result->limit($limit);
self::set_current_locale($oldLang); self::set_current_locale($oldLang);
return $result; return $result;
} }
@ -867,15 +872,11 @@ class Translatable extends DataExtension implements PermissionProvider {
// Find the locale language-independent of the page // Find the locale language-independent of the page
self::disable_locale_filter(); self::disable_locale_filter();
$default = DataObject::get_one ( $default = SiteTree::get()->where(sprintf (
'SiteTree', '"URLSegment" = \'%s\'%s',
sprintf ( Convert::raw2sql($URLSegment),
'"URLSegment" = \'%s\'%s', (is_int($parentID) ? " AND \"ParentID\" = $parentID" : null)
Convert::raw2sql($URLSegment), ))->First();
(is_int($parentID) ? " AND \"ParentID\" = $parentID" : null)
),
false
);
self::enable_locale_filter(); self::enable_locale_filter();
return $default; return $default;
@ -1104,7 +1105,9 @@ class Translatable extends DataExtension implements PermissionProvider {
)->leftJoin("{$baseDataClass}_translationgroups", $joinOnClause); )->leftJoin("{$baseDataClass}_translationgroups", $joinOnClause);
if($stage) Versioned::reading_stage($currentStage); if($stage) Versioned::reading_stage($currentStage);
} else { } else {
$translations = DataObject::get($this->owner->class, $filter) $class = $this->owner->class;
$translations = $class::get()
->where($filter)
->leftJoin("{$baseDataClass}_translationgroups", $joinOnClause); ->leftJoin("{$baseDataClass}_translationgroups", $joinOnClause);
} }
@ -1498,7 +1501,7 @@ class Translatable extends DataExtension implements PermissionProvider {
* @return bool * @return bool
*/ */
public function augmentValidURLSegment() { public function augmentValidURLSegment() {
if (self::locale_filter_enabled()) { if(self::locale_filter_enabled()) {
self::disable_locale_filter(); self::disable_locale_filter();
$reEnableFilter = true; $reEnableFilter = true;
} }
@ -1513,14 +1516,12 @@ class Translatable extends DataExtension implements PermissionProvider {
} }
} }
$existingPage = DataObject::get_one( $existingPage = SiteTree::get()
'SiteTree', // disable get_one cache, as this otherwise may pick up results from when locale_filter was on
"\"URLSegment\" = '{$this->owner->URLSegment}' $IDFilter $parentFilter", ->where("\"URLSegment\" = '{$this->owner->URLSegment}' $IDFilter $parentFilter")->First();
false // disable get_one cache, as this otherwise may pick up results from when locale_filter was on
); if($reEnableFilter) self::enable_locale_filter();
if ($reEnableFilter) {
self::enable_locale_filter();
}
return !$existingPage; return !$existingPage;
} }