/** * Performs a delete on given scaffolded Model. * * @param CakeRequest $request Request for scaffolding * @return mixed Success on delete, error if delete fails * @throws MethodNotAllowedException When HTTP method is not a DELETE * @throws NotFoundException When id being deleted does not exist. */ protected function _scaffoldDelete(CakeRequest $request) { if ($this->controller->beforeScaffold('delete')) { if (!$request->is('post')) { throw new MethodNotAllowedException(); } $id = false; if (isset($request->params['pass'][0])) { $id = $request->params['pass'][0]; } $this->ScaffoldModel->id = $id; if (!$this->ScaffoldModel->exists()) { throw new NotFoundException(__d('cake', 'Invalid %s', Inflector::humanize($this->modelClass))); } if ($this->ScaffoldModel->delete()) { $message = __d('cake', 'The %1$s with id: %2$s has been deleted.', Inflector::humanize($this->modelClass), $id); return $this->_sendMessage($message); } else { $message = __d('cake', 'There was an error deleting the %1$s with id: %2$s', Inflector::humanize($this->modelClass), $id ); return $this->_sendMessage($message); } } elseif ($this->controller->scaffoldError('delete') === false) { return $this->_scaffoldError(); } }
/** * Performs a delete on given scaffolded Model. * * @param CakeRequest $request Request for scaffolding * @return mixed Success on delete, error if delete fails * @throws MethodNotAllowedException When HTTP method is not a DELETE * @throws NotFoundException When id being deleted does not exist. */ protected function _scaffoldDelete(CakeRequest $request) { if ($this->controller->beforeScaffold('delete')) { $modelClass = $this->controller->modelClass; if (!$request->is('post')) { throw new MethodNotAllowedException(); } $id = false; if (isset($request->params['pass'][0])) { $id = $request->params['pass'][0]; } $this->ScaffoldModel->id = $id; if (!$this->ScaffoldModel->exists()) { throw new NotFoundException(__d('cake', '%s inválido', Inflector::humanize($this->modelClass))); } $deleteID = $this->ScaffoldModel->id; if ($deleteID) { $tableFields = $this->ScaffoldModel->_schema; foreach ($tableFields as $key => $val) { if (subStr($key, -5) == '_file' || subStr($key, -10) == '_th_hidden') { $thisRecord = $this->ScaffoldModel->find('all', array('conditions' => array($modelClass . '.id' => $id))); if (file_exists($thisRecord[0][$modelClass][$key])) { if (!unlink($thisRecord[0][$modelClass][$key])) { unlink($thisRecord[0][$modelClass][$key]); } } } } } if ($this->ScaffoldModel->delete()) { $message = __d('cake', '%1$s com o id: %2$s foi apagado.', Inflector::humanize($this->modelClass), $id); return $this->_sendMessage($message); } else { $message = __d('cake', 'Houve um erro ao apagar %1$s com o id: %2$s', Inflector::humanize($this->modelClass), $id); return $this->_sendMessage($message); } } elseif ($this->controller->scaffoldError('delete') === false) { return $this->_scaffoldError(); } }
/** * testToBeInheritedGuardmethods method * * @return void */ public function testToBeInheritedGuardmethods() { $request = new CakeRequest('controller_posts/index'); $Controller = new Controller($request, $this->getMock('CakeResponse')); $this->assertTrue($Controller->beforeScaffold('')); $this->assertTrue($Controller->afterScaffoldSave('')); $this->assertTrue($Controller->afterScaffoldSaveError('')); $this->assertFalse($Controller->scaffoldError('')); }