PageRenderTime 54ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/core/Updates/1.2-rc1.php

https://github.com/quarkness/piwik
PHP | 147 lines | 110 code | 14 blank | 23 comment | 2 complexity | 9121d8c98bad998b34eecac88b03df91 MD5 | raw file
  1. <?php
  2. /**
  3. * Piwik - Open source web analytics
  4. *
  5. * @link http://piwik.org
  6. * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
  7. * @version $Id$
  8. *
  9. * @category Piwik
  10. * @package Updates
  11. */
  12. /**
  13. * @package Updates
  14. */
  15. class Piwik_Updates_1_2_rc1 extends Piwik_Updates
  16. {
  17. static function getSql($schema = 'Myisam')
  18. {
  19. return array(
  20. // Various performance improvements schema updates
  21. 'ALTER TABLE `'. Piwik_Common::prefixTable('log_visit') .'`
  22. DROP `visit_server_date`,
  23. DROP INDEX `index_idsite_date_config`,
  24. DROP INDEX `index_idsite_datetime_config`,
  25. ADD `visit_entry_idaction_name` INT UNSIGNED NOT NULL AFTER `visit_entry_idaction_url`,
  26. ADD `visit_exit_idaction_name` INT UNSIGNED NOT NULL AFTER `visit_exit_idaction_url`,
  27. CHANGE `visit_exit_idaction_url` `visit_exit_idaction_url` INT UNSIGNED NOT NULL,
  28. CHANGE `visit_entry_idaction_url` `visit_entry_idaction_url` INT UNSIGNED NOT NULL,
  29. CHANGE `referer_type` `referer_type` TINYINT UNSIGNED NULL DEFAULT NULL,
  30. ADD `idvisitor` BINARY(8) NOT NULL AFTER `idsite`,
  31. ADD visitor_count_visits SMALLINT(5) UNSIGNED NOT NULL AFTER `visitor_returning`,
  32. ADD visitor_days_since_last SMALLINT(5) UNSIGNED NOT NULL,
  33. ADD visitor_days_since_first SMALLINT(5) UNSIGNED NOT NULL,
  34. ADD `config_id` BINARY(8) NOT NULL AFTER `config_md5config`,
  35. ADD custom_var_k1 VARCHAR(100) DEFAULT NULL,
  36. ADD custom_var_v1 VARCHAR(100) DEFAULT NULL,
  37. ADD custom_var_k2 VARCHAR(100) DEFAULT NULL,
  38. ADD custom_var_v2 VARCHAR(100) DEFAULT NULL,
  39. ADD custom_var_k3 VARCHAR(100) DEFAULT NULL,
  40. ADD custom_var_v3 VARCHAR(100) DEFAULT NULL,
  41. ADD custom_var_k4 VARCHAR(100) DEFAULT NULL,
  42. ADD custom_var_v4 VARCHAR(100) DEFAULT NULL,
  43. ADD custom_var_k5 VARCHAR(100) DEFAULT NULL,
  44. ADD custom_var_v5 VARCHAR(100) DEFAULT NULL
  45. ' => false,
  46. 'ALTER TABLE `'. Piwik_Common::prefixTable('log_link_visit_action') .'`
  47. ADD `idsite` INT( 10 ) UNSIGNED NOT NULL AFTER `idlink_va` ,
  48. ADD `server_time` DATETIME AFTER `idsite`,
  49. ADD `idvisitor` BINARY(8) NOT NULL AFTER `idsite`,
  50. ADD `idaction_name_ref` INT UNSIGNED NOT NULL AFTER `idaction_name`,
  51. ADD INDEX `index_idsite_servertime` ( `idsite` , `server_time` )
  52. ' => false,
  53. 'ALTER TABLE `'. Piwik_Common::prefixTable('log_conversion') .'`
  54. DROP `referer_idvisit`,
  55. ADD `idvisitor` BINARY(8) NOT NULL AFTER `idsite`,
  56. ADD visitor_count_visits SMALLINT(5) UNSIGNED NOT NULL,
  57. ADD visitor_days_since_first SMALLINT(5) UNSIGNED NOT NULL,
  58. ADD custom_var_k1 VARCHAR(100) DEFAULT NULL,
  59. ADD custom_var_v1 VARCHAR(100) DEFAULT NULL,
  60. ADD custom_var_k2 VARCHAR(100) DEFAULT NULL,
  61. ADD custom_var_v2 VARCHAR(100) DEFAULT NULL,
  62. ADD custom_var_k3 VARCHAR(100) DEFAULT NULL,
  63. ADD custom_var_v3 VARCHAR(100) DEFAULT NULL,
  64. ADD custom_var_k4 VARCHAR(100) DEFAULT NULL,
  65. ADD custom_var_v4 VARCHAR(100) DEFAULT NULL,
  66. ADD custom_var_k5 VARCHAR(100) DEFAULT NULL,
  67. ADD custom_var_v5 VARCHAR(100) DEFAULT NULL
  68. ' => false,
  69. // Migrate 128bits IDs inefficiently stored as 8bytes (256 bits) into 64bits
  70. 'UPDATE '.Piwik_Common::prefixTable('log_visit') .'
  71. SET idvisitor = binary(unhex(substring(visitor_idcookie,1,16))),
  72. config_id = binary(unhex(substring(config_md5config,1,16)))
  73. ' => false,
  74. 'UPDATE '.Piwik_Common::prefixTable('log_conversion') .'
  75. SET idvisitor = binary(unhex(substring(visitor_idcookie,1,16)))
  76. ' => false,
  77. // Drop migrated fields
  78. 'ALTER TABLE `'. Piwik_Common::prefixTable('log_visit') .'`
  79. DROP visitor_idcookie,
  80. DROP config_md5config
  81. ' => false,
  82. 'ALTER TABLE `'. Piwik_Common::prefixTable('log_conversion') .'`
  83. DROP visitor_idcookie
  84. ' => false,
  85. // Recreate INDEX on new field
  86. 'ALTER TABLE `'. Piwik_Common::prefixTable('log_visit') .'`
  87. ADD INDEX `index_idsite_datetime_config` (idsite, visit_last_action_time, config_id)
  88. ' => false,
  89. // Backfill action logs as best as we can
  90. 'UPDATE '.Piwik_Common::prefixTable('log_link_visit_action') .' as action,
  91. '.Piwik_Common::prefixTable('log_visit') .' as visit
  92. SET action.idsite = visit.idsite,
  93. action.server_time = visit.visit_last_action_time,
  94. action.idvisitor = visit.idvisitor
  95. WHERE action.idvisit=visit.idvisit
  96. ' => false,
  97. 'ALTER TABLE `'. Piwik_Common::prefixTable('log_link_visit_action') .'`
  98. CHANGE `server_time` `server_time` DATETIME NOT NULL
  99. ' => false,
  100. // New index used max once per request, in case this table grows significantly in the future
  101. 'ALTER TABLE `'. Piwik_Common::prefixTable('option') .'` ADD INDEX ( `autoload` ) ' => false,
  102. // new field for websites
  103. 'ALTER TABLE `'. Piwik_Common::prefixTable('site') .'` ADD `group` VARCHAR( 250 ) NOT NULL' => false,
  104. );
  105. }
  106. static function update()
  107. {
  108. // first we disable the plugins and keep an array of warnings messages
  109. $pluginsToDisableMessage = array(
  110. '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' href='?module=Proxy&action=redirect&url=http://dev.piwik.org/trac/ticket/45'>Click here.</a>",
  111. 'EntryPage' => "EntryPage plugin is not compatible with this version of Piwik, it was disabled.",
  112. );
  113. $disabledPlugins = array();
  114. foreach($pluginsToDisableMessage as $pluginToDisable => $warningMessage)
  115. {
  116. if(Piwik_PluginsManager::getInstance()->isPluginActivated($pluginToDisable))
  117. {
  118. Piwik_PluginsManager::getInstance()->deactivatePlugin($pluginToDisable);
  119. $disabledPlugins[] = $warningMessage;
  120. }
  121. }
  122. // Run the SQL
  123. Piwik_Updater::updateDatabase(__FILE__, self::getSql());
  124. // Outputs warning message, pointing users to the plugin download page
  125. if(!empty($disabledPlugins))
  126. {
  127. throw new Exception("The following plugins were disabled during the upgrade:"
  128. ."<ul><li>" .
  129. implode('</li><li>', $disabledPlugins) .
  130. "</li></ul>");
  131. }
  132. }
  133. }