Browse Source

Console ModuleController colored info for installation 2

master
Egorka 6 years ago
parent
commit
9e917cb4c1
  1. 8
      console/components/ConsoleColor.php
  2. 8
      console/controllers/ModuleController.php

8
console/components/ConsoleColor.php

@ -50,16 +50,14 @@ class ConsoleColor
public static $EOF = "\n";
/**
* Logs a string to console.
*
* @param string $str Input String
* @param string $color Text Color
* @param boolean $newline Append EOF?
* @param [type] $background Background Color
*
* Formatted output
* @return string
*/
public static function log($str = '', $color = 'normal', $newline = false, $background_color = null)
public static function log($str = '', $color = 'normal', $newline = false, $background_color = null): string
{
if (is_bool($color)) {
$newline = $color;
@ -69,7 +67,7 @@ class ConsoleColor
$newline = true;
}
$str = $newline ? $str . self::$EOF : $str;
echo self::$color($str, $background_color);
return self::$color($str, $background_color);
}
/**

8
console/controllers/ModuleController.php

@ -71,24 +71,32 @@ class ModuleController extends Controller
mkdir($path);
// git clone
chdir($path);
echo ConsoleColor::log('Git clone: ', 'normal');
shell_exec('git clone https://gitlab.com/zertex/zxcms-' . $name . '.git .');
echo ConsoleColor::log('complete', 'white') . PHP_EOL;
// get module manifest
$manifest = require \Yii::getAlias('@common/modules/' . $name . '/manifest.php');
// migration
echo ConsoleColor::log('Database: ', 'normal');
if (file_exists($path . '/migrations')) {
shell_exec('php ' . __DIR__ . '/yii migrate --migrationPath=' . $path . '/migrations --interactive=0');
}
echo ConsoleColor::log('complete', 'white') . PHP_EOL;
// add module record with active flag
$db_module = ModuleRecord::find()->andWhere(['name' => $name])->one();
if (!$db_module) {
$this->_service->create($name, 'common\\modules\\' . $name . '\\' . $manifest['vjlule'], 'common', 1);
}
// init permissions
echo ConsoleColor::log('Database: ', 'normal');
if (isset($manifest['permissions']) && is_array($manifest['permissions'])) {
$this->assignPermissions($manifest['permissions']);
}
echo ConsoleColor::log('complete', 'white') . PHP_EOL;
// regenerate cp global search
echo ConsoleColor::log('Search database: ', 'normal');
SearchPerformance::init();
echo ConsoleColor::log('complete', 'white') . PHP_EOL;
echo ConsoleColor::log('Module ' . $name . ' successfully installed', 'light_green') . PHP_EOL;
}

Loading…
Cancel
Save