Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Updates.php « core - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b458f70e773ad64460290f3b41d5e2cfa5f58a69 (plain)
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
/**
 * Piwik - free/libre analytics platform
 *
 * @link https://matomo.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 *
 */
namespace Piwik;
use Piwik\Updater\Migration;

/**
 * Base class for update scripts.
 *
 * Update scripts perform version updates for Piwik core or individual plugins. They can run
 * SQL queries and/or PHP code to update an environment to a newer version.
 *
 * To create a new update script, create a class that extends `Updates`. Name the class and file
 * after the version, eg, `class Updates_3_0_0` and `3.0.0.php`. Override the {@link getMigrationQueries()}
 * method if you need to run SQL queries. Override the {@link doUpdate()} method to do other types
 * of updating, eg, to activate/deactivate plugins or create files.
 *
 * If you define SQL queries in {@link getMigrationQueries()}, you have to call {@link Updater::executeMigrationQueries()},
 * eg:
 *
 *     public function doUpdate(Updater $updater)
 *     {
 *         $updater->executeMigrationQueries(__FILE__, $this->getMigrationQueries());
 *     }
 *
 * @example core/Updates/0.4.2.php
 */
abstract class Updates
{
    /**
     * @deprecated since v2.12.0 use getMigrationQueries() instead. Will be removed in Piwik 4.0.0
     */
    public static function getSql()
    {
        return array();
    }

    /**
     * @deprecated since v2.12.0 use doUpdate() instead. Will be removed in Piwik 4.0.0
     */
    public static function update()
    {
    }

    /**
     * Return migrations to be executed in this update.
     *
     * Migrations should be defined here, instead of in `doUpdate()`, since this method is used to display a preview
     * of which migrations and database queries an update will run. If you execute migrations directly in `doUpdate()`,
     * they won't be displayed to the user.
     *
     * @param Updater $updater
     * @return Migration[]
     * @api
     */
    public function getMigrations(Updater $updater)
    {
        return $this->getMigrationQueries($updater);
    }

    /**
     * Return SQL to be executed in this update.
     *
     * @param Updater $updater
     * @return array
     * @deprecated since Piwik 3.0.0, implement {@link getMigrations()} instead. Will be removed in Piwik 4.0.0
     */
    public function getMigrationQueries(Updater $updater)
    {
        return static::getSql();
    }

    /**
     * Perform the incremental version update.
     *
     * This method should preform all updating logic. If you define migrations in an overridden `getMigrations()`
     * method, you must call {@link Updater::executeMigrations()} here.
     *
     * See {@link \Piwik\Plugins\ExamplePlugin\Updates\Updates_0_0_2} for an example.
     *
     * @param Updater $updater
     * @api
     */
    public function doUpdate(Updater $updater)
    {
        static::update();
    }

    /**
     * Tell the updater that this is a major update.
     * Leads to a more visible notice.
     *
     * NOTE to release manager: Remember to mention in the Changelog
     * that this update contains major DB upgrades and will take some time!
     *
     * @return bool
     */
    public static function isMajorUpdate()
    {
        return false;
    }

    /**
     * Enables maintenance mode. Should be used for updates where Piwik will be unavailable
     * for a large amount of time.
     */
    public static function enableMaintenanceMode()
    {
        $config = Config::getInstance();

        $tracker = $config->Tracker;
        $tracker['record_statistics'] = 0;
        $config->Tracker = $tracker;

        $general = $config->General;
        $general['maintenance_mode'] = 1;
        $config->General = $general;

        $config->forceSave();
    }

    /**
     * Helper method to disable maintenance mode after large updates.
     */
    public static function disableMaintenanceMode()
    {
        $config = Config::getInstance();

        $tracker = $config->Tracker;
        $tracker['record_statistics'] = 1;
        $config->Tracker = $tracker;

        $general = $config->General;
        $general['maintenance_mode'] = 0;
        $config->General = $general;

        $config->forceSave();
    }

    public static function deletePluginFromConfigFile($pluginToDelete)
    {
        $config = Config::getInstance();
        if (isset($config->Plugins['Plugins'])) {
            $plugins = $config->Plugins['Plugins'];
            if (($key = array_search($pluginToDelete, $plugins)) !== false) {
                unset($plugins[$key]);
            }
            $config->Plugins['Plugins'] = $plugins;

            $pluginsInstalled = $config->PluginsInstalled['PluginsInstalled'];
            if (($key = array_search($pluginToDelete, $pluginsInstalled)) !== false) {
                unset($pluginsInstalled[$key]);
            }
            $config->PluginsInstalled = array('PluginsInstalled' => $pluginsInstalled);

            $config->forceSave();
        }
    }
}