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();
|
||||
|
||||
/**
|
||||
* 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)?
|
||||
*
|
||||
@@ -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
|
||||
// $value = $field->type->wakeupValue($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
|
||||
return parent::set($key, $value);
|
||||
@@ -1289,6 +1297,12 @@ class Page extends WireData implements \Countable, WireMatchable {
|
||||
if(!$field) return $value; // likely a runtime field, not part of our data
|
||||
$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) {
|
||||
// API access may be limited when output formatting is ON
|
||||
if($field->flags & Field::flagAccessAPI) {
|
||||
@@ -3520,6 +3534,7 @@ class Page extends WireData implements \Countable, WireMatchable {
|
||||
if($value != null && is_object($value)) {
|
||||
if(method_exists($value, 'uncache') && $value !== $this) $value->uncache();
|
||||
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');
|
||||
$query->groupby('pages.id');
|
||||
|
||||
if($options['autojoin'] && $this->autojoin) foreach($fields as $field) {
|
||||
if(!empty($options['joinFields']) && in_array($field->name, $options['joinFields'])) {
|
||||
// joinFields option specified to force autojoin this field
|
||||
} else {
|
||||
if(!($field->flags & Field::flagAutojoin)) continue; // autojoin not enabled for field
|
||||
if($fields instanceof Fields && !($field->flags & Field::flagGlobal)) continue; // non-fieldgroup, autojoin only if global flag is set
|
||||
if($options['autojoin'] && $this->autojoin) {
|
||||
foreach($fields as $field) {
|
||||
if(!empty($options['joinFields']) && in_array($field->name, $options['joinFields'])) {
|
||||
// joinFields option specified to force autojoin this field
|
||||
} else {
|
||||
// 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);
|
||||
|
Reference in New Issue
Block a user