"Fossies" - the Fresh Open Source Software Archive

Member "matomo/core/Updates/1.2-rc1.php" (3 Aug 2022, 7617 Bytes) of package /linux/www/matomo-4.11.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

A hint: This file contains one or more very long lines, so maybe it is better readable using the pure text view mode that shows the contents as wrapped lines within the browser window.


    1 <?php
    2 /**
    3  * Matomo - 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 
   10 namespace Piwik\Updates;
   11 
   12 use Piwik\Common;
   13 use Piwik\Updater;
   14 use Piwik\Updates;
   15 use Piwik\Updater\Migration\Factory as MigrationFactory;
   16 
   17 /**
   18  */
   19 class Updates_1_2_rc1 extends Updates
   20 {
   21     /**
   22      * @var MigrationFactory
   23      */
   24     private $migration;
   25 
   26     public function __construct(MigrationFactory $factory)
   27     {
   28         $this->migration = $factory;
   29     }
   30 
   31     public function getMigrations(Updater $updater)
   32     {
   33         $customVarType = 'VARCHAR(100) DEFAULT NULL';
   34         $customVarColumns = array(
   35             'custom_var_k1' => $customVarType,
   36             'custom_var_v1' => $customVarType,
   37             'custom_var_k2' => $customVarType,
   38             'custom_var_v2' => $customVarType,
   39             'custom_var_k3' => $customVarType,
   40             'custom_var_v3' => $customVarType,
   41             'custom_var_k4' => $customVarType,
   42             'custom_var_v4' => $customVarType,
   43             'custom_var_k5' => $customVarType,
   44             'custom_var_v5' => $customVarType,
   45         );
   46 
   47         return array(
   48             // Various performance improvements schema updates
   49             $this->migration->db->sql('ALTER TABLE `' . Common::prefixTable('log_visit') . '`
   50                 DROP `visit_server_date`,
   51                 DROP INDEX `index_idsite_date_config`,
   52                 DROP INDEX `index_idsite_datetime_config`,
   53                 ADD `idvisitor` BINARY(8) NOT NULL AFTER `idsite`,
   54                 ADD `config_id` BINARY(8) NOT NULL AFTER `config_md5config`
   55                ', array(Updater\Migration\Db::ERROR_CODE_UNKNOWN_COLUMN, Updater\Migration\Db::ERROR_CODE_COLUMN_NOT_EXISTS)),
   56             $this->migration->db->sql('ALTER TABLE `' . Common::prefixTable('log_visit') . '`
   57                 ADD `visit_entry_idaction_name` INT UNSIGNED NOT NULL AFTER `visit_entry_idaction_url`,
   58                 ADD `visit_exit_idaction_name` INT UNSIGNED NOT NULL AFTER `visit_exit_idaction_url`,
   59                 CHANGE `visit_exit_idaction_url` `visit_exit_idaction_url` INT UNSIGNED NOT NULL,
   60                 CHANGE `visit_entry_idaction_url` `visit_entry_idaction_url` INT UNSIGNED NOT NULL,
   61                 CHANGE `referer_type` `referer_type` TINYINT UNSIGNED NULL DEFAULT NULL,
   62                 ADD visitor_count_visits SMALLINT(5) UNSIGNED NOT NULL AFTER `visitor_returning`,
   63                 ADD visitor_days_since_last SMALLINT(5) UNSIGNED NOT NULL,
   64                 ADD visitor_days_since_first SMALLINT(5) UNSIGNED NOT NULL
   65                ', Updater\Migration\Db::ERROR_CODE_DUPLICATE_COLUMN),
   66 
   67             $this->migration->db->addColumns('log_visit', $customVarColumns),
   68 
   69             $this->migration->db->addColumns('log_link_visit_action', array(
   70                 'idsite' => 'INT( 10 ) UNSIGNED NOT NULL',
   71                 'idvisitor' => 'BINARY(8) NOT NULL',
   72                 'idaction_name_ref' => 'INT UNSIGNED NOT NULL'
   73             ), 'idlink_va'),
   74 
   75             $this->migration->db->addColumn('log_link_visit_action', 'server_time', 'DATETIME', 'idsite'),
   76             $this->migration->db->addIndex('log_link_visit_action', array('idsite', 'server_time'), 'index_idsite_servertime'),
   77             
   78             $this->migration->db->sql('ALTER TABLE `' . Common::prefixTable('log_conversion') . '`
   79                 DROP `referer_idvisit`,
   80                 ADD `idvisitor` BINARY(8) NOT NULL AFTER `idsite`
   81                ', array(Updater\Migration\Db::ERROR_CODE_DUPLICATE_COLUMN, Updater\Migration\Db::ERROR_CODE_COLUMN_NOT_EXISTS)),
   82             $this->migration->db->addColumns('log_conversion', array(
   83                 'visitor_count_visits' => 'SMALLINT(5) UNSIGNED NOT NULL',
   84                 'visitor_days_since_first' => 'SMALLINT(5) UNSIGNED NOT NULL',
   85             )),
   86             $this->migration->db->addColumns('log_conversion', $customVarColumns),
   87 
   88             // Migrate 128bits IDs inefficiently stored as 8bytes (256 bits) into 64bits
   89             $this->migration->db->sql('UPDATE ' . Common::prefixTable('log_visit') . '
   90                 SET idvisitor = binary(unhex(substring(visitor_idcookie,1,16))),
   91                     config_id = binary(unhex(substring(config_md5config,1,16)))
   92                    ', Updater\Migration\Db::ERROR_CODE_UNKNOWN_COLUMN),
   93             $this->migration->db->sql('UPDATE ' . Common::prefixTable('log_conversion') . '
   94                 SET idvisitor = binary(unhex(substring(visitor_idcookie,1,16)))
   95                    ', Updater\Migration\Db::ERROR_CODE_UNKNOWN_COLUMN),
   96 
   97             // Drop migrated fields
   98             $this->migration->db->sql('ALTER TABLE `' . Common::prefixTable('log_visit') . '`
   99                 DROP visitor_idcookie,
  100                 DROP config_md5config
  101                 ', Updater\Migration\Db::ERROR_CODE_COLUMN_NOT_EXISTS),
  102             $this->migration->db->sql('ALTER TABLE `' . Common::prefixTable('log_conversion') . '`
  103                 DROP visitor_idcookie
  104                 ', Updater\Migration\Db::ERROR_CODE_COLUMN_NOT_EXISTS),
  105 
  106             // Recreate INDEX on new field
  107             $this->migration->db->addIndex('log_visit', array('idsite', 'visit_last_action_time', 'config_id'), 'index_idsite_datetime_config'),
  108 
  109             // Backfill action logs as best as we can
  110             $this->migration->db->sql('UPDATE ' . Common::prefixTable('log_link_visit_action') . ' as action,
  111                       ' . Common::prefixTable('log_visit') . '  as visit
  112                 SET action.idsite = visit.idsite,
  113                     action.server_time = visit.visit_last_action_time,
  114                     action.idvisitor = visit.idvisitor
  115                 WHERE action.idvisit=visit.idvisit
  116                 '),
  117 
  118             $this->migration->db->changeColumnType('log_link_visit_action', 'server_time', 'DATETIME NOT NULL'),
  119 
  120             // New index used max once per request, in case this table grows significantly in the future
  121             $this->migration->db->addIndex('option', 'autoload', 'autoload'),
  122 
  123             // new field for websites
  124             $this->migration->db->addColumn('site', 'group', 'VARCHAR( 250 ) NOT NULL'),
  125         );
  126     }
  127 
  128     public function doUpdate(Updater $updater)
  129     {
  130         // first we disable the plugins and keep an array of warnings messages
  131         $pluginsToDisableMessage = array(
  132             'GeoIP'     => "GeoIP plugin was disabled, because it is not compatible with the new Piwik 1.2. \nYou can download the latest version of the plugin, compatible with Piwik 1.2.\n<a target='_blank' rel='noopener' href='https://github.com/matomo-org/matomo/issues/45'>Click here.</a>",
  133             'EntryPage' => "EntryPage plugin is not compatible with this version of Matomo, it was disabled.",
  134         );
  135         $disabledPlugins = array();
  136         foreach ($pluginsToDisableMessage as $pluginToDisable => $warningMessage) {
  137             if (\Piwik\Plugin\Manager::getInstance()->isPluginActivated($pluginToDisable)) {
  138                 \Piwik\Plugin\Manager::getInstance()->deactivatePlugin($pluginToDisable);
  139                 $disabledPlugins[] = $warningMessage;
  140             }
  141         }
  142 
  143         // Run the SQL
  144         $updater->executeMigrations(__FILE__, $this->getMigrations($updater));
  145 
  146         // Outputs warning message, pointing users to the plugin download page
  147         if (!empty($disabledPlugins)) {
  148             throw new \Exception("The following plugins were disabled during the upgrade:"
  149                 . "<ul><li>" .
  150                 implode('</li><li>', $disabledPlugins) .
  151                 "</li></ul>");
  152         }
  153     }
  154 }