Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

FIXED: Error where uninitialised Locale field would crash queries. #39

Merged
merged 1 commit into from

3 participants

@tractorcow
Collaborator

Fixed an error where uninitialised Locale field would crash queries. This is noticeable during full text search, when models are instantiated with lazy loading.

I had setup a full text search form for my blog, and as full text search works, only sitetree default fields are returned up front, meaning lazy-loaded fields (e.g. Locale) can not be guaranteed to exist.

The error received:

Error retrieved: "ERROR [Notice]: Undefined property: BlogEntry::$Locale"

I simply substituted in an !empty() in the augmentSQL() function to safely check for existence of a Locale value instead of simply calling the field directly.

@tractorcow tractorcow FIXED: Error where uninitialised Locale field would crash queries. Th…
…is is noticeable during full text search, when full model fields might not be initialised.
d846a72
@chillu chillu merged commit 8b923ca into from
@chillu
Owner

Good call!

@GerbenLimburg

Thanks, you made my day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 9, 2012
  1. @tractorcow

    FIXED: Error where uninitialised Locale field would crash queries. Th…

    tractorcow authored
    …is is noticeable during full text search, when full model fields might not be initialised.
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  code/model/Translatable.php
View
2  code/model/Translatable.php
@@ -539,7 +539,7 @@ function augmentSQL(SQLQuery &$query) {
// 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::get_current_locale();
+ $locale = ($this->owner->ID && !empty($this->owner->Locale)) ? $this->owner->Locale : Translatable::get_current_locale();
$baseTable = ClassInfo::baseDataClass($this->owner->class);
if(
$locale
Something went wrong with that request. Please try again.