"Fossies" - the Fresh Open Source Software Archive

Member "matomo/core/Updates/1.4-rc2.php" (3 Aug 2022, 1998 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.

    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_4_rc2 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         $errorCodeDbNotExists = Updater\Migration\Db::ERROR_CODE_TABLE_NOT_EXISTS;
   34 
   35         return array(
   36             $this->migration->db->sql("SET sql_mode=''"),
   37             // this converts the 32-bit UNSIGNED INT column to a 16 byte VARBINARY;
   38             // _but_ MySQL does string conversion! (e.g., integer 1 is converted to 49 -- the ASCII code for "1")
   39             $this->migration->db->sql('ALTER TABLE ' . Common::prefixTable('log_visit') . ' MODIFY location_ip VARBINARY(16) NOT NULL'),
   40             $this->migration->db->sql('ALTER TABLE ' . Common::prefixTable('logger_api_call') . ' MODIFY caller_ip VARBINARY(16) NOT NULL', $errorCodeDbNotExists),
   41 
   42             // fortunately, 2^32 is 10 digits long and fits in the VARBINARY(16) without truncation;
   43             // to fix this, we cast to an integer, convert to hex, pad out leading zeros, and unhex it
   44             $this->migration->db->sql('UPDATE ' . Common::prefixTable('log_visit') . "
   45                 SET location_ip = UNHEX(LPAD(HEX(CONVERT(location_ip, UNSIGNED)), 8, '0'))"),
   46             $this->migration->db->sql('UPDATE ' . Common::prefixTable('logger_api_call') . "
   47                 SET caller_ip = UNHEX(LPAD(HEX(CONVERT(caller_ip, UNSIGNED)), 8, '0'))", $errorCodeDbNotExists),
   48         );
   49     }
   50 
   51     public function doUpdate(Updater $updater)
   52     {
   53         $updater->executeMigrations(__FILE__, $this->getMigrations($updater));
   54     }
   55 }