mirror of
https://github.com/processwire/processwire.git
synced 2025-08-16 03:34:33 +02:00
Fix issue processwire/processwire-issues#1535
This commit is contained in:
@@ -1834,7 +1834,7 @@ class PagesEditor extends Wire {
|
|||||||
// detect name from path
|
// detect name from path
|
||||||
$options['name'] = $name;
|
$options['name'] = $name;
|
||||||
}
|
}
|
||||||
if(empty($parent)) {
|
if(empty($parent) && !$this->pages->loader()->isLoading()) {
|
||||||
// detect parent from path
|
// detect parent from path
|
||||||
$parentPath = count($parts) ? implode('/', $parts) : '/';
|
$parentPath = count($parts) ? implode('/', $parts) : '/';
|
||||||
$parent = $this->pages->getByPath($parentPath);
|
$parent = $this->pages->getByPath($parentPath);
|
||||||
@@ -1844,7 +1844,7 @@ class PagesEditor extends Wire {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// detect template from parent (when possible)
|
// detect template from parent (when possible)
|
||||||
if(!$template && !empty($parent) && empty($options['id'])) {
|
if(!$template && !empty($parent) && empty($options['id']) && !$this->pages->loader()->isLoading()) {
|
||||||
$parent = is_object($parent) ? $parent : $this->pages->get($parent);
|
$parent = is_object($parent) ? $parent : $this->pages->get($parent);
|
||||||
if($parent->id) {
|
if($parent->id) {
|
||||||
if(count($parent->template->childTemplates) === 1) {
|
if(count($parent->template->childTemplates) === 1) {
|
||||||
@@ -1856,12 +1856,15 @@ class PagesEditor extends Wire {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// detect parent from template (when possible)
|
// detect parent from template (when possible)
|
||||||
if($template && empty($parent) && empty($options['id']) && count($template->parentTemplates) === 1) {
|
if($template && empty($parent) && empty($options['id']) && !$this->pages->loader()->isLoading()) {
|
||||||
|
if(count($template->parentTemplates) === 1) {
|
||||||
$parentTemplates = $template->parentTemplates();
|
$parentTemplates = $template->parentTemplates();
|
||||||
if($parentTemplates->count()) {
|
if($parentTemplates->count()) {
|
||||||
$numParents = $this->pages->count("template=$parentTemplates, include=all");
|
$numParents = $this->pages->count("template=$parentTemplates, include=all");
|
||||||
if($numParents === 1) {
|
if($numParents === 1) {
|
||||||
$parent = $this->pages->get("template=$parentTemplates");
|
$parent = $this->pages->get("template=$parentTemplates");
|
||||||
|
if(!$parent->id) $parent = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -64,6 +64,14 @@ class PagesLoader extends Wire {
|
|||||||
*/
|
*/
|
||||||
protected $debug = false;
|
protected $debug = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Are we currenty loading pages?
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected $loading = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Page instance ID
|
* Page instance ID
|
||||||
*
|
*
|
||||||
@@ -415,7 +423,9 @@ class PagesLoader extends Wire {
|
|||||||
$cachePages = false;
|
$cachePages = false;
|
||||||
$template = null;
|
$template = null;
|
||||||
$templatesByID = array();
|
$templatesByID = array();
|
||||||
|
$loading = $this->loading;
|
||||||
|
|
||||||
|
if(!$loading) $this->loading = true;
|
||||||
foreach($pagesIDs as $id => $templateID) {
|
foreach($pagesIDs as $id => $templateID) {
|
||||||
if(isset($templatesByID[$templateID])) {
|
if(isset($templatesByID[$templateID])) {
|
||||||
$template = $templatesByID[$templateID];
|
$template = $templatesByID[$templateID];
|
||||||
@@ -429,6 +439,7 @@ class PagesLoader extends Wire {
|
|||||||
$pages->add($page);
|
$pages->add($page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!$loading) $this->loading = false;
|
||||||
$pages->setDuplicateChecking(true);
|
$pages->setDuplicateChecking(true);
|
||||||
if(count($pagesIDs)) $pages->_lazy(true);
|
if(count($pagesIDs)) $pages->_lazy(true);
|
||||||
unset($template, $templatesByID);
|
unset($template, $templatesByID);
|
||||||
@@ -934,6 +945,7 @@ class PagesLoader extends Wire {
|
|||||||
/** @var WireDatabasePDO $database */
|
/** @var WireDatabasePDO $database */
|
||||||
$database = $this->wire('database');
|
$database = $this->wire('database');
|
||||||
$idsByTemplate = array();
|
$idsByTemplate = array();
|
||||||
|
$loading = $this->loading;
|
||||||
|
|
||||||
if(is_array($template)) {
|
if(is_array($template)) {
|
||||||
// $template property specifies an array of options
|
// $template property specifies an array of options
|
||||||
@@ -1045,6 +1057,7 @@ class PagesLoader extends Wire {
|
|||||||
return $pages;
|
return $pages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!$loading) $this->loading = true;
|
||||||
|
|
||||||
if(count($idsByTemplate)) {
|
if(count($idsByTemplate)) {
|
||||||
// ok
|
// ok
|
||||||
@@ -1205,11 +1218,16 @@ class PagesLoader extends Wire {
|
|||||||
$template = null;
|
$template = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($options['getOne']) return count($loaded) ? reset($loaded) : $this->pages->newNullPage();
|
if($options['getOne']) {
|
||||||
|
if(!$loading) $this->loading = false;
|
||||||
|
return count($loaded) ? reset($loaded) : $this->pages->newNullPage();
|
||||||
|
}
|
||||||
|
|
||||||
$pages = $this->pages->newPageArray($options);
|
$pages = $this->pages->newPageArray($options);
|
||||||
$pages->setDuplicateChecking(false);
|
$pages->setDuplicateChecking(false);
|
||||||
$pages->import($loaded);
|
$pages->import($loaded);
|
||||||
$pages->setDuplicateChecking(true);
|
$pages->setDuplicateChecking(true);
|
||||||
|
if(!$loading) $this->loading = false;
|
||||||
|
|
||||||
// debug mode only
|
// debug mode only
|
||||||
if($this->debug) {
|
if($this->debug) {
|
||||||
@@ -1231,6 +1249,7 @@ class PagesLoader extends Wire {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return $pages;
|
return $pages;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1922,4 +1941,16 @@ class PagesLoader extends Wire {
|
|||||||
return $this->lastPageFinder;
|
return $this->lastPageFinder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Are we currently loading pages?
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
* @since 3.0.195
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function isLoading() {
|
||||||
|
return $this->loading;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user