|
|
|
@ -9,6 +9,7 @@ namespace console\controllers;
|
|
|
|
|
use console\components\ConsoleColor; |
|
|
|
|
use core\components\SearchPerformance; |
|
|
|
|
use core\entities\ModuleRecord; |
|
|
|
|
use core\helpers\FileHelper; |
|
|
|
|
use core\services\ModuleService; |
|
|
|
|
use core\services\PermissionManager; |
|
|
|
|
use yii\console\Controller; |
|
|
|
@ -61,7 +62,6 @@ class ModuleController extends Controller
|
|
|
|
|
public function actionInstall($name) |
|
|
|
|
{ |
|
|
|
|
$path = \Yii::getAlias('@common/modules/' . $name); |
|
|
|
|
|
|
|
|
|
echo ConsoleColor::log('Installing module: ', 'yellow') . ConsoleColor::log($name, 'white') . PHP_EOL; |
|
|
|
|
|
|
|
|
|
// check exists |
|
|
|
@ -85,7 +85,7 @@ class ModuleController extends Controller
|
|
|
|
|
// migration |
|
|
|
|
echo ConsoleColor::log('Database: ', 'normal'); |
|
|
|
|
if (file_exists($path . '/migrations')) { |
|
|
|
|
shell_exec('php ' . \Yii::getAlias('@yii') . '/yii migrate --migrationPath=' . $path . '/migrations --interactive=0'); |
|
|
|
|
shell_exec('php ' . __DIR__ . '/../../yii migrate --migrationPath=' . $path . '/migrations --interactive=0'); |
|
|
|
|
} |
|
|
|
|
echo ConsoleColor::log('complete', 'white') . PHP_EOL; |
|
|
|
|
|
|
|
|
@ -110,6 +110,44 @@ class ModuleController extends Controller
|
|
|
|
|
echo ConsoleColor::log('Module ' . $name . ' successfully installed', 'light_green') . PHP_EOL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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) { |
|
|
|
|
$this->_service->delete($db_module); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// revert migration |
|
|
|
|
echo ConsoleColor::log('Database: ', 'normal'); |
|
|
|
|
if (file_exists($path . '/migrations')) { |
|
|
|
|
shell_exec('php ' . __DIR__ . '/../../yii migrate/down 500 --migrationPath=' . $path . '/migrations --interactive=0'); |
|
|
|
|
} |
|
|
|
|
echo ConsoleColor::log('clean', 'white') . PHP_EOL; |
|
|
|
|
|
|
|
|
|
// check exists, remove if founded |
|
|
|
|
echo ConsoleColor::log('Module files: ', 'normal'); |
|
|
|
|
if (file_exists($path)) { |
|
|
|
|
FileHelper::removeDirectory($path); |
|
|
|
|
} |
|
|
|
|
echo ConsoleColor::log('clean', 'white') . PHP_EOL; |
|
|
|
|
|
|
|
|
|
// drop permissions |
|
|
|
|
echo ConsoleColor::log('Permissions: ', 'normal'); |
|
|
|
|
if (isset($manifest['permissions']) && is_array($manifest['permissions'])) { |
|
|
|
|
$this->removePermissions($manifest['permissions']); |
|
|
|
|
} |
|
|
|
|
echo ConsoleColor::log('clean', 'white') . PHP_EOL; |
|
|
|
|
|
|
|
|
|
echo ConsoleColor::log('Module ' . $name . ' successfully deleted', 'light_green') . PHP_EOL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private function assignPermissions(array $permissions): void |
|
|
|
|
{ |
|
|
|
|
foreach ($permissions as $permission => $description) { |
|
|
|
@ -118,4 +156,13 @@ class ModuleController extends Controller
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private function removePermissions(array $permissions) |
|
|
|
|
{ |
|
|
|
|
foreach ($permissions as $permission => $description) { |
|
|
|
|
if ($this->_permission_manager->permissionExists($permission)) { |
|
|
|
|
$this->_permission_manager->delete($permission); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|