API
6 years ago
Access
6 years ago
Application
6 years ago
Archive
6 years ago
ArchiveProcessor
6 years ago
Archiver
6 years ago
AssetManager
6 years ago
Auth
6 years ago
Category
6 years ago
CliMulti
6 years ago
Columns
6 years ago
Composer
6 years ago
Concurrency
6 years ago
Config
6 years ago
Container
6 years ago
CronArchive
6 years ago
DataAccess
5 years ago
DataFiles
6 years ago
DataTable
6 years ago
Db
6 years ago
DeviceDetector
5 years ago
Email
6 years ago
Exception
6 years ago
Http
6 years ago
Intl
6 years ago
Mail
6 years ago
Measurable
6 years ago
Menu
6 years ago
Metrics
6 years ago
Notification
6 years ago
Period
6 years ago
Plugin
6 years ago
ProfessionalServices
6 years ago
Report
6 years ago
ReportRenderer
6 years ago
Scheduler
6 years ago
Segment
6 years ago
Session
6 years ago
Settings
6 years ago
Tracker
5 years ago
Translation
6 years ago
UpdateCheck
6 years ago
Updater
6 years ago
Updates
6 years ago
Validators
6 years ago
View
6 years ago
ViewDataTable
6 years ago
Visualization
6 years ago
Widget
6 years ago
.htaccess
6 years ago
Access.php
6 years ago
Archive.php
6 years ago
ArchiveProcessor.php
6 years ago
AssetManager.php
6 years ago
Auth.php
6 years ago
BaseFactory.php
6 years ago
Cache.php
6 years ago
CacheId.php
6 years ago
CliMulti.php
6 years ago
Common.php
6 years ago
Config.php
6 years ago
Console.php
6 years ago
Context.php
6 years ago
Cookie.php
5 years ago
CronArchive.php
5 years ago
DataArray.php
6 years ago
DataTable.php
6 years ago
Date.php
6 years ago
Db.php
6 years ago
DbHelper.php
6 years ago
Development.php
6 years ago
DeviceDetectorFactory.php
6 years ago
ErrorHandler.php
6 years ago
EventDispatcher.php
6 years ago
ExceptionHandler.php
6 years ago
FileIntegrity.php
6 years ago
Filechecks.php
6 years ago
Filesystem.php
6 years ago
FrontController.php
6 years ago
Http.php
6 years ago
IP.php
6 years ago
Log.php
6 years ago
LogDeleter.php
6 years ago
Mail.php
6 years ago
Metrics.php
6 years ago
MetricsFormatter.php
6 years ago
Nonce.php
5 years ago
Notification.php
6 years ago
NumberFormatter.php
6 years ago
Option.php
5 years ago
Period.php
6 years ago
Piwik.php
6 years ago
Plugin.php
6 years ago
Profiler.php
6 years ago
ProxyHeaders.php
6 years ago
ProxyHttp.php
6 years ago
QuickForm2.php
6 years ago
RankingQuery.php
6 years ago
Registry.php
6 years ago
ReportRenderer.php
6 years ago
ScheduledTask.php
6 years ago
Segment.php
6 years ago
Sequence.php
6 years ago
Session.php
6 years ago
SettingsPiwik.php
6 years ago
SettingsServer.php
6 years ago
Singleton.php
6 years ago
Site.php
6 years ago
TCPDF.php
6 years ago
TaskScheduler.php
6 years ago
Theme.php
6 years ago
Timer.php
6 years ago
Tracker.php
6 years ago
Translate.php
6 years ago
Twig.php
6 years ago
Unzip.php
6 years ago
UpdateCheck.php
6 years ago
Updater.php
6 years ago
Updates.php
6 years ago
Url.php
6 years ago
UrlHelper.php
6 years ago
Version.php
5 years ago
View.php
6 years ago
bootstrap.php
6 years ago
dispatch.php
6 years ago
testMinimumPhpVersion.php
6 years ago
Updates.php
165 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Piwik - free/libre analytics platform |
| 4 | * |
| 5 | * @link https://matomo.org |
| 6 | * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 7 | * |
| 8 | */ |
| 9 | namespace Piwik; |
| 10 | use Piwik\Updater\Migration; |
| 11 | |
| 12 | /** |
| 13 | * Base class for update scripts. |
| 14 | * |
| 15 | * Update scripts perform version updates for Piwik core or individual plugins. They can run |
| 16 | * SQL queries and/or PHP code to update an environment to a newer version. |
| 17 | * |
| 18 | * To create a new update script, create a class that extends `Updates`. Name the class and file |
| 19 | * after the version, eg, `class Updates_3_0_0` and `3.0.0.php`. Override the {@link getMigrationQueries()} |
| 20 | * method if you need to run SQL queries. Override the {@link doUpdate()} method to do other types |
| 21 | * of updating, eg, to activate/deactivate plugins or create files. |
| 22 | * |
| 23 | * If you define SQL queries in {@link getMigrationQueries()}, you have to call {@link Updater::executeMigrationQueries()}, |
| 24 | * eg: |
| 25 | * |
| 26 | * public function doUpdate(Updater $updater) |
| 27 | * { |
| 28 | * $updater->executeMigrationQueries(__FILE__, $this->getMigrationQueries()); |
| 29 | * } |
| 30 | * |
| 31 | * @example core/Updates/0.4.2.php |
| 32 | */ |
| 33 | abstract class Updates |
| 34 | { |
| 35 | /** |
| 36 | * @deprecated since v2.12.0 use getMigrationQueries() instead. Will be removed in Piwik 4.0.0 |
| 37 | */ |
| 38 | public static function getSql() |
| 39 | { |
| 40 | return array(); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * @deprecated since v2.12.0 use doUpdate() instead. Will be removed in Piwik 4.0.0 |
| 45 | */ |
| 46 | public static function update() |
| 47 | { |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Return migrations to be executed in this update. |
| 52 | * |
| 53 | * Migrations should be defined here, instead of in `doUpdate()`, since this method is used to display a preview |
| 54 | * of which migrations and database queries an update will run. If you execute migrations directly in `doUpdate()`, |
| 55 | * they won't be displayed to the user. |
| 56 | * |
| 57 | * @param Updater $updater |
| 58 | * @return Migration[] |
| 59 | * @api |
| 60 | */ |
| 61 | public function getMigrations(Updater $updater) |
| 62 | { |
| 63 | return $this->getMigrationQueries($updater); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Return SQL to be executed in this update. |
| 68 | * |
| 69 | * @param Updater $updater |
| 70 | * @return array |
| 71 | * @deprecated since Piwik 3.0.0, implement {@link getMigrations()} instead. Will be removed in Piwik 4.0.0 |
| 72 | */ |
| 73 | public function getMigrationQueries(Updater $updater) |
| 74 | { |
| 75 | return static::getSql(); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Perform the incremental version update. |
| 80 | * |
| 81 | * This method should preform all updating logic. If you define migrations in an overridden `getMigrations()` |
| 82 | * method, you must call {@link Updater::executeMigrations()} here. |
| 83 | * |
| 84 | * See {@link \Piwik\Plugins\ExamplePlugin\Updates\Updates_0_0_2} for an example. |
| 85 | * |
| 86 | * @param Updater $updater |
| 87 | * @api |
| 88 | */ |
| 89 | public function doUpdate(Updater $updater) |
| 90 | { |
| 91 | static::update(); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Tell the updater that this is a major update. |
| 96 | * Leads to a more visible notice. |
| 97 | * |
| 98 | * NOTE to release manager: Remember to mention in the Changelog |
| 99 | * that this update contains major DB upgrades and will take some time! |
| 100 | * |
| 101 | * @return bool |
| 102 | */ |
| 103 | public static function isMajorUpdate() |
| 104 | { |
| 105 | return false; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Enables maintenance mode. Should be used for updates where Piwik will be unavailable |
| 110 | * for a large amount of time. |
| 111 | */ |
| 112 | public static function enableMaintenanceMode() |
| 113 | { |
| 114 | $config = Config::getInstance(); |
| 115 | |
| 116 | $tracker = $config->Tracker; |
| 117 | $tracker['record_statistics'] = 0; |
| 118 | $config->Tracker = $tracker; |
| 119 | |
| 120 | $general = $config->General; |
| 121 | $general['maintenance_mode'] = 1; |
| 122 | $config->General = $general; |
| 123 | |
| 124 | $config->forceSave(); |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Helper method to disable maintenance mode after large updates. |
| 129 | */ |
| 130 | public static function disableMaintenanceMode() |
| 131 | { |
| 132 | $config = Config::getInstance(); |
| 133 | |
| 134 | $tracker = $config->Tracker; |
| 135 | $tracker['record_statistics'] = 1; |
| 136 | $config->Tracker = $tracker; |
| 137 | |
| 138 | $general = $config->General; |
| 139 | $general['maintenance_mode'] = 0; |
| 140 | $config->General = $general; |
| 141 | |
| 142 | $config->forceSave(); |
| 143 | } |
| 144 | |
| 145 | public static function deletePluginFromConfigFile($pluginToDelete) |
| 146 | { |
| 147 | $config = Config::getInstance(); |
| 148 | if (isset($config->Plugins['Plugins'])) { |
| 149 | $plugins = $config->Plugins['Plugins']; |
| 150 | if (($key = array_search($pluginToDelete, $plugins)) !== false) { |
| 151 | unset($plugins[$key]); |
| 152 | } |
| 153 | $config->Plugins['Plugins'] = $plugins; |
| 154 | |
| 155 | $pluginsInstalled = $config->PluginsInstalled['PluginsInstalled']; |
| 156 | if (($key = array_search($pluginToDelete, $pluginsInstalled)) !== false) { |
| 157 | unset($pluginsInstalled[$key]); |
| 158 | } |
| 159 | $config->PluginsInstalled = array('PluginsInstalled' => $pluginsInstalled); |
| 160 | |
| 161 | $config->forceSave(); |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 |