Completed
Push — master ( cd9fc4...4b17a4 )
by André
23:37
created

ScriptHandler::clearCache()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 13
rs 9.4285
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\Event;
15
16
class ScriptHandler extends DistributionBundleScriptHandler
17
{
18
    /**
19
     * Clears the Symfony cache.
20
     *
21
     * Overloaded to clear project containers first before booting up Symfony container as part of clearCache() =>
22
     * cache:clear call. Since this will crash with RuntimeException if bundles have been removed or added when for
23
     * instance moving between git branches and running `composer install/update` afterwards.
24
     *
25
     * @param Event $event
26
     */
27
    public static function clearCache(Event $event)
28
    {
29
        $options = static::getOptions($event);
30
        $cacheDir = $options['symfony-app-dir'] . '/cache';
31
32
        // Take Symfony 3.0 directory structure into account if configured.
33
        if (isset($options['symfony-var-dir']) && is_dir($options['symfony-var-dir'])) {
34
            $cacheDir = $options['symfony-var-dir'] . '/cache';
35
        }
36
37
        array_map('unlink', glob($cacheDir . '/*/*ProjectContainer.php'));
38
        parent::clearCache($event);
39
    }
40
41
    /**
42
     * Dump minified assets for prod environment under the web root directory.
43
     *
44
     * @param $event Event A instance
45
     */
46
    public static function dumpAssets(Event $event)
47
    {
48
        $options = self::getOptions($event);
49
        $appDir = $options['symfony-app-dir'];
50
        $webDir = $options['symfony-web-dir'];
51
        $command = 'assetic:dump';
52
53
        // if not set falls back to default behaviour of console commands (using SYMFONY_ENV or fallback to 'dev')
54
        if (!empty($options['ezpublish-asset-dump-env'])) {
55
            $event->getIO()->write('<error>Use of `ezpublish-asset-dump-env` is deprecated, use SYMFONY_ENV to set anything other then dev for all commands</error>');
56
57
            if ($options['ezpublish-asset-dump-env'] === 'none') {
58
                // If asset dumping is skipped, output help text on how to generate it if needed
59
                return self::dumpAssetsHelpText($event);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Bundle\EzPublishCoreB...r::dumpAssetsHelpText() has been deprecated with message: Will be made private in the future for use by dumpAssets.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
60
            }
61
62
            $command .= ' --env=' . escapeshellarg($options['ezpublish-asset-dump-env']);
63
        }
64
65
        if (!is_dir($appDir)) {
66
            echo 'The symfony-app-dir (' . $appDir . ') specified in composer.json was not found in ' . getcwd() . ', can not install assets.' . PHP_EOL;
67
68
            return;
69
        }
70
71
        if (!is_dir($webDir)) {
72
            echo 'The symfony-web-dir (' . $webDir . ') specified in composer.json was not found in ' . getcwd() . ', can not install assets.' . PHP_EOL;
73
74
            return;
75
        }
76
77
        static::executeCommand($event, $appDir, $command . ' ' . escapeshellarg($webDir));
78
    }
79
80
    /**
81
     * Just dump help text on how to dump assets.
82
     *
83
     * Typically to use this instead on composer update as dump command uses prod environment where cache is not cleared,
84
     * causing it to sometimes crash when cache needs to be cleared.
85
     *
86
     * @deprecated Will be made private in the future for use by dumpAssets.
87
     * @param $event Event A instance
88
     */
89
    public static function dumpAssetsHelpText(Event $event)
90
    {
91
        $event->getIO()->write('<info>To dump eZ Publish production assets, which is needed for production environment, execute the following:</info>');
92
        $event->getIO()->write('    php app/console assetic:dump --env=prod web');
93
        $event->getIO()->write('');
94
    }
95
96
    /**
97
     * Just dump welcome text on how to install eZ Platform.
98
     *
99
     * @param $event Event A instance
100
     */
101
    public static function installWelcomeText(Event $event)
102
    {
103
        $event->getIO()->write(<<<'EOT'
104
105
      ________      ____    ___             __       ___         
106
     /\_____  \    /\  _`\ /\_ \           /\ \__  /'___\ 
107
   __\/____//'/'   \ \ \_\ \//\ \      __  \ \ ,_\/\ \__/  ___   _ __    ___ ___
108
 /'__`\   //'/'     \ \ ,__/ \ \ \   /'__`\ \ \ \/\ \ ,__\/ __`\/\`'__\/' __` __`\  
109
/\  __/  //'/'___    \ \ \/   \_\ \_/\ \L\.\_\ \ \_\ \ \_/\ \L\ \ \ \/ /\ \/\ \/\ \ 
110
\ \____\ /\_______\   \ \_\   /\____\ \__/.\_\\ \__\\ \_\\ \____/\ \_\ \ \_\ \_\ \_\
111
 \/____/ \/_______/    \/_/   \/____/\/__/\/_/ \/__/ \/_/ \/___/  \/_/  \/_/\/_/\/_/
112
113
114
<fg=cyan>Welcome to eZ Platform!</fg=cyan>
115
116
<options=bold>Quick Install:</>
117
(Assuming the CLI user you execute commands with below is same that extracted/installed the software)
118
<comment>    $  export SYMFONY_ENV="prod"</comment>
119
<comment>    $  php app/console ezplatform:install <type></comment>
120
<comment>    $  php app/console assetic:dump</comment>
121
<comment>    $  php app/console server:run</comment>
122
123
Note:
124
- "ezplatform:install" has different installer <type>s depending on your install, see <fg=green>INSTALL.md</> or <fg=green>README.md</> for which one to use.
125
- For development use you can enable full debugging by setting SYMFONY_ENV to "dev".
126
- Last command will give you url to frontend of installation, add "/ez" to reach backend.
127
128
For full install instructions, including setting up directory permissions, see install instructions in <fg=green>INSTALL.md</>
129
or <fg=green>README.md</>.
130
131
EOT
132
        );
133
    }
134
}
135