/
InstallThemeCommand.php
57 lines (51 loc) · 1.91 KB
/
InstallThemeCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace Concrete\Core\Console\Command;
use Concrete\Core\Console\Command;
use Concrete\Core\Support\Facade\Application;
use Concrete\Core\Page\Theme\Theme;
use Loader;
use Exception;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class InstallThemeCommand extends Command
{
protected function configure()
{
$this->setName('c5:theme:install')
->addOption('activate', 'a', InputOption::VALUE_NONE, 'Activate this theme after install', null)
->setDescription('Install a Concrete Theme')
->setCanRunAsRoot(false)
->addArgument('theme-handle', null, InputOption::VALUE_REQUIRED, 'The handle name of the theme');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$rc = static::SUCCESS;
$theme = Theme::getByFileHandle($input->getArgument('theme-handle'));
$app = Application::getFacadeApplication();
$config = $app->make('config');
$v = Loader::helper('validation/error');
try {
if (is_object($theme)) {
$theme = Theme::add($input->getArgument('theme-handle'));
$output->writeln('<info>Theme Installed successfully!</info>');
if ($input->getOption('activate')) {
$theme->applyToSite();
}
} else {
throw new Exception('Invalid Theme');
}
} catch (Exception $e) {
switch ($e->getMessage()) {
case Theme::E_THEME_INSTALLED:
$output->writeln('That theme has already been installed.');
break;
default:
$output->writeln($e->getMessage());
$rc = static::FAILURE;
break;
}
}
return $rc;
}
}