From 5ddc25a019fd27c8bd1770af37b80f5c7cf0570b Mon Sep 17 00:00:00 2001 From: FdeQuillettes Date: Wed, 24 Jun 2015 13:10:17 +0200 Subject: [PATCH 1/4] removed check for statusSystemID removed check for statusSystemID, clone doesn't affect the id or delete the page --- wire/modules/Process/ProcessPageClone.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wire/modules/Process/ProcessPageClone.module b/wire/modules/Process/ProcessPageClone.module index 68cdfbcd..b8ee49f0 100644 --- a/wire/modules/Process/ProcessPageClone.module +++ b/wire/modules/Process/ProcessPageClone.module @@ -113,7 +113,7 @@ class ProcessPageClone extends Process { public function hasPermission(Page $page) { $user = $this->user; - if($page->is(Page::statusSystem) || $page->is(Page::statusSystemID)) return false; + if($page->is(Page::statusSystem)) return false; if($page->parent->template->noChildren) return false; if($page->template->noParents) return false; From 2efcb2f36c45ea29e939904b409f786e5f3a8ddc Mon Sep 17 00:00:00 2001 From: FdeQuillettes Date: Wed, 24 Jun 2015 14:46:38 +0200 Subject: [PATCH 2/4] when cloning pages, status should be ignored There is no status that technically denies cloning, but statusSystemID and statusSystem prevent cloning in the current implmentation. Therefore during the cloning, status should be 1 for the newly cloned page. When the actual cloning is done, the original status can be restored. --- wire/core/Pages.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/wire/core/Pages.php b/wire/core/Pages.php index 86ce8ab3..e5127de4 100644 --- a/wire/core/Pages.php +++ b/wire/core/Pages.php @@ -1591,6 +1591,10 @@ public function ___clone(Page $page, Page $parent = null, $recursive = true, $op foreach($page->template->fieldgroup as $field) { $page->get($field->name); } + + $oldStatus = $page->status; + $page->status = $page->status | Page::statusSystemOverride; + $page->status = 1; // clone in memory $copy = clone $page; @@ -1618,6 +1622,8 @@ public function ___clone(Page $page, Page $parent = null, $recursive = true, $op $this->cloning = true; $options['ignoreFamily'] = true; // skip family checks during clone $this->save($copy, $options); + $copy->status = $oldStatus; + $copy->save(); } catch(Exception $e) { $this->cloning = false; throw $e; From f74b61cbc67de84217fccaeadbced2ea6dd893ef Mon Sep 17 00:00:00 2001 From: FdeQuillettes Date: Wed, 24 Jun 2015 14:54:23 +0200 Subject: [PATCH 3/4] removed check for statusSystemID and statusSystem neither should block cloning --- wire/modules/Process/ProcessPageClone.module | 1 - 1 file changed, 1 deletion(-) diff --git a/wire/modules/Process/ProcessPageClone.module b/wire/modules/Process/ProcessPageClone.module index b8ee49f0..2f311499 100644 --- a/wire/modules/Process/ProcessPageClone.module +++ b/wire/modules/Process/ProcessPageClone.module @@ -113,7 +113,6 @@ class ProcessPageClone extends Process { public function hasPermission(Page $page) { $user = $this->user; - if($page->is(Page::statusSystem)) return false; if($page->parent->template->noChildren) return false; if($page->template->noParents) return false; From 7834e4983763e0fc3b109c31dc96e003da091507 Mon Sep 17 00:00:00 2001 From: FdeQuillettes Date: Thu, 25 Jun 2015 15:51:13 +0200 Subject: [PATCH 4/4] moved return based on numChildren When updating the pages_parents table, all items referencing this page were removed but not necessarily readded, resulting in queries that used has_parent not working correctly --- wire/core/Pages.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wire/core/Pages.php b/wire/core/Pages.php index e5127de4..51221e3a 100644 --- a/wire/core/Pages.php +++ b/wire/core/Pages.php @@ -1339,8 +1339,6 @@ protected function saveParents($pages_id, $numChildren, $level = 0) { $query->bindValue(':pages_id', $pages_id, PDO::PARAM_INT); $query->execute(); - if(!$numChildren) return true; - $insertSql = ''; $id = $pages_id; $cnt = 0; @@ -1362,6 +1360,8 @@ protected function saveParents($pages_id, $numChildren, $level = 0) { $sql = "INSERT INTO pages_parents (pages_id, parents_id) VALUES" . rtrim($insertSql, ","); $database->exec($sql); } + + if(!$numChildren) return true; // find all children of $pages_id that themselves have children $sql = "SELECT pages.id, COUNT(children.id) AS numChildren " .