Merge pull request #12692 from bancer/model-exists-without-id

Add model id to all `exists()` method calls
This commit is contained in:
Mark Story 2018-11-01 21:21:27 -04:00 committed by GitHub
commit b1a93df604
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 11 additions and 14 deletions

View file

@ -131,12 +131,11 @@
* @return void * @return void
*/ */
public function <?php echo $admin; ?>delete($id = null) { public function <?php echo $admin; ?>delete($id = null) {
$this-><?php echo $currentModelName; ?>->id = $id; if (!$this-><?php echo $currentModelName; ?>->exists($id)) {
if (!$this-><?php echo $currentModelName; ?>->exists()) {
throw new NotFoundException(__('Invalid <?php echo strtolower($singularHumanName); ?>')); throw new NotFoundException(__('Invalid <?php echo strtolower($singularHumanName); ?>'));
} }
$this->request->allowMethod('post', 'delete'); $this->request->allowMethod('post', 'delete');
if ($this-><?php echo $currentModelName; ?>->delete()) { if ($this-><?php echo $currentModelName; ?>->delete($id)) {
<?php if ($wannaUseSession): ?> <?php if ($wannaUseSession): ?>
$this->Flash->success(__('The <?php echo strtolower($singularHumanName); ?> has been deleted.')); $this->Flash->success(__('The <?php echo strtolower($singularHumanName); ?> has been deleted.'));
} else { } else {

View file

@ -225,7 +225,7 @@ class TreeBehavior extends ModelBehavior {
} }
$parentIsSet = array_key_exists($parent, $Model->data[$Model->alias]); $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]) { if ($parentIsSet && $Model->data[$Model->alias][$parent]) {
$parentNode = $this->_getNode($Model, $Model->data[$Model->alias][$parent]); $parentNode = $this->_getNode($Model, $Model->data[$Model->alias][$parent]);
if (!$parentNode) { if (!$parentNode) {

View file

@ -2547,7 +2547,7 @@ class DboSource extends DataSource {
if (!empty($conditions)) { if (!empty($conditions)) {
return $conditions; return $conditions;
} }
$exists = $Model->exists(); $exists = $Model->exists($Model->getID());
if (!$exists && ($conditions !== null || !empty($Model->__safeUpdateMode))) { if (!$exists && ($conditions !== null || !empty($Model->__safeUpdateMode))) {
return false; return false;
} elseif (!$exists) { } elseif (!$exists) {

View file

@ -1824,7 +1824,7 @@ class Model extends CakeObject implements CakeEventListener {
} }
} }
$exists = $this->exists(); $exists = $this->exists($this->getID());
$dateFields = array('modified', 'updated'); $dateFields = array('modified', 'updated');
if (!$exists) { if (!$exists) {
@ -2696,7 +2696,7 @@ class Model extends CakeObject implements CakeEventListener {
return false; return false;
} }
if (!$this->exists()) { if (!$this->exists($this->getID())) {
return false; return false;
} }

View file

@ -257,7 +257,7 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable {
} }
} }
$exists = $model->exists(); $exists = $model->exists($model->getID());
$methods = $this->getMethods(); $methods = $this->getMethods();
$fields = $this->_validationList($fieldList); $fields = $this->_validationList($fieldList);

View file

@ -77,12 +77,11 @@
* @return void * @return void
*/ */
public function delete($id = null) { public function delete($id = null) {
$this->BakeArticle->id = $id; if (!$this->BakeArticle->exists($id)) {
if (!$this->BakeArticle->exists()) {
throw new NotFoundException(__('Invalid bake article')); throw new NotFoundException(__('Invalid bake article'));
} }
$this->request->allowMethod('post', 'delete'); $this->request->allowMethod('post', 'delete');
if ($this->BakeArticle->delete()) { if ($this->BakeArticle->delete($id)) {
$this->Flash->success(__('The bake article has been deleted.')); $this->Flash->success(__('The bake article has been deleted.'));
} else { } else {
$this->Flash->error(__('The bake article could not be deleted. Please, try again.')); $this->Flash->error(__('The bake article could not be deleted. Please, try again.'));

View file

@ -71,12 +71,11 @@
* @return void * @return void
*/ */
public function delete($id = null) { public function delete($id = null) {
$this->BakeArticle->id = $id; if (!$this->BakeArticle->exists($id)) {
if (!$this->BakeArticle->exists()) {
throw new NotFoundException(__('Invalid bake article')); throw new NotFoundException(__('Invalid bake article'));
} }
$this->request->allowMethod('post', 'delete'); $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')); return $this->flash(__('The bake article has been deleted.'), array('action' => 'index'));
} else { } else {
return $this->flash(__('The bake article could not be deleted. Please, try again.'), array('action' => 'index')); return $this->flash(__('The bake article could not be deleted. Please, try again.'), array('action' => 'index'));