This method performs the following steps in order:
1. call [[beforeDelete()]]. If the method returns false, it will skip the
rest of the steps;
2. delete the record from the database;
3. call [[afterDelete()]].
In the above step 1 and 3, events named [[EVENT_BEFORE_DELETE]] and [[EVENT_AFTER_DELETE]]
will be raised by the corresponding methods.
public function delete() { foreach ($this->answerVariants as $model) { $model->delete(); } parent::delete(); }
public function delete() { foreach ($this->getFotos()->all() as $foto) { $foto->delete(); } return parent::delete(); }
public function delete() { if (parent::delete()) { Page::updateAll(['category_key' => null], ['category_key' => $this->key, 'lang_code' => $this->lang_code]); return true; } return false; }
public function delete() { foreach ($this->tasks as $task) { $task->delete(); } return parent::delete(); // TODO: Change the autogenerated stub }
/** * function ->delete () */ public function delete() { // $now = strtotime('now'); // $username = Yii::$app->user->identity->username; if (parent::delete()) { return true; } return false; }
public function delete() { $result = parent::delete(); if ($result) { // При изменении препаратов, менять пользователя и дату изменения в карте глаукомного пациента Glaukuchet::findOne($this->id_glaukuchet)->UpdateChangeAttributes(); } return $result; }
/** * @param ActiveRecord $model * @param array $params * @return bool * @throws \Exception */ public function performModelDelete(ActiveRecord $model, array $params) { Yii::$app->response->format = Response::FORMAT_JSON; if ($model->delete()) { if (isset($params['afterDelete']) && is_callable($params['afterDelete'])) { call_user_func($params['afterDelete'], $model); } $data = ['success' => true, 'message' => Yii::t('management', 'Model has been removed')]; if (isset($params['success']) && is_callable($params['success'])) { $data = array_merge($data, call_user_func($params['success'], $model)); } } else { $data = ['success' => false, 'message' => Yii::t('management', 'Model not saved'), 'messages' => ActiveForm::validate($model)]; if (isset($params['error']) && is_callable($params['error'])) { $data = array_merge($data, call_user_func($params['error'], $model)); } } return $this->sendJson($data); }
/** * Suppression d'un objet * Cette méthode renvoie un objet de type Response. Elle doit être appelée sur un return comme la méthode redirect() de la classe * Controller. Ex. : return $this->redirectAfterCreateSuccess($model) * * @param ActiveRecord $model * @param string|null $redirectTo * @return \yii\web\Response */ protected function deleteModelAndRedirect(ActiveRecord $model, $redirectTo = null) { try { if (!$model->delete()) { Yii::$app->session->setFlash('flash-danger', HLib::t('messages', 'Delete unsuccessful')); } else { Yii::$app->session->setFlash('flash-success', HLib::t('messages', 'Delete successful')); } } catch (StaleObjectException $s) { Yii::$app->session->setFlash('flash-warning', HLib::t('messages', 'This object is outdated. Deletion failed')); } catch (IntegrityException $s) { Yii::$app->session->setFlash('flash-warning', HLib::t('messages', 'This object is referenced by another object. Deletion failed')); } catch (Exception $s) { Yii::$app->session->setFlash('flash-danger', HLib::t('messages', 'An error occured during the process. Deletion failed')); } if (is_null($redirectTo)) { $redirectTo = Url::to([$this->getControllerRoute() . '/index']); } return $this->redirect($redirectTo); }
/** * Destroys the relationship between two models. * * The model with the foreign key of the relationship will be deleted if `$delete` is true. * Otherwise, the foreign key will be set null and the model will be saved without validation. * * @param string $name the case sensitive name of the relationship. * @param ActiveRecord $model the model to be unlinked from the current one. * @param boolean $delete whether to delete the model that contains the foreign key. * If false, the model's foreign key will be set null and saved. * If true, the model containing the foreign key will be deleted. * @throws InvalidCallException if the models cannot be unlinked */ public function unlink($name, $model, $delete = false) { $relation = $this->getRelation($name); if ($relation->via !== null) { if (is_array($relation->via)) { /** @var ActiveRelation $viaRelation */ list($viaName, $viaRelation) = $relation->via; $viaClass = $viaRelation->modelClass; unset($this->_related[$viaName]); } else { $viaRelation = $relation->via; $viaTable = reset($relation->via->from); } $columns = []; foreach ($viaRelation->link as $a => $b) { $columns[$a] = $this->{$b}; } foreach ($relation->link as $a => $b) { $columns[$b] = $model->{$a}; } if (is_array($relation->via)) { /** @var $viaClass ActiveRecord */ if ($delete) { $viaClass::deleteAll($columns); } else { $nulls = []; foreach (array_keys($columns) as $a) { $nulls[$a] = null; } $viaClass::updateAll($nulls, $columns); } } else { /** @var $viaTable string */ $command = static::getDb()->createCommand(); if ($delete) { $command->delete($viaTable, $columns)->execute(); } else { $nulls = []; foreach (array_keys($columns) as $a) { $nulls[$a] = null; } $command->update($viaTable, $nulls, $columns)->execute(); } } } else { $p1 = $model->isPrimaryKey(array_keys($relation->link)); $p2 = $this->isPrimaryKey(array_values($relation->link)); if ($p1 && $p2 || $p2) { foreach ($relation->link as $a => $b) { $model->{$a} = null; } $delete ? $model->delete() : $model->save(false); } elseif ($p1) { foreach ($relation->link as $b) { $this->{$b} = null; } $delete ? $this->delete() : $this->save(false); } else { throw new InvalidCallException('Unable to unlink models: the link does not involve any primary key.'); } } if (!$relation->multiple) { unset($this->_related[$name]); } elseif (isset($this->_related[$name])) { /** @var ActiveRecord $b */ foreach ($this->_related[$name] as $a => $b) { if ($model->getPrimaryKey() == $b->getPrimaryKey()) { unset($this->_related[$name][$a]); } } } }
public function delete() { if ($this->canDelete()) { return parent::delete(); } return false; }
/** * function ->delete () */ public function delete() { $now = strtotime('now'); $username = Yii::$app->user->identity->username; $model = $this; if ($log = new UserLog()) { $log->username = $username; $log->action = "Delete"; $log->object_class = "ProductTranslation"; $log->object_pk = $model->id; $log->created_at = $now; $log->is_success = 0; $log->save(); } if (parent::delete()) { if ($log) { $log->is_success = 1; $log->save(); } FileUtils::removeFolder(Yii::$app->params['images_folder'] . $model->image_path); return true; } return false; }
public function delete() { $this->removeImages(); parent::delete(); }
public function delete() { if (is_file($this->getSrcPath())) { unlink($this->getSrcPath()); } if (is_file($this->getPreviewPath())) { unlink($this->getPreviewPath()); } parent::delete(); }
public function delete() { //$this->gallery->dec(); $this->unlink_images($this->type); return parent::delete(); }
public function delete() { if ($res = parent::delete()) { foreach ($this->tagRelation as $tag) { $tag->delete(); } $this->storage->delete($this->image); return $res; } return false; }
public function delete() { if (parent::delete()) { foreach ($this->childs as $child) { $child->delete(); } } return false; }
/** * Deletes the table row corresponding to this active record. * * This method performs the following steps in order: * * 1. call [[beforeDelete()]]. If the method returns false, it will skip the * rest of the steps; * 2. delete the record from the database; * 3. call [[afterDelete()]]. * * In the above step 1 and 3, events named [[EVENT_BEFORE_DELETE]] and [[EVENT_AFTER_DELETE]] * will be raised by the corresponding methods. * * @param boolean $withSubtree whether subtree should be deleted with model or simply attach to model's parent * @return integer|false the number of rows deleted, or false if the deletion is unsuccessful for some reason. * Note that it is possible the number of rows deleted is 0, even though the deletion execution is successful. * @throws StaleObjectException if [[optimisticLock|optimistic locking]] is enabled and the data * being deleted is outdated. * @throws Exception2 in case delete failed. */ public function delete($withSubtree = false) { if ($this->getChildren()->count() == 0) { return parent::delete(); } $transaction = $this->getDb()->beginTransaction(); try { if ($withSubtree) { $this->removeDescendants(); } else { $idParentAttribute = $this->getIdParentAttribute(); $this->changeMyChildrensParentToGrandparent($this->{$idParentAttribute}); } if (parent::delete()) { $transaction->commit(); return true; } else { $transaction->rollBack(); return false; } } catch (Exception $e) { $transaction->rollBack(); throw $e; } }
public function delete() { parent::delete(); }
/** * permanently delete model * * @return boolean */ public function hardDelete() { return parent::delete(); }
/** Deside delete user or just set a deleted status */ public function delete() { if (!($this->id == 1 && $this->module->cantDeleteRoot == true)) { if ($this->status == self::STATUS_DELETED) { Yii::$app->authManager->revokeAll($this->getId()); parent::delete(); } else { $this->status = self::STATUS_DELETED; $this->save(false); // validation = false } } }
/** * Delete the current record * * @see \yii\db\BaseActiveRecord::delete() * * @param boolean $hasParentModel * whether this method was called from the top level or by a parent * If false, it means the method was called at the top level * @param boolean $fromDeleteFull * has the delete() call come from deleteFull() or not * @return boolean * did delete() successfully process */ public function delete($hasParentModel = false, $fromDeleteFull = false) { $ok = true; if (!$this->getReadOnly() && $this->getCanDelete()) { try { $ok = parent::delete(); } catch (\Exception $e) { $ok = false; $this->addActionError($e->getMessage(), $e->getCode()); } if ($ok && !$fromDeleteFull) { $this->deleteWrapUp(); } } elseif (!$hasParentModel) { $message = 'Attempting to delete ' . Tools::getClassName($this) . ($this->getReadOnly() ? ' readOnly model' : ' model flagged as not deletable'); //$this->addActionError($message); throw new Exception($message); } else { $this->addActionWarning('Skipped delete of ' . Tools::getClassName($this) . ' which is ' . ($this->getReadOnly() ? 'read only' : 'flagged as not deletable')); } return $ok; }
/** * function ->delete () */ public function delete() { $now = strtotime('now'); $username = Yii::$app->user->identity->username; $model = $this; if ($log = new UserLog()) { $log->username = $username; $log->action = "Delete ProductCategoryTranslation, id = {$model->id}"; $log->created_at = $now; $log->type = 3; $log->is_success = 0; $log->save(); } if (parent::delete()) { if ($log) { $log->is_success = 1; $log->save(); } return true; } return false; }
/** * @param ActiveRecord $model * @return ActiveRecord * @throws \yii\web\ServerErrorHttpException */ protected function chainDelete($model) { if (!$model->delete()) { if (YII_DEBUG) { Yii::$app->response->statusCode = 500; Yii::$app->response->format = Response::FORMAT_JSON; var_dump($model->getErrors()); Yii::$app->end(); } throw new ServerErrorHttpException('Do not able to save the model.'); } return $model; }
public function delete() { $filename = $this->getContainerDir() . '/' . $this->filename; if (is_writable($filename) && unlink($filename)) { // silently fail removing container directory if not empty rmdir($this->getContainerDir()); return parent::delete(); } return false; }
public function delete() { $images = Magic::find()->where(['module' => $this->formName(), 'group_id' => 0, 'record_id' => $this->id])->all(); if ($images) { foreach ($images as $image) { $image->delete(); } } parent::delete(); }
/** * function ->delete () */ public function delete() { $now = strtotime('now'); $username = Yii::$app->user->identity->username; $model = $this; if ($log = new UserLog()) { $log->username = $username; $log->action = 'Delete'; $log->object_class = 'ProductCategoryToProduct'; $log->object_pk = $model->id; $log->created_at = $now; $log->is_success = 0; $log->save(); } if (parent::delete()) { if ($log) { $log->is_success = 1; $log->save(); } return true; } return false; }
/** * @param \yii\db\ActiveRecord $model * @return bool */ private function deleteTranslation($model) { if (!$model->isNewRecord) { $model->delete(); unset($this->_models[$model->getAttribute($this->languageAttribute)]); } return true; }
/** * @inheritdoc */ public function delete() { $this->trigger(static::EVENT_AFTER_DELETE_TRANSACTION); return parent::delete(); }
public function delete() { unlink("{$this->basePath}/{$this->path}"); return parent::delete(); }