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. 41
      backend/views/module/list.php
  2. 18
      console/controllers/ModuleController.php
  3. 5
      core/entities/ModuleRecord.php

41
backend/views/module/list.php

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

18
console/controllers/ModuleController.php

@ -120,18 +120,24 @@ class ModuleController extends Controller
public function actionRemove($name) 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 // drop module record
$db_module = ModuleRecord::find()->andWhere(['name' => $name])->one(); $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) { if ($db_module) {
$this->_service->delete($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 // revert migration
echo ConsoleColor::log('Database: ', 'normal'); echo ConsoleColor::log('Database: ', 'normal');
if (file_exists($path . '/migrations')) { 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; return $this->active == $this::STATUS_DISABLED;
} }
public function isSystem(): bool
{
return $this->system == $this::SYSTEM_YES;
}
public static function find(): ModuleRecordQuery public static function find(): ModuleRecordQuery
{ {
return new ModuleRecordQuery(static::class); return new ModuleRecordQuery(static::class);

Loading…
Cancel
Save