From 9da26596bc69abd6a07ac3e7b487b32b1ebd059a Mon Sep 17 00:00:00 2001 From: Egorka Date: Fri, 14 Sep 2018 20:00:59 +0300 Subject: [PATCH] Module view list fix ModuleRecord add isSystem boolean method Console module controller stop deleting system module --- backend/views/module/list.php | 41 +++++++++++++++++++------------- console/controllers/ModuleController.php | 18 +++++++++----- core/entities/ModuleRecord.php | 5 ++++ 3 files changed, 42 insertions(+), 22 deletions(-) diff --git a/backend/views/module/list.php b/backend/views/module/list.php index be966c0..3ac40c3 100644 --- a/backend/views/module/list.php +++ b/backend/views/module/list.php @@ -56,26 +56,35 @@ $this->registerJs($js, $this::POS_READY); diff --git a/console/controllers/ModuleController.php b/console/controllers/ModuleController.php index cba2f5d..a178d85 100644 --- a/console/controllers/ModuleController.php +++ b/console/controllers/ModuleController.php @@ -120,18 +120,24 @@ class ModuleController extends Controller public function actionRemove($name) { - $path = \Yii::getAlias('@common/modules/' . $name); - echo ConsoleColor::log('Removing module: ', 'yellow') . ConsoleColor::log($name, 'white') . PHP_EOL; - - // get module manifest - $manifest = require \Yii::getAlias('@common/modules/' . $name . '/manifest.php'); - // drop module record $db_module = ModuleRecord::find()->andWhere(['name' => $name])->one(); + + if ($db_module == ModuleRecord::SYSTEM_YES) { + echo ConsoleColor::log('Module ' . $name . ' is system. Cannot be deleted.', 'red') . PHP_EOL; + return; + } + if ($db_module) { $this->_service->delete($db_module); } + $path = \Yii::getAlias('@common/modules/' . $name); + echo ConsoleColor::log('Removing module: ', 'yellow') . ConsoleColor::log($name, 'white') . PHP_EOL; + + // get module manifest + $manifest = require \Yii::getAlias('@common/modules/' . $name . '/manifest.php'); + // revert migration echo ConsoleColor::log('Database: ', 'normal'); if (file_exists($path . '/migrations')) { diff --git a/core/entities/ModuleRecord.php b/core/entities/ModuleRecord.php index ed1fc61..146cc5a 100644 --- a/core/entities/ModuleRecord.php +++ b/core/entities/ModuleRecord.php @@ -68,6 +68,11 @@ class ModuleRecord extends \yii\db\ActiveRecord return $this->active == $this::STATUS_DISABLED; } + public function isSystem(): bool + { + return $this->system == $this::SYSTEM_YES; + } + public static function find(): ModuleRecordQuery { return new ModuleRecordQuery(static::class);