Commit 7962dbf6 authored by john's avatar john

3031

parent f14e3733
...@@ -213,13 +213,24 @@ class DocumentationListAdminController extends AdminController ...@@ -213,13 +213,24 @@ class DocumentationListAdminController extends AdminController
*/ */
public function actionDelete($id) public function actionDelete($id)
{ {
$model = $this->findModel($id);
$items = \common\modules\documentation\models\DocContent::find()->where(['list_id' => $id])->all(); $items = \common\modules\documentation\models\DocContent::find()->where(['list_id' => $id])->all();
foreach ($items as $item) { foreach ($items as $item) {
$item->list_id = null; $item->list_id = null;
$item->save(); $item->save();
} }
$children = DocList::find()->where(['parent_id' => $id])->all();
foreach ($children as $child) {
$last = DocList::find()
->where(['=', 'parent_id', (int) $model->parent_id])
->andWhere(['!=', 'id', $model->id])
->orderBy(['position' => SORT_DESC])->one();
$child->position = $last ? $last->position + 1 : 0;
$child->parent_id = $model->parent_id;
$child->save();
}
$this->findModel($id)->delete(); $model->delete();
return $this->redirect(['manage']); return $this->redirect(['manage']);
} }
......
<?php
use yii\db\Migration;
/**
* Class m190315_091511_remove_foreighn_key_from_content
*/
class m190315_091511_remove_foreighn_key_from_content extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->dropForeignKey('fk_doc_content_doc_list', 'doc_content');
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->addForeignKey(
'fk_doc_content_doc_list', 'doc_content', 'list_id', 'doc_list', 'id'
);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment