Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
CompileLightncandy
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 3
90
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
30
 compile
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3namespace Flow\Maintenance;
4
5use Flow\TemplateHelper;
6use Maintenance;
7
8$IP = getenv( 'MW_INSTALL_PATH' );
9if ( $IP === false ) {
10    $IP = __DIR__ . '/../../..';
11}
12
13require_once "$IP/maintenance/Maintenance.php";
14
15/**
16 * Populate the *_user_ip fields within flow.  This only updates
17 * the database and not the cache.  The model loading layer handles
18 * cached old values.
19 *
20 * @ingroup Maintenance
21 */
22class CompileLightncandy extends Maintenance {
23    /** @var TemplateHelper */
24    protected $lightncandy;
25
26    public function __construct() {
27        parent::__construct();
28
29        $this->requireExtension( 'Flow' );
30    }
31
32    public function execute() {
33        $dir = __DIR__ . '/../handlebars';
34        $this->lightncandy = new TemplateHelper( $dir, /* $forceRecompile = */ true );
35
36        // looking for 664 permissions on the final files
37        umask( 0002 );
38
39        // clean out the compiled directory
40        foreach ( glob( $dir . '/compiled/*' ) as $file ) {
41            if ( !unlink( $file ) ) {
42                $this->error( "Failed to unlink previously compiled code: $file" );
43            }
44        }
45
46        // compile all non-partials
47        $skipPrefix = '.partial.handlebars';
48        $len = strlen( $skipPrefix );
49        foreach ( glob( $dir . '/*.handlebars' ) as $file ) {
50            if ( substr( $file, -$len ) !== $skipPrefix ) {
51                $this->compile( basename( $file, '.handlebars' ) );
52            }
53        }
54        $this->output( "\n" );
55    }
56
57    protected function compile( $templateName ) {
58        $filenames = $this->lightncandy->getTemplateFilenames( $templateName );
59
60        if ( !file_exists( $filenames['template'] ) ) {
61            $this->error( "Could not find template at: {$filenames['template']}" );
62        }
63
64        $this->lightncandy->getTemplate( $templateName );
65        if ( !file_exists( $filenames['compiled'] ) ) {
66            $this->error( "Template compilation completed, but no compiled code found on disk" );
67        } else {
68            $this->output( "Successfully compiled $templateName to {$filenames['compiled']}\n" );
69        }
70    }
71}
72
73$maintClass = CompileLightncandy::class;
74require_once RUN_MAINTENANCE_IF_MAIN;