FEATURE: prepare for installing templates
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Module;
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class SetTemplate extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'template:set {template}';
|
||||
/**
|
||||
* The console command description.
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Install template';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$template = $this->argument('template');
|
||||
|
||||
$templatePath = app_path('../templates/' . $template);
|
||||
if (!is_dir($templatePath) || !file_exists($templatePath . '/config.php')) {
|
||||
throw new NotFoundHttpException('Invalid template ' . $template . '!');
|
||||
}
|
||||
|
||||
// try to find currently installed template
|
||||
$current = Module::where('is_template', true)->first();
|
||||
|
||||
if ($current) {
|
||||
$this->line('Template is already set up. Currently using '.trans($current->name).'.');
|
||||
$confirm = $this->ask('Uninstall it and install '.$template.'? [y/n]');
|
||||
|
||||
if ($confirm === 'y') {
|
||||
$this->line('Uninstalling '.$current->name.'.');
|
||||
$current->uninstall();
|
||||
} else {
|
||||
$this->line('Aborting installation.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// install template
|
||||
$config = @include $templatePath . '/config.php';
|
||||
|
||||
try {
|
||||
$config['staticName'] = $template;
|
||||
Module::install($config['name'], $config['alias'], $config['description'], $config['handler'], false, $config);
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Cannot install template '.$template.'.');
|
||||
return;
|
||||
}
|
||||
|
||||
// theme written
|
||||
$this->line('Template successfully setup.');
|
||||
// $this->line('');
|
||||
// $this->line(' ** PUBLISHING ASSETS AND VIEWS **');
|
||||
// // publish assets and views for module and theme
|
||||
// $this->call('vendor:publish', ['--tag' => ['public-assets'], '--force' => true]);
|
||||
// $this->call('vendor:publish', ['--tag' => ['module-views'], '--force' => true]);
|
||||
// $this->call('vendor:publish');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user