From 3ea39d96b449d94385600e6db6482188bf9db607 Mon Sep 17 00:00:00 2001 From: bancer Date: Tue, 30 Oct 2018 10:39:16 +0100 Subject: [PATCH] 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);