DOCUMENTATION: add documentantion for installation commands
This commit is contained in:
@@ -3,7 +3,6 @@
|
|||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Facades\Artisan;
|
|
||||||
use Illuminate\Support\Facades\File;
|
use Illuminate\Support\Facades\File;
|
||||||
|
|
||||||
class InstallAllModules extends Command
|
class InstallAllModules extends Command
|
||||||
@@ -38,11 +37,13 @@ class InstallAllModules extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
// crawl all subdirectories in modules path
|
||||||
$modules = File::directories(config('modules.paths.modules'));
|
$modules = File::directories(config('modules.paths.modules'));
|
||||||
|
|
||||||
foreach ($modules as $module) {
|
foreach ($modules as $module) {
|
||||||
$moduleName = basename($module);
|
$moduleName = basename($module);
|
||||||
|
|
||||||
|
// try to install each module
|
||||||
try {
|
try {
|
||||||
$this->call('install-module', ['name' => $moduleName]);
|
$this->call('install-module', ['name' => $moduleName]);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|||||||
@@ -42,23 +42,32 @@ class InstallModule extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$name = $this->argument('name');
|
$this->moduleName = $name = $this->argument('name');
|
||||||
$this->moduleName = $name;
|
|
||||||
|
|
||||||
|
// invalid module name provided
|
||||||
if (!is_dir($this->modulesPath . DIRECTORY_SEPARATOR . $name)) {
|
if (!is_dir($this->modulesPath . DIRECTORY_SEPARATOR . $name)) {
|
||||||
throw new InvalidArgumentException('Invalid module ' . $name . '. No directory under ' . $this->modulesPath . DIRECTORY_SEPARATOR . $name . ' found!');
|
throw new InvalidArgumentException('Invalid module ' . $name . '. No directory under ' . $this->modulesPath . DIRECTORY_SEPARATOR . $name . ' found!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get config
|
||||||
$config = $this->loadConfig();
|
$config = $this->loadConfig();
|
||||||
|
|
||||||
|
// check if it is valid
|
||||||
$this->checkMandatoryFields($config);
|
$this->checkMandatoryFields($config);
|
||||||
|
|
||||||
// all mandatory fields are present, we can write it into database and create modules.json
|
// all mandatory fields are present, we can write it into database and create modules.json
|
||||||
$this->installModule($config);
|
$this->installModule($config);
|
||||||
|
|
||||||
|
// inform user
|
||||||
$this->line('Module ' . $name . ' successfuly installed');
|
$this->line('Module ' . $name . ' successfuly installed');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load config from Config/config.php in module files. We cannot use config() because the file have not published
|
||||||
|
* yet.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
private function loadConfig()
|
private function loadConfig()
|
||||||
{
|
{
|
||||||
// we cannot rely on config() helper, because this module does not have to be published
|
// we cannot rely on config() helper, because this module does not have to be published
|
||||||
@@ -67,6 +76,11 @@ class InstallModule extends Command
|
|||||||
return $config;
|
return $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if config contains all mandatory entries.
|
||||||
|
*
|
||||||
|
* @param $config
|
||||||
|
*/
|
||||||
private function checkMandatoryFields($config)
|
private function checkMandatoryFields($config)
|
||||||
{
|
{
|
||||||
$fields = ['providers', 'handler', 'name', 'files', 'alias'];
|
$fields = ['providers', 'handler', 'name', 'files', 'alias'];
|
||||||
@@ -77,6 +91,18 @@ class InstallModule extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Installs module into database.
|
||||||
|
*
|
||||||
|
* This method calls Module::install, which handles specific installation of module. In this way we should be able
|
||||||
|
* to install any module even with some other database structures.
|
||||||
|
*
|
||||||
|
* @param $config
|
||||||
|
*
|
||||||
|
* @return Module
|
||||||
|
* @throws \ErrorException
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
private function installModule($config)
|
private function installModule($config)
|
||||||
{
|
{
|
||||||
$name = isset($config['translatedName']) ? $config['translatedName'] : $config['name'];
|
$name = isset($config['translatedName']) ? $config['translatedName'] : $config['name'];
|
||||||
|
|||||||
Reference in New Issue
Block a user