Completed
Push — tmp_sql_installer ( 5116d2 )
by André
26:50
created

ScriptHandler::installWelcomeText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 13
rs 9.4286
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
/**
4
 * File containing the ScriptHandler class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 *
9
 * @version //autogentag//
10
 */
11
namespace eZ\Bundle\EzPublishCoreBundle\Composer;
12
13
use Sensio\Bundle\DistributionBundle\Composer\ScriptHandler as DistributionBundleScriptHandler;
14
use Composer\Script\CommandEvent;
15
16
class ScriptHandler extends DistributionBundleScriptHandler
17
{
18
    /**
19
     * Dump minified assets for prod environment under the web root directory.
20
     *
21
     * @param $event CommandEvent A instance
22
     */
23
    public static function dumpAssets(CommandEvent $event)
24
    {
25
        $options = self::getOptions($event);
26
        $appDir = $options['symfony-app-dir'];
27
        $webDir = $options['symfony-web-dir'];
28
        $env = isset($options['ezpublish-asset-dump-env']) ? $options['ezpublish-asset-dump-env'] : '';
29
30
        if (!$env) {
31
            $env = $event->getIO()->ask(
32
                "<question>Which environment would you like to dump production assets for?</question> (Default: 'prod', type 'none' to skip) ",
33
                'prod'
34
            );
35
        }
36
37
        if ($env === 'none') {
38
            return;
39
        }
40
41
        if (!is_dir($appDir)) {
42
            echo 'The symfony-app-dir (' . $appDir . ') specified in composer.json was not found in ' . getcwd() . ', can not install assets.' . PHP_EOL;
43
44
            return;
45
        }
46
47
        if (!is_dir($webDir)) {
48
            echo 'The symfony-web-dir (' . $webDir . ') specified in composer.json was not found in ' . getcwd() . ', can not install assets.' . PHP_EOL;
49
50
            return;
51
        }
52
53
        static::executeCommand($event, $appDir, 'assetic:dump --env=' . escapeshellarg($env) . ' ' . escapeshellarg($webDir));
54
    }
55
56
    /**
57
     * Just dump help text on how to dump assets.
58
     *
59
     * Typically to use this instead on composer update as dump command uses prod environment where cache is not cleared,
60
     * causing it to sometimes crash when cache needs to be cleared.
61
     *
62
     * @param $event CommandEvent A instance
63
     */
64
    public static function dumpAssetsHelpText(CommandEvent $event)
65
    {
66
        $event->getIO()->write('<info>To dump eZ Publish production assets, execute the following:</info>');
67
        $event->getIO()->write('    php app/console assetic:dump --env=prod web');
68
        $event->getIO()->write('');
69
    }
70
71
    /**
72
     * Just dump welcome text on how to install eZ Platform.
73
     *
74
     * @param $event CommandEvent A instance
75
     */
76
    public static function installWelcomeText(CommandEvent $event)
77
    {
78
        $event->getIO()->write(<<<'EOT'
79
<fg=cyan>Welcome to eZ Platform!</fg=cyan>
80
81
<options=bold>Please read the INSTALL.md file to complete the installation.</options>
82
83
<options=bold>Assuming that your database information were correctly entered, you may install a clean database by running the install command:</options>
84
<comment>    $ php app/console --env=prod ezplatform:install clean</comment>
85
86
EOT
87
        );
88
    }
89
}
90