1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Knowledge Base package. |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2015 LIN3S <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace LIN3S\KnowledgeBaseBundle\Command; |
13
|
|
|
|
14
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
15
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
17
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Assets command class. |
21
|
|
|
* |
22
|
|
|
* @author Gorka Laucirica <[email protected]> |
23
|
|
|
* @author Beñat Espiña <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class AssetCommand extends ContainerAwareCommand |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* {@inheritdoc} |
29
|
|
|
*/ |
30
|
|
|
protected function configure() |
31
|
|
|
{ |
32
|
|
|
$this |
33
|
|
|
->setName('lin3s:kb:assets:install') |
34
|
|
|
->setDescription('Generates the symlink of assets that are located into Template\'s path'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {@inheritdoc} |
39
|
|
|
*/ |
40
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
41
|
|
|
{ |
42
|
|
|
$config = $this->getContainer()->get('lin3s_knowledge_base.configuration'); |
43
|
|
|
$rootDir = $this->getContainer()->get('kernel')->getRootDir(); |
44
|
|
|
$template = $config->template(); |
45
|
|
|
|
46
|
|
|
$targetDirectory = $rootDir . '/../web/' . $config->assetsBaseUrl() . '/' . $template->name(); |
47
|
|
|
|
48
|
|
|
$fileSystem = new Filesystem(); |
49
|
|
|
|
50
|
|
|
try { |
51
|
|
|
if ($fileSystem->exists($targetDirectory)) { |
52
|
|
|
return; |
53
|
|
|
} |
54
|
|
|
$fileSystem->symlink($template->assetsPath(), $targetDirectory, true); |
55
|
|
|
$output->writeln(sprintf('<fg=green>%s</fg=green>', 'The symlink is successfully completed')); |
56
|
|
|
} catch (\Exception $exception) { |
57
|
|
|
$output->writeln( |
58
|
|
|
sprintf( |
59
|
|
|
"<fg=red>%s \n%s\n</fg=red>", |
60
|
|
|
'Something wrong happens during the symlink process:', |
61
|
|
|
$exception->getMessage() |
62
|
|
|
) |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|