mirror of
https://github.com/processwire/processwire.git
synced 2025-08-10 16:54:44 +02:00
Additional updates for autojoin related issue, delay autojoin field sanitization until first access of field
This commit is contained in:
@@ -357,6 +357,14 @@ class Page extends WireData implements \Countable, WireMatchable {
|
|||||||
*/
|
*/
|
||||||
protected $fieldDataQueue = array();
|
protected $fieldDataQueue = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Field names that should be sanitized on first access (populated when isLoaded==false)
|
||||||
|
*
|
||||||
|
* @var array of (field name => raw field value)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected $sanitizeNameQueue = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is this a new page (not yet existing in the database)?
|
* Is this a new page (not yet existing in the database)?
|
||||||
*
|
*
|
||||||
@@ -902,7 +910,7 @@ class Page extends WireData implements \Countable, WireMatchable {
|
|||||||
// send the value to the Fieldtype to be woken up for storage in the page
|
// send the value to the Fieldtype to be woken up for storage in the page
|
||||||
// $value = $field->type->wakeupValue($this, $field, $value);
|
// $value = $field->type->wakeupValue($this, $field, $value);
|
||||||
$value = $field->type->_callHookMethod('wakeupValue', array($this, $field, $value));
|
$value = $field->type->_callHookMethod('wakeupValue', array($this, $field, $value));
|
||||||
$value = $field->type->sanitizeValue($this, $field, $value);
|
$this->sanitizeNameQueue[$field->name] = $field->name;
|
||||||
|
|
||||||
// page is currently loading, so we don't need to continue any further
|
// page is currently loading, so we don't need to continue any further
|
||||||
return parent::set($key, $value);
|
return parent::set($key, $value);
|
||||||
@@ -1288,7 +1296,13 @@ class Page extends WireData implements \Countable, WireMatchable {
|
|||||||
$value = parent::get($key);
|
$value = parent::get($key);
|
||||||
if(!$field) return $value; // likely a runtime field, not part of our data
|
if(!$field) return $value; // likely a runtime field, not part of our data
|
||||||
$invokeArgument = '';
|
$invokeArgument = '';
|
||||||
|
|
||||||
|
if($value !== null && isset($this->sanitizeNameQueue[$key])) {
|
||||||
|
$value = $field->type->sanitizeValue($this, $field, $value);
|
||||||
|
$this->setQuietly($key, $value);
|
||||||
|
unset($this->sanitizeNameQueue[$key]);
|
||||||
|
}
|
||||||
|
|
||||||
if($field->useRoles && $this->outputFormatting) {
|
if($field->useRoles && $this->outputFormatting) {
|
||||||
// API access may be limited when output formatting is ON
|
// API access may be limited when output formatting is ON
|
||||||
if($field->flags & Field::flagAccessAPI) {
|
if($field->flags & Field::flagAccessAPI) {
|
||||||
@@ -3520,6 +3534,7 @@ class Page extends WireData implements \Countable, WireMatchable {
|
|||||||
if($value != null && is_object($value)) {
|
if($value != null && is_object($value)) {
|
||||||
if(method_exists($value, 'uncache') && $value !== $this) $value->uncache();
|
if(method_exists($value, 'uncache') && $value !== $this) $value->uncache();
|
||||||
parent::set($field->name, null);
|
parent::set($field->name, null);
|
||||||
|
if(isset($this->sanitizeNameQueue[$field->name])) unset($this->sanitizeNameQueue[$field->name]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -641,16 +641,22 @@ class PagesLoader extends Wire {
|
|||||||
if($joinSortfield) $query->leftjoin('pages_sortfields ON pages_sortfields.pages_id=pages.id');
|
if($joinSortfield) $query->leftjoin('pages_sortfields ON pages_sortfields.pages_id=pages.id');
|
||||||
$query->groupby('pages.id');
|
$query->groupby('pages.id');
|
||||||
|
|
||||||
if($options['autojoin'] && $this->autojoin) foreach($fields as $field) {
|
if($options['autojoin'] && $this->autojoin) {
|
||||||
if(!empty($options['joinFields']) && in_array($field->name, $options['joinFields'])) {
|
foreach($fields as $field) {
|
||||||
// joinFields option specified to force autojoin this field
|
if(!empty($options['joinFields']) && in_array($field->name, $options['joinFields'])) {
|
||||||
} else {
|
// joinFields option specified to force autojoin this field
|
||||||
if(!($field->flags & Field::flagAutojoin)) continue; // autojoin not enabled for field
|
} else {
|
||||||
if($fields instanceof Fields && !($field->flags & Field::flagGlobal)) continue; // non-fieldgroup, autojoin only if global flag is set
|
// check if autojoin not enabled for field
|
||||||
|
if(!($field->flags & Field::flagAutojoin)) continue;
|
||||||
|
// non-fieldgroup, autojoin only if global flag is set
|
||||||
|
if($fields instanceof Fields && !($field->flags & Field::flagGlobal)) continue;
|
||||||
|
}
|
||||||
|
$table = $database->escapeTable($field->table);
|
||||||
|
// check autojoin not allowed, otherwise merge in the autojoin query
|
||||||
|
if(!$field->type || !$field->type->getLoadQueryAutojoin($field, $query)) continue;
|
||||||
|
// complete autojoin
|
||||||
|
$query->leftjoin("$table ON $table.pages_id=pages.id"); // QA
|
||||||
}
|
}
|
||||||
$table = $database->escapeTable($field->table);
|
|
||||||
if(!$field->type || !$field->type->getLoadQueryAutojoin($field, $query)) continue; // autojoin not allowed
|
|
||||||
$query->leftjoin("$table ON $table.pages_id=pages.id"); // QA
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!is_null($parent_id)) $query->where("pages.parent_id=" . (int) $parent_id);
|
if(!is_null($parent_id)) $query->where("pages.parent_id=" . (int) $parent_id);
|
||||||
|
Reference in New Issue
Block a user