-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathPluginRegisterCommand.php
More file actions
77 lines (60 loc) · 2.97 KB
/
PluginRegisterCommand.php
File metadata and controls
77 lines (60 loc) · 2.97 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
namespace Codeages\PluginBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Codeages\PluginBundle\System\PluginRegister;
use AppBundle\Common\BlockToolkit;
class PluginRegisterCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('plugin:register')
->addArgument('code', InputArgument::REQUIRED, 'Plugin code.')
->addOption('without-database', null, InputOption::VALUE_NONE, 'create database?')
->setDescription('Register plugin.');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$biz = $this->getContainer()->get('biz');
$code = $input->getArgument('code');
$withoutDatabase = $input->getOption('without-database');
$output->writeln(sprintf('Register plugin <comment>%s</comment> :', $code));
$rootDir = dirname($this->getContainer()->getParameter('kernel.root_dir'));
$installer = new PluginRegister($rootDir, 'plugins', $biz);
if ($installer->isPluginRegisted($code)) {
throw new \RuntimeException('Plugin is already registed.');
}
$output->write(' - Parse meta file plugin.json');
$metas = $installer->parseMetas($code);
$output->writeln(' <info>[Ok]</info>');
if (!$withoutDatabase) {
$output->write(' - Execute create database scripts.');
$executed = $installer->executeDatabaseScript($code);
$output->writeln($executed ? ' <info>[Ok]</info>' : ' <info>[Ignore]</info>');
}
$output->write(' - Execute install script.');
$executed = $installer->executeScript($code);
$output->writeln($executed ? ' <info>[Ok]</info>' : ' <info>[Ignore]</info>');
$output->write(' - Install assets.');
$content = $installer->installAssets($code);
$output->writeln(' <info>[Ok]</info>');
$output->writeln($content);
$output->write(' - Install block.');
BlockToolkit::init($installer->getPluginDirectory($code).'/block.json', $this->getContainer());
$output->writeln(' <info>[Ok]</info>');
$output->write(' - Create plugin installed record.');
$app = $installer->registerPlugin($code);
$output->writeln($app ? ' <info>[Ok]</info>' : ' <info>[Ignore]</info>');
$output->write(' - Refresh plugin cache.');
$installer->refreshInstalledPluginConfiguration();
$output->writeln($executed ? ' <info>[Ok]</info>' : ' <info>[Ignore]</info>');
$output->write(' - Refresh default roles.');
$installer->refreshDefaultRoles();
$output->writeln(' <info>[Ok]</info>');
$output->writeln("<info>Finished!</info>\n");
}
}