revolution /setup/includes/runner/modinstallrunnerweb.class.php

Language PHP Lines 147
MD5 Hash 31b111ddc63abb19325bc28aa3fc8183 Estimated Cost $2,408 (why?)
Repository git://github.com/modxcms/revolution.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
require_once strtr(realpath(MODX_SETUP_PATH.'includes/runner/modinstallrunner.class.php'),'\\','/');
/**
 * @package modx
 * @subpackage setup
 */
class modInstallRunnerWeb extends modInstallRunner {

    public function initialize() {
        /* set the time limit infinite in case it takes a bit
         * TODO: fix this by allowing resume when it takes a long time
         */
        @ set_time_limit(0);
    }
    /**
     * Execute the installation process.
     *
     * @param integer $mode The install mode.
     * @return array An array of result messages collected during execution.
     */
    public function execute($mode) {
        /* write config file */
        $this->writeConfig();

        /* get connection */
        $this->install->getConnection($mode);

        /* run appropriate database routines */
        switch ($mode) {
            case modInstall::MODE_UPGRADE_REVO :
            case modInstall::MODE_UPGRADE_REVO_ADVANCED :
                $this->loadVersionInstaller();
                $this->versioner->install();
                break;
                /* new install, create tables */
            default :
                $modx =& $this->install->xpdo;
                $install =& $this->install;
                include MODX_SETUP_PATH . 'includes/tables_create.php';
                break;
        }

        if ($this->install->xpdo) {
            if (!$this->installPackage()) {
                return $this->getResults();
            }

            $this->updateWorkspace();

            $modx =& $this->install->xpdo;
            $settings =& $this->install->settings;
            $install =& $this->install;

            /* if new install */
            if ($mode == modInstall::MODE_NEW) {
                include MODX_SETUP_PATH.'includes/new.install.php';

            /* if upgrade */
            } else {
                include MODX_SETUP_PATH.'includes/upgrade.install.php';
            }

            $this->postRun();

            $this->success = true;
        }

        return $this->getResults();
    }

    /**
     * Do post-run cleanups
     * @return void
     */
    public function cleanup() {
        /* empty sessions table to prevent old permissions from loading */
        $tableName = $this->install->xpdo->getTableName('modSession');
        $this->install->xpdo->exec($this->install->driver->truncate($tableName));

        /* clear cache */
        $this->install->xpdo->cacheManager->deleteTree(MODX_CORE_PATH.'cache/',array(
            'skipDirs' => false,
            'extensions' => array(
                '.cache.php',
                '.tpl.php',
            ),
        ));

        $this->install->settings->store(array(
            'finished' => true,
        ));
    }

    public function postRun() {
        $compressJs = $this->install->settings->get('compress_js');
        if ($compressJs === 0) {
            /** @var modSystemSetting $setting */
            $setting = $this->install->xpdo->getObject('modSystemSetting',array(
                'key' => 'compress_js',
            ));
            if (empty($setting)) {
                $setting = $this->install->xpdo->newObject('modSystemSetting');
                $setting->fromArray(array(
                    'key' => 'compress_js',
                    'xtype' => 'combo-boolean',
                    'namespace' => 'core',
                    'area' => 'manager',
                ),'',true);
            }
            $setting->set('value',0);
            $setting->save();
        }
        $compressCss = $this->install->settings->get('compress_css');
        if ($compressCss === 0) {
            /** @var modSystemSetting $setting */
            $setting = $this->install->xpdo->getObject('modSystemSetting',array(
                'key' => 'compress_css',
            ));
            if (empty($setting)) {
                $setting = $this->install->xpdo->newObject('modSystemSetting');
                $setting->fromArray(array(
                    'key' => 'compress_css',
                    'xtype' => 'combo-boolean',
                    'namespace' => 'core',
                    'area' => 'manager',
                ),'',true);
            }
            $setting->set('value',0);
            $setting->save();
        }

        // If the user opted in to send the powered by header, enable the setting here
        // The setting is installed disabled by default, so we don't have to force it off if unchecked
        $sendPoweredByHeader = $this->install->settings->get('send_poweredby_header');
        if (!empty($sendPoweredByHeader)) {
            $setting = $this->install->xpdo->getObject('modSystemSetting',array(
                'key' => 'send_poweredby_header',
            ));
            if ($setting instanceof modSystemSetting) {
                $setting->set('value', 1);
                $setting->save();
            }
        }
        return true;
    }
}
Back to Top