Browse Source

Module view list fix

ModuleRecord add isSystem boolean method
Console module controller stop deleting system module
master
Egorka 6 years ago
parent
commit
9da26596bc
  1. 9
      backend/views/module/list.php
  2. 18
      console/controllers/ModuleController.php
  3. 5
      core/entities/ModuleRecord.php

9
backend/views/module/list.php

@ -56,6 +56,7 @@ $this->registerJs($js, $this::POS_READY);
<?= $module_description ?>
</div>
<div class="box-footer" style="text-align: right">
<?php if (!$module->isSystem()) : ?>
<?php if ($module->isEnabled()) : ?>
<?= Html::a(Yii::t('main', 'Disable'), ['module/disable', 'id' => $module->id], [
'class' => 'btn btn-default btn-sm',
@ -71,11 +72,19 @@ $this->registerJs($js, $this::POS_READY);
],
]) ?>
<?php endif; ?>
<?php endif; ?>
<?php if (!$module->isSystem()) : ?>
<?= Html::button(Yii::t('buttons', 'Delete'), [
'class' => 'btn btn-danger btn-sm delete-button',
'data-name' => $module->name,
]) ?>
<?php else : ?>
<?= Html::button(Yii::t('buttons', 'Delete'), [
'class' => 'btn btn-danger btn-sm disabled',
'data-name' => $module->name,
]) ?>
<?php endif; ?>
</div>
</div>
</div>

18
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')) {

5
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);

Loading…
Cancel
Save