Completed
Push — asset_dump_sf_env ( 758bb0...2d4c20 )
by André
22:21
created

ScriptHandler::dumpAssets()   B

Complexity

Conditions 5
Paths 7

Size

Total Lines 33
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 33
rs 8.439
cc 5
eloc 17
nc 7
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
        $command = 'assetic:dump';
29
30
        // if not set falls back to default behaviour of console commands (using SYMFONY_ENV or fallback to 'dev')
31
        if (!empty($options['ezpublish-asset-dump-env'])) {
32
            $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>');
33
34
            if ($options['ezpublish-asset-dump-env'] === 'none') {
35
                // If asset dumping is skipped, output help text on how to generate it if needed
36
                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...
37
            }
38
39
            $command .= ' --env=' . escapeshellarg($options['ezpublish-asset-dump-env']);
40
        }
41
42
        if (!is_dir($appDir)) {
43
            echo 'The symfony-app-dir (' . $appDir . ') specified in composer.json was not found in ' . getcwd() . ', can not install assets.' . PHP_EOL;
44
45
            return;
46
        }
47
48
        if (!is_dir($webDir)) {
49
            echo 'The symfony-web-dir (' . $webDir . ') specified in composer.json was not found in ' . getcwd() . ', can not install assets.' . PHP_EOL;
50
51
            return;
52
        }
53
54
        static::executeCommand($event, $appDir, $command . ' ' . escapeshellarg($webDir));
55
    }
56
57
    /**
58
     * Just dump help text on how to dump assets.
59
     *
60
     * Typically to use this instead on composer update as dump command uses prod environment where cache is not cleared,
61
     * causing it to sometimes crash when cache needs to be cleared.
62
     *
63
     * @deprecated Will be made private in the future for use by dumpAssets.
64
     * @param $event CommandEvent A instance
65
     */
66
    public static function dumpAssetsHelpText(CommandEvent $event)
67
    {
68
        $event->getIO()->write('<info>To dump eZ Publish production assets, which is needed for production environment, execute the following:</info>');
69
        $event->getIO()->write('    php app/console assetic:dump --env=prod web');
70
        $event->getIO()->write('');
71
    }
72
73
    /**
74
     * Just dump welcome text on how to install eZ Platform.
75
     *
76
     * @param $event CommandEvent A instance
77
     */
78
    public static function installWelcomeText(CommandEvent $event)
79
    {
80
        $event->getIO()->write(<<<'EOT'
81
82
________________/\\\\\\\\\\\\\\\____________/\\\\\\\\\\\\\____/\\\\\\________________________________________/\\\\\_________________________________________________
83
 ________________\////////////\\\____________\/\\\/////////\\\_\////\\\______________________________________/\\\///__________________________________________________
84
  __________________________/\\\/_____________\/\\\_______\/\\\____\/\\\_______________________/\\\__________/\\\______________________________________________________
85
   _____/\\\\\\\\__________/\\\/_______________\/\\\\\\\\\\\\\/_____\/\\\_____/\\\\\\\\\_____/\\\\\\\\\\\__/\\\\\\\\\_______/\\\\\_____/\\/\\\\\\\_____/\\\\\__/\\\\\___
86
    ___/\\\/////\\\_______/\\\/_________________\/\\\/////////_______\/\\\____\////////\\\___\////\\\////__\////\\\//______/\\\///\\\__\/\\\/////\\\__/\\\///\\\\\///\\\_
87
     __/\\\\\\\\\\\______/\\\/___________________\/\\\________________\/\\\______/\\\\\\\\\\_____\/\\\_________\/\\\_______/\\\__\//\\\_\/\\\___\///__\/\\\_\//\\\__\/\\\_
88
      _\//\\///////_____/\\\/_____________________\/\\\________________\/\\\_____/\\\/////\\\_____\/\\\_/\\_____\/\\\______\//\\\__/\\\__\/\\\_________\/\\\__\/\\\__\/\\\_
89
       __\//\\\\\\\\\\__/\\\\\\\\\\\\\\\___________\/\\\______________/\\\\\\\\\_\//\\\\\\\\/\\____\//\\\\\______\/\\\_______\///\\\\\/___\/\\\_________\/\\\__\/\\\__\/\\\_
90
        ___\//////////__\///////////////____________\///______________\/////////___\////////\//______\/////_______\///__________\/////_____\///__________\///___\///___\///__
91
92
93
<fg=cyan>Welcome to eZ Platform!</fg=cyan>
94
95
<options=bold>Please read the INSTALL.md file to complete the installation.</options>
96
97
<options=bold>Assuming that your database information were correctly entered, you may install a clean database by running the install command:</options>
98
<comment>    $ php app/console --env=prod ezplatform:install clean</comment>
99
100
EOT
101
        );
102
    }
103
}
104