From 3ea39d96b449d94385600e6db6482188bf9db607 Mon Sep 17 00:00:00 2001 From: bancer Date: Tue, 30 Oct 2018 10:39:16 +0100 Subject: [PATCH 1/3] Add model id to all `exists()` method calls, Related issue - https://github.com/dereuromark/cakephp-shim/issues/25 --- .../Console/Templates/default/actions/controller_actions.ctp | 2 +- lib/Cake/Model/Behavior/TreeBehavior.php | 2 +- lib/Cake/Model/Datasource/DboSource.php | 2 +- lib/Cake/Model/Model.php | 4 ++-- lib/Cake/Model/ModelValidator.php | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Cake/Console/Templates/default/actions/controller_actions.ctp b/lib/Cake/Console/Templates/default/actions/controller_actions.ctp index 8a943b9e7..463af3799 100644 --- a/lib/Cake/Console/Templates/default/actions/controller_actions.ctp +++ b/lib/Cake/Console/Templates/default/actions/controller_actions.ctp @@ -132,7 +132,7 @@ */ public function delete($id = null) { $this->->id = $id; - if (!$this->->exists()) { + if (!$this->->exists($id)) { throw new NotFoundException(__('Invalid ')); } $this->request->allowMethod('post', 'delete'); diff --git a/lib/Cake/Model/Behavior/TreeBehavior.php b/lib/Cake/Model/Behavior/TreeBehavior.php index 9fc12e706..d944007be 100644 --- a/lib/Cake/Model/Behavior/TreeBehavior.php +++ b/lib/Cake/Model/Behavior/TreeBehavior.php @@ -225,7 +225,7 @@ class TreeBehavior extends ModelBehavior { } $parentIsSet = array_key_exists($parent, $Model->data[$Model->alias]); - if (!$Model->id || !$Model->exists()) { + if (!$Model->id || !$Model->exists($Model->getID())) { if ($parentIsSet && $Model->data[$Model->alias][$parent]) { $parentNode = $this->_getNode($Model, $Model->data[$Model->alias][$parent]); if (!$parentNode) { diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 1af4f9eee..ba790a945 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -2547,7 +2547,7 @@ class DboSource extends DataSource { if (!empty($conditions)) { return $conditions; } - $exists = $Model->exists(); + $exists = $Model->exists($Model->getID()); if (!$exists && ($conditions !== null || !empty($Model->__safeUpdateMode))) { return false; } elseif (!$exists) { diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 44df5c8e7..1957baf83 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -1824,7 +1824,7 @@ class Model extends CakeObject implements CakeEventListener { } } - $exists = $this->exists(); + $exists = $this->exists($this->getID()); $dateFields = array('modified', 'updated'); if (!$exists) { @@ -2696,7 +2696,7 @@ class Model extends CakeObject implements CakeEventListener { return false; } - if (!$this->exists()) { + if (!$this->exists($this->getID())) { return false; } diff --git a/lib/Cake/Model/ModelValidator.php b/lib/Cake/Model/ModelValidator.php index 9ab4f3f2a..406c0816c 100644 --- a/lib/Cake/Model/ModelValidator.php +++ b/lib/Cake/Model/ModelValidator.php @@ -257,7 +257,7 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable { } } - $exists = $model->exists(); + $exists = $model->exists($model->getID()); $methods = $this->getMethods(); $fields = $this->_validationList($fieldList); From d8d65027ac00300e3bc843ceeebd0cba2c21e92e Mon Sep 17 00:00:00 2001 From: bancer Date: Tue, 30 Oct 2018 11:02:42 +0100 Subject: [PATCH 2/3] Adjust unit tests with id parameter for exists() method --- lib/Cake/Test/bake_compare/Controller/ActionsUsingSessions.ctp | 2 +- lib/Cake/Test/bake_compare/Controller/ActionsWithNoSessions.ctp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Test/bake_compare/Controller/ActionsUsingSessions.ctp b/lib/Cake/Test/bake_compare/Controller/ActionsUsingSessions.ctp index b4072d770..2fd1933c0 100644 --- a/lib/Cake/Test/bake_compare/Controller/ActionsUsingSessions.ctp +++ b/lib/Cake/Test/bake_compare/Controller/ActionsUsingSessions.ctp @@ -78,7 +78,7 @@ */ public function delete($id = null) { $this->BakeArticle->id = $id; - if (!$this->BakeArticle->exists()) { + if (!$this->BakeArticle->exists($id)) { throw new NotFoundException(__('Invalid bake article')); } $this->request->allowMethod('post', 'delete'); diff --git a/lib/Cake/Test/bake_compare/Controller/ActionsWithNoSessions.ctp b/lib/Cake/Test/bake_compare/Controller/ActionsWithNoSessions.ctp index d3f5b19d5..a7079a778 100644 --- a/lib/Cake/Test/bake_compare/Controller/ActionsWithNoSessions.ctp +++ b/lib/Cake/Test/bake_compare/Controller/ActionsWithNoSessions.ctp @@ -72,7 +72,7 @@ */ public function delete($id = null) { $this->BakeArticle->id = $id; - if (!$this->BakeArticle->exists()) { + if (!$this->BakeArticle->exists($id)) { throw new NotFoundException(__('Invalid bake article')); } $this->request->allowMethod('post', 'delete'); From 58ebf6a303fca3fbb6980b7aab97ad9c629ee615 Mon Sep 17 00:00:00 2001 From: bancer Date: Wed, 31 Oct 2018 09:46:01 +0100 Subject: [PATCH 3/3] Remove id property from bake template --- .../Console/Templates/default/actions/controller_actions.ctp | 3 +-- lib/Cake/Test/bake_compare/Controller/ActionsUsingSessions.ctp | 3 +-- .../Test/bake_compare/Controller/ActionsWithNoSessions.ctp | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/Cake/Console/Templates/default/actions/controller_actions.ctp b/lib/Cake/Console/Templates/default/actions/controller_actions.ctp index 463af3799..0cde5c638 100644 --- a/lib/Cake/Console/Templates/default/actions/controller_actions.ctp +++ b/lib/Cake/Console/Templates/default/actions/controller_actions.ctp @@ -131,12 +131,11 @@ * @return void */ public function delete($id = null) { - $this->->id = $id; if (!$this->->exists($id)) { throw new NotFoundException(__('Invalid ')); } $this->request->allowMethod('post', 'delete'); - if ($this->->delete()) { + if ($this->->delete($id)) { $this->Flash->success(__('The has been deleted.')); } else { diff --git a/lib/Cake/Test/bake_compare/Controller/ActionsUsingSessions.ctp b/lib/Cake/Test/bake_compare/Controller/ActionsUsingSessions.ctp index 2fd1933c0..34e3fc23f 100644 --- a/lib/Cake/Test/bake_compare/Controller/ActionsUsingSessions.ctp +++ b/lib/Cake/Test/bake_compare/Controller/ActionsUsingSessions.ctp @@ -77,12 +77,11 @@ * @return void */ public function delete($id = null) { - $this->BakeArticle->id = $id; if (!$this->BakeArticle->exists($id)) { throw new NotFoundException(__('Invalid bake article')); } $this->request->allowMethod('post', 'delete'); - if ($this->BakeArticle->delete()) { + if ($this->BakeArticle->delete($id)) { $this->Flash->success(__('The bake article has been deleted.')); } else { $this->Flash->error(__('The bake article could not be deleted. Please, try again.')); diff --git a/lib/Cake/Test/bake_compare/Controller/ActionsWithNoSessions.ctp b/lib/Cake/Test/bake_compare/Controller/ActionsWithNoSessions.ctp index a7079a778..cfdd24f7f 100644 --- a/lib/Cake/Test/bake_compare/Controller/ActionsWithNoSessions.ctp +++ b/lib/Cake/Test/bake_compare/Controller/ActionsWithNoSessions.ctp @@ -71,12 +71,11 @@ * @return void */ public function delete($id = null) { - $this->BakeArticle->id = $id; if (!$this->BakeArticle->exists($id)) { throw new NotFoundException(__('Invalid bake article')); } $this->request->allowMethod('post', 'delete'); - if ($this->BakeArticle->delete()) { + if ($this->BakeArticle->delete($id)) { return $this->flash(__('The bake article has been deleted.'), array('action' => 'index')); } else { return $this->flash(__('The bake article could not be deleted. Please, try again.'), array('action' => 'index'));