[PP-svn] SF.net SVN: projectpier: [160] ProjectPier/Branches/0.8.0.x
Brought to you by:
projectpier
|
From: <rcr...@us...> - 2008-06-16 08:43:00
|
Revision: 160
http://projectpier.svn.sourceforge.net/projectpier/?rev=160&view=rev
Author: rcrossvs
Date: 2008-06-16 01:43:05 -0700 (Mon, 16 Jun 2008)
Log Message:
-----------
provides upgrade script for 0.8.3, which fixes timezone #588. Thanks to Phil Hord for help
Modified Paths:
--------------
ProjectPier/Branches/0.8.0.x/init.php
ProjectPier/Branches/0.8.0.x/public/upgrade/scripts/OnionUpgradeScript.class.php
ProjectPier/Branches/0.8.0.x/public/upgrade/scripts/PapayaUpgradeScript.class.php
ProjectPier/Branches/0.8.0.x/version.php
Added Paths:
-----------
ProjectPier/Branches/0.8.0.x/public/upgrade/scripts/RhubarbUpgradeScript.class.php
Modified: ProjectPier/Branches/0.8.0.x/init.php
===================================================================
--- ProjectPier/Branches/0.8.0.x/init.php 2008-04-28 05:06:08 UTC (rev 159)
+++ ProjectPier/Branches/0.8.0.x/init.php 2008-06-16 08:43:05 UTC (rev 160)
@@ -59,7 +59,7 @@
define('PRODUCT_NAME', 'ProjectPier');
if (!defined('PRODUCT_VERSION')) {
- define('PRODUCT_VERSION', '0.8');
+ define('PRODUCT_VERSION', '0.8.0.3');
} // if
define('MAX_SEARCHABLE_FILE_SIZE', 1048576); // if file type is searchable script will load its content into search index. Using this constant you can set the max filesize of the file that will be imported. Noone wants 500MB in search index for single file
Modified: ProjectPier/Branches/0.8.0.x/public/upgrade/scripts/OnionUpgradeScript.class.php
===================================================================
--- ProjectPier/Branches/0.8.0.x/public/upgrade/scripts/OnionUpgradeScript.class.php 2008-04-28 05:06:08 UTC (rev 159)
+++ ProjectPier/Branches/0.8.0.x/public/upgrade/scripts/OnionUpgradeScript.class.php 2008-06-16 08:43:05 UTC (rev 160)
@@ -64,13 +64,22 @@
$config_is_set = require_once INSTALLATION_PATH . '/config/config.php';
if (!$config_is_set) {
- $this->printMessage('Valid config files was not found!', true);
+ $this->printMessage('Valid config file was not found!', true);
return false;
} else {
$this->printMessage('Config file found and loaded.');
} // if
// ---------------------------------------------------
+ // Check for version match (pre-0.7.0 had no version?)
+ // ---------------------------------------------------
+
+ if (defined('PRODUCT_VERSION') && PRODUCT_VERSION !== '0.6') {
+ $this->printMessage('This upgrade script can be used only to upgrade 0.6 to 0.7', true);
+ return false;
+ } // if
+
+ // ---------------------------------------------------
// Check if files and folders are writable
// ---------------------------------------------------
@@ -368,7 +377,7 @@
'ROOT_URL' => ROOT_URL,
'DEFAULT_LOCALIZATION' => DEFAULT_LOCALIZATION,
'DEBUG' => false,
- 'PRODUCT_VERSION' => require INSTALLATION_PATH . '/version.php',
+ 'PRODUCT_VERSION' => $this->getVersionTo(),
); // array
tpl_assign('config_file_constants', $constants);
if (file_put_contents(INSTALLATION_PATH . '/config/config.php', tpl_fetch(get_template_path('config_file')))) {
Modified: ProjectPier/Branches/0.8.0.x/public/upgrade/scripts/PapayaUpgradeScript.class.php
===================================================================
--- ProjectPier/Branches/0.8.0.x/public/upgrade/scripts/PapayaUpgradeScript.class.php 2008-04-28 05:06:08 UTC (rev 159)
+++ ProjectPier/Branches/0.8.0.x/public/upgrade/scripts/PapayaUpgradeScript.class.php 2008-06-16 08:43:05 UTC (rev 160)
@@ -23,8 +23,8 @@
*/
function __construct(Output $output) {
parent::__construct($output);
- $this->setVersionFrom('0.8.0');
- $this->setVersionTo('0.8.0');
+ $this->setVersionFrom('0.7');
+ $this->setVersionTo('0.7.1');
} // __construct
/**
@@ -49,7 +49,7 @@
} // if
if (PRODUCT_VERSION == '0.7.1') {
- $this->printMessage('You are already running ProjectPier 0.8.0');
+ $this->printMessage('You are already running activeCollab 0.7.1');
return true;
} // if
@@ -135,7 +135,7 @@
} // if
if (mysql_query('COMMIT')) {
- $this->printMessage('ProjectPier has been upgraded. You are now running ProjectPier 0.8.0 Enjoy!');
+ $this->printMessage('activeCollab has been upgraded. You are now running activeCollab 0.7.1. Enjoy!');
return true;
} else {
$this->printMessage('Failed to commit updates. Upgrade process failed!', true);
@@ -214,7 +214,7 @@
'ROOT_URL' => ROOT_URL,
'DEFAULT_LOCALIZATION' => DEFAULT_LOCALIZATION,
'DEBUG' => false,
- 'PRODUCT_VERSION' => require INSTALLATION_PATH . '/version.php',
+ 'PRODUCT_VERSION' => $this->getVersionTo(),
); // array
tpl_assign('config_file_constants', $constants);
if (file_put_contents(INSTALLATION_PATH . '/config/config.php', tpl_fetch(get_template_path('config_file')))) {
Added: ProjectPier/Branches/0.8.0.x/public/upgrade/scripts/RhubarbUpgradeScript.class.php
===================================================================
--- ProjectPier/Branches/0.8.0.x/public/upgrade/scripts/RhubarbUpgradeScript.class.php (rev 0)
+++ ProjectPier/Branches/0.8.0.x/public/upgrade/scripts/RhubarbUpgradeScript.class.php 2008-06-16 08:43:05 UTC (rev 160)
@@ -0,0 +1,230 @@
+<?php
+
+ /**
+ * Upgrade from 0.7.1/0.8.0.x to 0.8.0.3
+ *
+ * @package ScriptUpgrader.scripts
+ * @http://www.projectpier.org/
+ */
+ class RhubarbUpgradeScript extends ScriptUpgraderScript {
+
+ /**
+ * Database connection link
+ *
+ * @var resource
+ */
+ private $database_connection = null;
+
+ /**
+ * Construct the RhubarbUpgradeScript
+ *
+ * @param Output $output
+ * @return RhubarbUpgradeScript
+ */
+ function __construct(Output $output) {
+ parent::__construct($output);
+ $this->setVersionFrom('0.8.0');
+ $this->setVersionTo('0.8.0.3');
+ } // __construct
+
+ /**
+ * Execute the script
+ *
+ * @param void
+ * @return boolean
+ */
+ function execute() {
+ define('ROOT', realpath(dirname(__FILE__) . '/../../../'));
+
+ // ---------------------------------------------------
+ // Load config
+ // ---------------------------------------------------
+
+ $config_is_set = require_once INSTALLATION_PATH . '/config/config.php';
+ if (!$config_is_set) {
+ $this->printMessage('Valid config file was not found!', true);
+ return false;
+ } else {
+ $this->printMessage('Config file found and loaded.');
+ }
+
+ if (PRODUCT_VERSION == '0.8.0.3') {
+ $this->printMessage('You are already running ProjectPier 0.8.0.3');
+ return true;
+ }
+
+ if (PRODUCT_VERSION !== '0.7.1' &&
+ preg_match('/^0\.8\.0(?:\.[0-3])?$/', PRODUCT_VERSION) == 0) {
+ $this->printMessage('This upgrade script can be used only to upgrade 0.7.1 or 0.8.0.x to 0.8.0.3', true);
+ return false;
+ }
+
+ // ---------------------------------------------------
+ // Connect to database
+ // ---------------------------------------------------
+
+ if ($this->database_connection = mysql_connect(DB_HOST, DB_USER, DB_PASS)) {
+ if (mysql_select_db(DB_NAME, $this->database_connection)) {
+ $this->printMessage('Upgrade script has connected to the database.');
+ } else {
+ $this->printMessage('Failed to select database ' . DB_NAME);
+ return false;
+ } // if
+ } else {
+ $this->printMessage('Failed to connect to database');
+ return false;
+ } // if
+
+ // ---------------------------------------------------
+ // Check MySQL version
+ // ---------------------------------------------------
+
+ $mysql_version = mysql_get_server_info($this->database_connection);
+ if ($mysql_version && version_compare($mysql_version, '4.1', '>=')) {
+ $constants['DB_CHARSET'] = 'utf8';
+ mysql_query("SET NAMES 'utf8'", $this->database_connection);
+ tpl_assign('default_collation', $default_collation = 'collate utf8_unicode_ci');
+ tpl_assign('default_charset', $default_charset = 'DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci');
+ } else {
+ tpl_assign('default_collation', $default_collation = '');
+ tpl_assign('default_charset', $default_charset = '');
+ } // if
+
+ tpl_assign('table_prefix', TABLE_PREFIX);
+
+ // ---------------------------------------------------
+ // Check test query
+ // ---------------------------------------------------
+
+ $test_table_name = TABLE_PREFIX . 'test_table';
+ $test_table_sql = "CREATE TABLE `$test_table_name` (
+ `id` int(10) unsigned NOT NULL auto_increment,
+ `name` varchar(50) $default_collation NOT NULL default '',
+ PRIMARY KEY (`id`)
+ ) ENGINE=InnoDB $default_charset;";
+
+ if (mysql_query($test_table_sql, $this->database_connection)) {
+ $this->printMessage('Test query has been executed. Its safe to proceed with database migration.');
+ mysql_query("DROP TABLE `$test_table_name`", $this->database_connection);
+ } else {
+ $this->printMessage('Failed to executed test query. MySQL said: ' . mysql_error($this->database_connection), true);
+ return false;
+ }
+
+ //return ;
+
+ // ---------------------------------------------------
+ // Execute migration
+ // ---------------------------------------------------
+
+ mysql_query('BEGIN WORK');
+
+ if ($this->fixTimezone() === false) {
+ mysql_query('ROLLBACK');
+ $this->printMessage('Upgrade process failed!', true);
+ return false;
+ }
+
+ if (!mysql_query('COMMIT')) {
+ $this->printMessage('Failed to commit updates. Upgrade process failed!', true);
+ return false;
+ }
+
+ $this->fixConfigFile();
+
+ $this->printMessage('ProjectPier has been upgraded. You are now running ProjectPier '.$this->getVersionTo().' Enjoy!');
+ }
+
+ /**
+ * Fix the timezone columns
+ *
+ * @param void
+ * @return null
+ */
+ function fixTimezone() {
+ $users_table = TABLE_PREFIX . 'users';
+ if (mysql_query("ALTER TABLE `$users_table` MODIFY COLUMN `timezone` FLOAT(3,1) NOT NULL DEFAULT '0.0'", $this->database_connection)) {
+ $this->printMessage('Users table has been updated');
+ } else {
+ $this->printMessage('Failed to update users table. MySQL said: ' . mysql_error($this->database_connection), true);
+ return false;
+ }
+ $companies_table = TABLE_PREFIX . 'companies';
+ if (mysql_query("ALTER TABLE `$companies_table` MODIFY COLUMN `timezone` FLOAT(3,1) NOT NULL DEFAULT '0.0'", $this->database_connection)) {
+ $this->printMessage('Companies table has been updated');
+ } else {
+ $this->printMessage('Failed to update companies table. MySQL said: ' . mysql_error($this->database_connection), true);
+ return false;
+ }
+ return true;
+ }
+
+
+ /**
+ * This function will update the configuration file
+ *
+ * @param void
+ * @return null
+ */
+ function fixConfigFile() {
+ $this->printMessage('Updating configuration file');
+
+ //----------------------------------------------------------
+ // Set up constants array with known values and defaults
+ //----------------------------------------------------------
+ $constants = array(
+ 'DB_ADAPTER' => DB_ADAPTER,
+ 'DB_HOST' => DB_HOST,
+ 'DB_USER' => DB_USER,
+ 'DB_PASS' => DB_PASS,
+ 'DB_NAME' => DB_NAME,
+ 'DB_CHARSET' => 'utf8',
+ 'DB_PERSIST' => true,
+ 'TABLE_PREFIX' => TABLE_PREFIX,
+ 'ROOT_URL' => ROOT_URL,
+ 'DEBUG' => false,
+ 'DEFAULT_LOCALIZATION' => 'en_us',
+ 'DEBUG' => false,
+ 'SHOW_MESSAGE_BODY' => true,
+ 'SHOW_COMMENT_BODY' => true,
+ 'SHOW_MILESTONE_BODY' => true,
+ ); // array
+
+ //----------------------------------------------------------
+ // Provide token_cookie_name only if defined
+ //----------------------------------------------------------
+ if (defined('TOKEN_COOKIE_NAME') ) {
+ $constants['TOKEN_COOKIE_NAME'] = TOKEN_COOKIE_NAME ;
+ }
+
+ //----------------------------------------------------------
+ // Replace default values with previously-defined values, if they exist.
+ //----------------------------------------------------------
+ foreach ($constants as $config_key => $config_value) {
+ if (defined($config_key)) {
+ $constants[$config_key] = constant($config_key);
+ } // if
+ } // foreach
+
+ //----------------------------------------------------------
+ // Insert changes to existing config
+ //----------------------------------------------------------
+ $constants['PRODUCT_VERSION'] = $this->getVersionTo() ;
+
+ //----------------------------------------------------------
+ // Write the config file out using a template
+ //----------------------------------------------------------
+ tpl_assign('config_file_constants', $constants);
+ if (file_put_contents(INSTALLATION_PATH . '/config/config.php', tpl_fetch(get_template_path('config_file')))) {
+ $this->printMessage('Configuration file updated');
+ return true;
+ } else {
+ $this->printMessage('Failed to update configuration file', true);
+ return false;
+ } // if
+ } // fixConfigFile
+
+
+ } // RhubarbUpgradeScript
+
+?>
Modified: ProjectPier/Branches/0.8.0.x/version.php
===================================================================
--- ProjectPier/Branches/0.8.0.x/version.php 2008-04-28 05:06:08 UTC (rev 159)
+++ ProjectPier/Branches/0.8.0.x/version.php 2008-06-16 08:43:05 UTC (rev 160)
@@ -3,16 +3,18 @@
/**
* Return version of codebase
*
- * This file contains the version of source code distribution. It does not always means the
- * version installed, just the version of the code. For instance, when you update the files
- * but you don't run the upgrade script - you are still using the old version with new files
- * ant that means that you are not actualy using new version. You'll most probably end up with
+ * This file contains the version of source code distribution. It does not reflect the
+ * version installed in the database, just the version of the code. For instance, when
+ * you update the code files to a new version but you don't run the upgrade script,
+ * you are still using the old version database with new code files. And that means
+ * that you are not actually using the new version. You'll most probably end up with
* a lot of problems and errors in that situation; they will be gone as soon as your run the
* upgrade script.
*
- *
+ * TODO: ProjectPier should check for version mismatches on startup and go to the
+ * Admin/Upgrade script page if needed.
*/
- return '0.8.0.2';
+ return '0.8.0.3';
?>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|