2015-04-25 03:57:40 +02:00
|
|
|
<?php namespace System\Console;
|
|
|
|
|
2015-05-02 12:29:22 +10:00
|
|
|
use Cms\Classes\Theme;
|
2015-04-25 03:57:40 +02:00
|
|
|
use Illuminate\Console\Command;
|
2015-05-02 12:29:22 +10:00
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
2015-04-25 03:57:40 +02:00
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
|
2017-03-16 17:08:20 +11:00
|
|
|
/**
|
|
|
|
* Console command to switch themes.
|
|
|
|
*
|
|
|
|
* This switches the active theme to another one, saved to the database.
|
|
|
|
*
|
|
|
|
* @package october\system
|
|
|
|
* @author Alexey Bobkov, Samuel Georges
|
|
|
|
*/
|
2015-04-25 03:57:40 +02:00
|
|
|
class ThemeUse extends Command
|
|
|
|
{
|
2015-05-02 12:29:22 +10:00
|
|
|
use \Illuminate\Console\ConfirmableTrait;
|
2015-04-25 03:57:40 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command name.
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $name = 'theme:use';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Switch the active theme.';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
* @return void
|
|
|
|
*/
|
2017-07-14 16:28:47 +10:00
|
|
|
public function handle()
|
2015-04-25 03:57:40 +02:00
|
|
|
{
|
2016-04-30 04:53:33 +10:00
|
|
|
if (!$this->confirmToProceed('Change the active theme?')) {
|
2015-04-25 03:57:40 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$newThemeName = $this->argument('name');
|
|
|
|
$newTheme = Theme::load($newThemeName);
|
|
|
|
|
|
|
|
if (!$newTheme->exists($newThemeName)) {
|
|
|
|
return $this->error(sprintf('The theme %s does not exist.', $newThemeName));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($newTheme->isActiveTheme()) {
|
|
|
|
return $this->error(sprintf('%s is already the active theme.', $newTheme->getId()));
|
|
|
|
}
|
|
|
|
|
|
|
|
$activeTheme = Theme::getActiveTheme();
|
|
|
|
$from = $activeTheme ? $activeTheme->getId() : 'nothing';
|
|
|
|
|
|
|
|
$this->info(sprintf('Switching theme from %s to %s', $from, $newTheme->getId()));
|
|
|
|
|
|
|
|
Theme::setActiveTheme($newThemeName);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the console command arguments.
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function getArguments()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
['name', InputArgument::REQUIRED, 'The name of the theme. (directory name)'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the console command options.
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function getOptions()
|
|
|
|
{
|
2015-05-02 12:29:22 +10:00
|
|
|
return [
|
|
|
|
['force', null, InputOption::VALUE_NONE, 'Force the operation to run.'],
|
|
|
|
];
|
2015-04-25 03:57:40 +02:00
|
|
|
}
|
|
|
|
}
|