From 0d5216267cc3c647596cf3ee7288e21b40fe6586 Mon Sep 17 00:00:00 2001 From: plegall Date: Wed, 28 Mar 2007 22:06:13 +0000 Subject: New: release upgrade scripts from 1.3.0 come back from branch 1.6. Only install/upgrade_1.6.2.php is really new, upgrade 60 was taken into account. Detection of 1.6.0 or 1.6.2 data model in upgrade.php. Release upgrade scripts added on trunk to be kept in a safer place. git-svn-id: http://piwigo.org/svn/trunk@1927 68402e56-0260-453c-a942-63ccdbb3a9ee --- install/upgrade_1.3.0.php | 130 ++++++++++ install/upgrade_1.3.1.php | 606 ++++++++++++++++++++++++++++++++++++++++++++++ install/upgrade_1.4.0.php | 296 ++++++++++++++++++++++ install/upgrade_1.5.0.php | 473 ++++++++++++++++++++++++++++++++++++ install/upgrade_1.6.0.php | 58 +++++ install/upgrade_1.6.2.php | 350 ++++++++++++++++++++++++++ template/yoga/upgrade.tpl | 44 ++++ upgrade.php | 316 ++++++++++++++++++++++++ 8 files changed, 2273 insertions(+) create mode 100644 install/upgrade_1.3.0.php create mode 100644 install/upgrade_1.3.1.php create mode 100644 install/upgrade_1.4.0.php create mode 100644 install/upgrade_1.5.0.php create mode 100644 install/upgrade_1.6.0.php create mode 100644 install/upgrade_1.6.2.php create mode 100644 template/yoga/upgrade.tpl create mode 100644 upgrade.php diff --git a/install/upgrade_1.3.0.php b/install/upgrade_1.3.0.php new file mode 100644 index 000000000..f5d650e6b --- /dev/null +++ b/install/upgrade_1.3.0.php @@ -0,0 +1,130 @@ + array('id'), + 'update' => array('uppercats') + ), + $datas + ); + +// now we upgrade from 1.3.1 to 1.6.0 +include_once(PHPWG_ROOT_PATH.'install/upgrade_1.3.1.php'); +?> \ No newline at end of file diff --git a/install/upgrade_1.3.1.php b/install/upgrade_1.3.1.php new file mode 100644 index 000000000..3e1e42c14 --- /dev/null +++ b/install/upgrade_1.3.1.php @@ -0,0 +1,606 @@ += 1) to 1.4.0 + */ + +if (!defined('PHPWG_ROOT_PATH')) +{ + die ('This page cannot be loaded directly, load upgrade.php'); +} +else +{ + if (!defined('PHPWG_IN_UPGRADE') or !PHPWG_IN_UPGRADE) + { + die ('Hacking attempt!'); + } +} + +// save data before deletion +$query = ' +SELECT prefix_thumbnail, mail_webmaster + FROM '.PREFIX_TABLE.'config +;'; +$save = mysql_fetch_array(mysql_query($query)); + +$queries = array( + " +DROP TABLE phpwebgallery_config +;", + + " +CREATE TABLE phpwebgallery_config ( + param varchar(40) NOT NULL default '', + value varchar(255) default NULL, + comment varchar(255) default NULL, + PRIMARY KEY (param) +) TYPE=MyISAM COMMENT='configuration table' +;", + + " +ALTER TABLE phpwebgallery_categories + CHANGE COLUMN site_id site_id tinyint(4) unsigned default '1' +;", + + " +ALTER TABLE phpwebgallery_categories + ADD COLUMN commentable enum('true','false') NOT NULL default 'true' +;", + + " +ALTER TABLE phpwebgallery_categories + ADD COLUMN global_rank varchar(255) default NULL +;", + + " +ALTER TABLE phpwebgallery_categories + ADD INDEX categories_i2 (id_uppercat) +;", + + " +ALTER TABLE phpwebgallery_comments + ADD COLUMN date_temp int(11) unsigned +;", + + " +UPDATE phpwebgallery_comments + SET date_temp = date +;", + + " +ALTER TABLE phpwebgallery_comments + CHANGE COLUMN date date datetime NOT NULL default '0000-00-00 00:00:00' +;", + + " +UPDATE phpwebgallery_comments + SET date = FROM_UNIXTIME(date_temp) +;", + + " +ALTER TABLE phpwebgallery_comments + DROP COLUMN date_temp +;", + + " +ALTER TABLE phpwebgallery_favorites + DROP INDEX user_id +;", + + " +ALTER TABLE phpwebgallery_favorites + ADD PRIMARY KEY (user_id,image_id) +;", + + " +ALTER TABLE phpwebgallery_history + ADD COLUMN date_temp int(11) unsigned +;", + + " +UPDATE phpwebgallery_history + SET date_temp = date +;", + + " +ALTER TABLE phpwebgallery_history + CHANGE COLUMN date date datetime NOT NULL default '0000-00-00 00:00:00' +;", + + " +UPDATE phpwebgallery_history + SET date = FROM_UNIXTIME(date_temp) +;", + + " +ALTER TABLE phpwebgallery_history + DROP COLUMN date_temp +;", + + " +ALTER TABLE phpwebgallery_history + ADD INDEX history_i1 (date) +;", + + " +ALTER TABLE phpwebgallery_image_category + ADD INDEX image_category_i1 (image_id), + ADD INDEX image_category_i2 (category_id) +;", + + " +ALTER TABLE phpwebgallery_images + CHANGE COLUMN tn_ext tn_ext varchar(4) default '' +;", + + " +ALTER TABLE phpwebgallery_images + ADD COLUMN path varchar(255) NOT NULL default '' +;", + + " +ALTER TABLE phpwebgallery_images + ADD COLUMN date_metadata_update date default NULL +;", + + " +ALTER TABLE phpwebgallery_images + ADD COLUMN average_rate float(5,2) unsigned default NULL +;", + + " +ALTER TABLE phpwebgallery_images + ADD COLUMN representative_ext varchar(4) default NULL +;", + + " +ALTER TABLE phpwebgallery_images + DROP INDEX storage_category_id +;", + + " +ALTER TABLE phpwebgallery_images + ADD INDEX images_i1 (storage_category_id) +;", + + " +ALTER TABLE phpwebgallery_images + ADD INDEX images_i2 (date_available) +;", + + " +ALTER TABLE phpwebgallery_images + ADD INDEX images_i3 (average_rate) +;", + + " +ALTER TABLE phpwebgallery_images + ADD INDEX images_i4 (hit) +;", + + " +ALTER TABLE phpwebgallery_images + ADD INDEX images_i5 (date_creation) +;", + + " +ALTER TABLE phpwebgallery_sessions + DROP COLUMN ip +;", + + " +ALTER TABLE phpwebgallery_sessions + ADD COLUMN expiration_temp int(11) unsigned +;", + + " +UPDATE phpwebgallery_sessions + SET expiration_temp = expiration +;", + + " +ALTER TABLE phpwebgallery_sessions + CHANGE COLUMN expiration expiration datetime NOT NULL default '0000-00-00 00:00:00' +;", + + " +UPDATE phpwebgallery_sessions + SET expiration = FROM_UNIXTIME(expiration_temp) +;", + + " +ALTER TABLE phpwebgallery_sessions + DROP COLUMN expiration_temp +;", + + " +ALTER TABLE phpwebgallery_sites + DROP INDEX galleries_url +;", + + " +ALTER TABLE phpwebgallery_sites + ADD UNIQUE sites_ui1 (galleries_url) +;", + + " +DROP TABLE phpwebgallery_user_category +;", + + " +ALTER TABLE phpwebgallery_users + DROP COLUMN long_period +;", + + " +ALTER TABLE phpwebgallery_users + DROP COLUMN short_period +;", + + " +ALTER TABLE phpwebgallery_users + ADD COLUMN recent_period tinyint(3) unsigned NOT NULL default '7' +;", + + " +ALTER TABLE phpwebgallery_users + DROP INDEX username +;", + + " +ALTER TABLE phpwebgallery_users + ADD UNIQUE users_ui1 (username) +;", + + " +CREATE TABLE phpwebgallery_rate ( + user_id smallint(5) unsigned NOT NULL default '0', + element_id mediumint(8) unsigned NOT NULL default '0', + rate tinyint(2) unsigned NOT NULL default '0', + PRIMARY KEY (user_id,element_id) +) TYPE=MyISAM +;", + + " +CREATE TABLE phpwebgallery_user_forbidden ( + user_id smallint(5) unsigned NOT NULL default '0', + need_update enum('true','false') NOT NULL default 'true', + forbidden_categories text, + PRIMARY KEY (user_id) +) TYPE=MyISAM +;", + + " +UPDATE phpwebgallery_users + SET language = 'en_UK.iso-8859-1' + , template = 'default' +;", + + " +DELETE FROM phpwebgallery_user_access +;", + + " +DELETE FROM phpwebgallery_group_access +;" + + ); + +foreach ($queries as $query) +{ + $query = str_replace('phpwebgallery_', PREFIX_TABLE, $query); + pwg_query($query); +} + +// +// check indexes +// +$indexes_of = array( + 'categories' => array( + 'categories_i2' => array( + 'columns' => array('id_uppercat'), + 'unique' => false, + ) + ), + 'image_category' => array( + 'image_category_i1' => array( + 'columns' => array('image_id'), + 'unique' => false, + ), + 'image_category_i2' => array( + 'columns' => array('category_id'), + 'unique' => false, + ), + ), + ); + +foreach (array_keys($indexes_of) as $table) +{ + $existing_indexes = array(); + + $query = ' +SHOW INDEX + FROM '.PREFIX_TABLE.$table.' +;'; + $result = pwg_query($query); + while ($row = mysql_fetch_array($result)) + { + if ($row['Key_name'] != 'PRIMARY') + { + if (!in_array($row['Key_name'], array_keys($indexes_of[$table]))) + { + $query = ' +ALTER TABLE '.PREFIX_TABLE.$table.' + DROP INDEX '.$row['Key_name'].' +;'; + pwg_query($query); + } + else + { + array_push($existing_indexes, $row['Key_name']); + } + } + } + + foreach ($indexes_of[$table] as $index_name => $index) + { + if (!in_array($index_name, $existing_indexes)) + { + $query = ' +ALTER TABLE '.PREFIX_TABLE.$table.' + ADD '.($index['unique'] ? 'UNIQUE' : 'INDEX').' ' + .$index_name.' ('.implode(',', $index['columns']).') +;'; + pwg_query($query); + } + } +} + +// +// insert params in new configuration table +// +$params = array( + array( + 'param' => 'prefix_thumbnail', + 'value' => $save['prefix_thumbnail'], + 'comment' => 'thumbnails filename prefix' + ), + array( + 'param' => 'mail_webmaster', + 'value' => $save['mail_webmaster'], + 'comment' => 'webmaster mail' + ), + array( + 'param' => 'default_language', + 'value' => 'en_UK.iso-8859-1', + 'comment' => 'Default gallery language' + ), + array( + 'param' => 'default_template', + 'value' => 'default', + 'comment' => 'Default gallery style' + ), + array( + 'param' => 'default_maxwidth', + 'value' => '', + 'comment' => 'maximum width authorized for displaying images' + ), + array( + 'param' => 'default_maxheight', + 'value' => '', + 'comment' => 'maximum height authorized for the displaying images' + ), + array( + 'param' => 'nb_comment_page', + 'value' => '10', + 'comment' => 'number of comments to display on each page' + ), + array( + 'param' => 'upload_maxfilesize', + 'value' => '150', + 'comment' => 'maximum filesize for the uploaded pictures' + ), + array( + 'param' => 'upload_maxwidth', + 'value' => '800', + 'comment' => 'maximum width authorized for the uploaded images' + ), + array( + 'param' => 'upload_maxheight', + 'value' => '600', + 'comment' => 'maximum height authorized for the uploaded images' + ), + array( + 'param' => 'upload_maxwidth_thumbnail', + 'value' => '150', + 'comment' => 'maximum width authorized for the uploaded thumbnails' + ), + array( + 'param' => 'upload_maxheight_thumbnail', + 'value' => '100', + 'comment' => 'maximum height authorized for the uploaded thumbnails' + ), + array( + 'param' => 'log', + 'value' => 'false', + 'comment' => 'keep an history of visits on your website' + ), + array( + 'param' => 'comments_validation', + 'value' => 'false', + 'comment' => 'administrators validate users comments before becoming visible' + ), + array( + 'param' => 'comments_forall', + 'value' => 'false', + 'comment' => 'even guest not registered can post comments' + ), + array( + 'param' => 'mail_notification', + 'value' => 'false', + 'comment' => 'automated mail notification for adminsitrators' + ), + array( + 'param' => 'nb_image_line', + 'value' => '5', + 'comment' => 'Number of images displayed per row' + ), + array( + 'param' => 'nb_line_page', + 'value' => '3', + 'comment' => 'Number of rows displayed per page' + ), + array( + 'param' => 'recent_period', + 'value' => '7', + 'comment' => 'Period within which pictures are displayed as new (in days)' + ), + array( + 'param' => 'auto_expand', + 'value' => 'false', + 'comment' => 'Auto expand of the category tree' + ), + array( + 'param' => 'show_nb_comments', + 'value' => 'false', + 'comment' => 'Show the number of comments under the thumbnails' + ), + array( + 'param' => 'use_iptc', + 'value' => 'false', + 'comment' => 'Use IPTC data during database synchronization with files metadata' + ), + array( + 'param' => 'use_exif', + 'value' => 'false', + 'comment' => 'Use EXIF data during database synchronization with files metadata' + ), + array( + 'param' => 'show_iptc', + 'value' => 'false', + 'comment' => 'Show IPTC metadata on picture.php if asked by user' + ), + array( + 'param' => 'show_exif', + 'value' => 'true', + 'comment' => 'Show EXIF metadata on picture.php if asked by user' + ), + array( + 'param' => 'authorize_remembering', + 'value' => 'true', + 'comment' => 'Authorize users to be remembered, see $conf{remember_me_length}' + ), + array( + 'param' => 'gallery_locked', + 'value' => 'false', + 'comment' => 'Lock your gallery temporary for non admin users' + ), + ); + +mass_inserts( + CONFIG_TABLE, + array_keys($params[0]), + $params + ); + +// refresh calculated datas +ordering(); +update_global_rank(); +update_category(); + +// update calculated field "images.path" +$cat_ids = array(); + +$query = ' +SELECT DISTINCT(storage_category_id) AS unique_storage_category_id + FROM '.IMAGES_TABLE.' +;'; +$result = pwg_query($query); +while ($row = mysql_fetch_array($result)) +{ + array_push($cat_ids, $row['unique_storage_category_id']); +} +$fulldirs = get_fulldirs($cat_ids); + +foreach ($cat_ids as $cat_id) +{ + $query = ' +UPDATE '.IMAGES_TABLE.' + SET path = CONCAT(\''.$fulldirs[$cat_id].'\',\'/\',file) + WHERE storage_category_id = '.$cat_id.' +;'; + pwg_query($query); +} + +// all sub-categories of private categories become private +$cat_ids = array(); + +$query = ' +SELECT id + FROM '.CATEGORIES_TABLE.' + WHERE status = \'private\' +;'; +$result = pwg_query($query); +while ($row = mysql_fetch_array($result)) +{ + array_push($cat_ids, $row['id']); +} + +if (count($cat_ids) > 0) +{ + $privates = get_subcat_ids($cat_ids); + + $query = ' +UPDATE '.CATEGORIES_TABLE.' + SET status = \'private\' + WHERE id IN ('.implode(',', $privates).') +;'; + pwg_query($query); +} + +$page['infos'] = array_merge( + $page['infos'], + array( + 'all sub-categories of private categories become private', + + 'user permissions and group permissions have been erased', + + 'only thumbnails prefix and webmaster mail address have been saved from +previous configuration', + + 'in include/mysql.inc.php, before +
?>
+insert +
define(\'PHPWG_INSTALLED\', true);
'
+    )
+  );
+
+
+// now we upgrade from 1.4.0
+include_once(PHPWG_ROOT_PATH.'install/upgrade_1.4.0.php');
+?>
\ No newline at end of file
diff --git a/install/upgrade_1.4.0.php b/install/upgrade_1.4.0.php
new file mode 100644
index 000000000..2d98cadf6
--- /dev/null
+++ b/install/upgrade_1.4.0.php
@@ -0,0 +1,296 @@
+
\ No newline at end of file
diff --git a/install/upgrade_1.5.0.php b/install/upgrade_1.5.0.php
new file mode 100644
index 000000000..2f69ffe10
--- /dev/null
+++ b/install/upgrade_1.5.0.php
@@ -0,0 +1,473 @@
+ $tag_id)
+  {
+    array_push(
+      $datas,
+      array(
+        'id'       => $tag_id,
+        'name'     => $tag_name,
+        'url_name' => str2url($tag_name),
+        )
+      );
+  }
+  
+  if (!empty($datas))
+  {
+    mass_inserts(
+      PREFIX_TABLE.'tags',
+      array_keys($datas[0]),
+      $datas
+      );
+  }
+
+  $datas = array();
+  foreach ($tag_images as $tag_id => $images)
+  {
+    foreach (array_unique($images) as $image_id)
+    {
+      array_push(
+        $datas,
+        array(
+          'tag_id'   => $tag_id,
+          'image_id' => $image_id,
+          )
+        );
+    }
+  }
+  
+  if (!empty($datas))
+  {
+    mass_inserts(
+      PREFIX_TABLE.'image_tag',
+      array_keys($datas[0]),
+      $datas
+      );
+  }
+
+  //
+  // Delete images.keywords
+  //
+  $query = '
+ALTER TABLE '.PREFIX_TABLE.'images DROP COLUMN keywords
+;';
+  pwg_query($query);
+
+  //
+  // Add useful indexes
+  //
+  $query = '
+ALTER TABLE '.PREFIX_TABLE.'tags
+  ADD INDEX tags_i1(url_name)
+;';
+  pwg_query($query);
+
+
+  $query = '
+ALTER TABLE '.PREFIX_TABLE.'image_tag
+  ADD INDEX image_tag_i1(tag_id)
+;';
+  pwg_query($query);
+
+  // print_time('tags have replaced keywords');
+}
+
+tag_replace_keywords();
+
+$queries = array(
+  "
+CREATE TABLE ".PREFIX_TABLE."search (
+  id int UNSIGNED NOT NULL AUTO_INCREMENT,
+  last_seen date DEFAULT NULL,
+  rules text,
+  PRIMARY KEY  (id)
+);",
+
+  "
+CREATE TABLE ".PREFIX_TABLE."user_mail_notification (
+  user_id smallint(5) NOT NULL default '0',
+  check_key varchar(16) binary NOT NULL default '',
+  enabled enum('true','false') NOT NULL default 'false',
+  last_send datetime default NULL,
+  PRIMARY KEY  (user_id),
+  UNIQUE KEY uidx_check_key (check_key)
+);",
+
+  "
+CREATE TABLE ".PREFIX_TABLE."upgrade (
+  id varchar(20) NOT NULL default '',
+  applied datetime NOT NULL default '0000-00-00 00:00:00',
+  description varchar(255) default NULL,
+  PRIMARY KEY  (`id`)
+);",
+
+  "
+ALTER TABLE ".PREFIX_TABLE."config
+  MODIFY COLUMN value TEXT
+;",
+
+  "
+ALTER TABLE ".PREFIX_TABLE."images
+  ADD COLUMN has_high enum('true') default NULL
+;",
+
+  "
+ALTER TABLE ".PREFIX_TABLE."rate
+  ADD COLUMN anonymous_id varchar(45) NOT NULL default ''
+;",
+  "
+ALTER TABLE ".PREFIX_TABLE."rate
+  ADD COLUMN date date NOT NULL default '0000-00-00'
+;",
+  "
+ALTER TABLE ".PREFIX_TABLE."rate
+  DROP PRIMARY KEY
+;",
+  "
+ALTER TABLE ".PREFIX_TABLE."rate
+  ADD PRIMARY KEY (element_id,user_id,anonymous_id)
+;",
+  "
+UPDATE ".PREFIX_TABLE."rate
+  SET date = CURDATE()
+;",
+  
+  "
+DELETE
+  FROM ".PREFIX_TABLE."sessions
+;",
+  "
+ALTER TABLE ".PREFIX_TABLE."sessions
+  DROP COLUMN user_id
+;",
+  "
+ALTER TABLE ".PREFIX_TABLE."sessions
+  ADD COLUMN data text NOT NULL
+;",
+  
+  "
+ALTER TABLE ".PREFIX_TABLE."user_cache
+  ADD COLUMN nb_total_images mediumint(8) unsigned default NULL
+;",
+  
+  "
+ALTER TABLE ".PREFIX_TABLE."user_infos
+  CHANGE COLUMN status
+     status enum('webmaster','admin','normal','generic','guest')
+     NOT NULL default 'guest'
+;",
+  "
+UPDATE ".PREFIX_TABLE."user_infos
+  SET status = 'normal'
+  WHERE status = 'guest'
+;",
+  "
+UPDATE ".PREFIX_TABLE."user_infos
+  SET status = 'guest'
+  WHERE user_id = ".$conf['guest_id']."
+;",
+  "
+UPDATE ".PREFIX_TABLE."user_infos
+  SET status = 'webmaster'
+  WHERE user_id = ".$conf['webmaster_id']."
+;",
+
+  "
+ALTER TABLE ".PREFIX_TABLE."user_infos
+   CHANGE COLUMN template template varchar(255) NOT NULL default 'yoga/clear'
+;",
+
+  "
+UPDATE ".PREFIX_TABLE."user_infos
+  SET template = 'yoga/dark'
+  WHERE template = 'yoga-dark'
+;",
+  "
+UPDATE ".PREFIX_TABLE."user_infos
+  SET template = 'yoga/clear'
+  WHERE template != 'yoga/dark'
+;",
+  "
+ALTER TABLE ".PREFIX_TABLE."user_infos
+  ADD COLUMN adviser enum('true','false') NOT NULL default 'false'
+;",
+  "
+ALTER TABLE ".PREFIX_TABLE."user_infos
+  ADD COLUMN enabled_high enum('true','false') NOT NULL default 'true'
+;",
+  "
+ALTER TABLE ".PREFIX_TABLE."categories
+  CHANGE COLUMN rank rank SMALLINT(5) UNSIGNED DEFAULT NULL
+;",
+  // configuration table
+  "
+UPDATE ".PREFIX_TABLE."config
+  SET value = 'yoga/clear'
+  WHERE param = 'default_template'
+;"
+  );
+
+foreach ($queries as $query)
+{
+  pwg_query($query);
+}
+
+//
+// Move rate, rate_anonymous and gallery_url from config file to database
+//
+$params = array(
+  'gallery_url' => array(
+    'http://demo.phpwebgallery.net',
+    'URL given in RSS feed'
+    ),
+  'rate' => array(
+    'true',
+    'Rating pictures feature is enabled'
+    ),
+  'rate_anonymous' => array(
+    'true',
+    'Rating pictures feature is also enabled for visitors'
+    )
+  );
+// Get real values from config file
+$conf_save = $conf;
+unset($conf);
+@include(PHPWG_ROOT_PATH. 'include/config_local.inc.php');
+if ( isset($conf['gallery_url']) )
+{
+  $params['gallery_url'][0] = $conf['gallery_url'];
+}
+if ( isset($conf['rate']) and is_bool($conf['rate']) )
+{
+  $params['rate'][0] = $conf['rate'] ? 'true' : 'false';
+}
+if ( isset($conf['rate_anonymous']) and is_bool($conf['rate_anonymous']) )
+{
+  $params['rate_anonymous'][0] = $conf['rate_anonymous'] ? 'true' : 'false';
+}
+$conf = $conf_save;
+
+// Do I already have them in DB ?
+$query = 'SELECT param FROM '.PREFIX_TABLE.'config';
+$result = pwg_query($query);
+while ($row = mysql_fetch_array($result))
+{
+  unset( $params[ $row['param'] ] );
+}
+
+// Perform the insert query
+foreach ($params as $param_key => $param_values)
+{
+  $query = '
+INSERT INTO '.PREFIX_TABLE.'config
+  (param,value,comment)
+  VALUES
+ ('."'$param_key','$param_values[0]','$param_values[1]')
+;";
+  pwg_query($query);
+}
+
+$query = "
+ALTER TABLE ".PREFIX_TABLE."config MODIFY COLUMN `value` TEXT;";
+pwg_query($query);
+
+
+//
+// replace gallery_description by page_banner
+//
+$query = '
+SELECT value
+  FROM '.PREFIX_TABLE.'config
+  WHERE param=\'gallery_title\'
+;';
+list($t) = array_from_query($query, 'value');
+
+$query = '
+SELECT value
+  FROM '.PREFIX_TABLE.'config
+  WHERE param=\'gallery_description\'
+;';
+list($d) = array_from_query($query, 'value');
+
+$page_banner='

'.$t.'

'.$d.'

'; +$page_banner=addslashes($page_banner); +$query = ' +INSERT INTO '.PREFIX_TABLE.'config + (param,value,comment) + VALUES + ( + \'page_banner\', + \''.$page_banner.'\', + \'html displayed on the top each page of your gallery\' + ) +;'; +pwg_query($query); + +$query = ' +DELETE FROM '.PREFIX_TABLE.'config + WHERE param=\'gallery_description\' +;'; +pwg_query($query); + +// +// configuration for notification by mail +// +$query = " +INSERT INTO ".CONFIG_TABLE." + (param,value,comment) + VALUES + ( + 'nbm_send_mail_as', + '', + 'Send mail as param value for notification by mail' + ), + ( + 'nbm_send_detailed_content', + 'true', + 'Send detailed content for notification by mail' + ), + ( + 'nbm_complementary_mail_content', + '', + 'Complementary mail content for notification by mail' + ) +;"; +pwg_query($query); + +// depending on the way the 1.5.0 was installed (from scratch or by upgrade) +// the database structure has small differences that should be corrected. + +$query = ' +ALTER TABLE '.PREFIX_TABLE.'users + CHANGE COLUMN password password varchar(32) default NULL +;'; +pwg_query($query); + +$to_keep = array('id', 'username', 'password', 'mail_address'); + +$query = ' +DESC '.PREFIX_TABLE.'users +;'; + +$result = pwg_query($query); + +while ($row = mysql_fetch_array($result)) +{ + if (!in_array($row['Field'], $to_keep)) + { + $query = ' +ALTER TABLE '.PREFIX_TABLE.'users + DROP COLUMN '.$row['Field'].' +;'; + pwg_query($query); + } +} + +// now we upgrade from 1.6.0 to 1.6.2 +include_once(PHPWG_ROOT_PATH.'install/upgrade_1.6.0.php'); +?> diff --git a/install/upgrade_1.6.0.php b/install/upgrade_1.6.0.php new file mode 100644 index 000000000..02cda6ce1 --- /dev/null +++ b/install/upgrade_1.6.0.php @@ -0,0 +1,58 @@ + diff --git a/install/upgrade_1.6.2.php b/install/upgrade_1.6.2.php new file mode 100644 index 000000000..44c479cfa --- /dev/null +++ b/install/upgrade_1.6.2.php @@ -0,0 +1,350 @@ +'), + array('&', '&') // <- this must be the last one + ); + +foreach ($replacements as $replacement) +{ + $query = ' +UPDATE '.PREFIX_TABLE.'comments + SET content = REPLACE(content, "'. + addslashes($replacement[0]). + '", "'. + addslashes($replacement[1]). + '") +;'; + pwg_query($query); +} + +load_conf_from_db(); + +$query = " +UPDATE ".USER_INFOS_TABLE." +SET + template = '".$conf['default_template']."', + nb_image_line = ".$conf['nb_image_line'].", + nb_line_page = ".$conf['nb_line_page'].", + language = '".$conf['default_language']."', + maxwidth = ". + (empty($conf['default_maxwidth']) ? "NULL" : $conf['default_maxwidth']). + ", + maxheight = ". + (empty($conf['default_maxheight']) ? "NULL" : $conf['default_maxheight']). + ", + recent_period = ".$conf['recent_period'].", + expand = '".boolean_to_string($conf['auto_expand'])."', + show_nb_comments = '".boolean_to_string($conf['show_nb_comments'])."', + show_nb_hits = '".boolean_to_string($conf['show_nb_hits'])."', + enabled_high = '".boolean_to_string( + (isset($conf['newuser_default_enabled_high']) ? + $conf['newuser_default_enabled_high'] : true) + ). + "' +WHERE + user_id = ".$conf['default_user_id'].";"; +pwg_query($query); + +$query = " +DELETE FROM ".CONFIG_TABLE." +WHERE + param IN +( + 'default_template', + 'nb_image_line', + 'nb_line_page', + 'default_language', + 'default_maxwidth', + 'default_maxheight', + 'recent_period', + 'auto_expand', + 'show_nb_comments', + 'show_nb_hits' +) +;"; +pwg_query($query); + +// now we upgrade from 1.7.0 +// include_once(PHPWG_ROOT_PATH.'install/upgrade_1.7.0.php'); +?> diff --git a/template/yoga/upgrade.tpl b/template/yoga/upgrade.tpl new file mode 100644 index 000000000..2d2b06505 --- /dev/null +++ b/template/yoga/upgrade.tpl @@ -0,0 +1,44 @@ + + + + + + PhpWebGallery : Upgrade to {RELEASE} + + + + +

Welcome to PhpWebGallery upgrade page.

+ +

This page proposes to upgrade your database corresponding to your old +version of PhpWebGallery to the current version. The upgrade assistant +thinks you are currently running a +release {introduction.CURRENT_RELEASE} (or equivalent).

+ +

Upgrade from release +{introduction.CURRENT_RELEASE} to {RELEASE}

+ + + +

Upgrade from version {upgrade.VERSION} to {RELEASE}

+ +

Statistics

+
    +
  • total upgrade time : {upgrade.TOTAL_TIME}
  • +
  • total SQL time : {upgrade.SQL_TIME}
  • +
  • SQL queries : {upgrade.NB_QUERIES}
  • +
+ + +

Upgrade informations

+ +
    + +
  • {upgrade.infos.info.CONTENT}
  • + +
+ + + + + diff --git a/upgrade.php b/upgrade.php new file mode 100644 index 000000000..b2ab1cded --- /dev/null +++ b/upgrade.php @@ -0,0 +1,316 @@ +'."\n"; +flush(); +// +-----------------------------------------------------------------------+ +// | functions | +// +-----------------------------------------------------------------------+ + +/** + * list all tables in an array + * + * @return array + */ +function get_tables() +{ + $tables = array(); + + $query = ' +SHOW TABLES +;'; + $result = mysql_query($query); + + while ($row = mysql_fetch_row($result)) + { + if (preg_match('/^'.PREFIX_TABLE.'/', $row[0])) + { + array_push($tables, $row[0]); + } + } + + return $tables; +} + +/** + * list all columns of each given table + * + * @return array of array + */ +function get_columns_of($tables) +{ + $columns_of = array(); + + foreach ($tables as $table) + { + $query = ' +DESC '.$table.' +;'; + $result = mysql_query($query); + + $columns_of[$table] = array(); + + while ($row = mysql_fetch_row($result)) + { + array_push($columns_of[$table], $row[0]); + } + } + + return $columns_of; +} + +/** + */ +function print_time($message) +{ + global $last_time; + + $new_time = get_moment(); + echo '
['.get_elapsed_time($last_time, $new_time).']';
+  echo ' '.$message;
+  echo '
'; + flush(); + $last_time = $new_time; +} + +// +-----------------------------------------------------------------------+ +// | playing zone | +// +-----------------------------------------------------------------------+ + +// echo implode('
', get_tables()); +// echo '
'; print_r(get_columns_of(get_tables())); echo '
'; + +// foreach (get_available_upgrade_ids() as $upgrade_id) +// { +// echo $upgrade_id, '
'; +// } + +// +-----------------------------------------------------------------------+ +// | template initialization | +// +-----------------------------------------------------------------------+ + +$template = new Template(PHPWG_ROOT_PATH.'template/yoga'); +$template->set_filenames(array('upgrade'=>'upgrade.tpl')); +$template->assign_vars(array('RELEASE'=>PHPWG_VERSION)); + +// +-----------------------------------------------------------------------+ +// | upgrade choice | +// +-----------------------------------------------------------------------+ + +if (!isset($_GET['version'])) +{ + // find the current release + $tables = get_tables(); + $columns_of = get_columns_of($tables); + + if (!in_array('param', $columns_of[PREFIX_TABLE.'config'])) + { + // we're in branch 1.3, important upgrade, isn't it? + if (in_array(PREFIX_TABLE.'user_category', $tables)) + { + $current_release = '1.3.1'; + } + else + { + $current_release = '1.3.0'; + } + } + else if (!in_array(PREFIX_TABLE.'user_cache', $tables)) + { + $current_release = '1.4.0'; + } + else if (!in_array(PREFIX_TABLE.'tags', $tables)) + { + $current_release = '1.5.0'; + } + else if (!in_array(PREFIX_TABLE.'history_summary', $tables)) + { + if (!in_array('auto_login_key', $columns_of[PREFIX_TABLE.'user_infos'])) + { + $current_release = '1.6.0'; + } + else + { + $current_release = '1.6.2'; + } + } + else + { + die('No upgrade required, the database structure is up to date'); + } + + $template->assign_block_vars( + 'introduction', + array( + 'CURRENT_RELEASE' => $current_release, + 'RUN_UPGRADE_URL' => + PHPWG_ROOT_PATH.'upgrade.php?version='.$current_release, + ) + ); +} + +// +-----------------------------------------------------------------------+ +// | upgrade launch | +// +-----------------------------------------------------------------------+ + +else +{ + $upgrade_file = PHPWG_ROOT_PATH.'install/upgrade_'.$_GET['version'].'.php'; + if (is_file($upgrade_file)) + { + $page['infos'] = array(); + $page['upgrade_start'] = get_moment(); + $conf['die_on_sql_error'] = false; + include($upgrade_file); + + // Available upgrades must be ignored after a fresh installation. To + // make PWG avoid upgrading, we must tell it upgrades have already been + // made. + list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); + define('CURRENT_DATE', $dbnow); + $datas = array(); + foreach (get_available_upgrade_ids() as $upgrade_id) + { + array_push( + $datas, + array( + 'id' => $upgrade_id, + 'applied' => CURRENT_DATE, + 'description' => 'upgrade included in migration', + ) + ); + } + mass_inserts( + UPGRADE_TABLE, + array_keys($datas[0]), + $datas + ); + + $page['upgrade_end'] = get_moment(); + + $template->assign_block_vars( + 'upgrade', + array( + 'VERSION' => $_GET['version'], + 'TOTAL_TIME' => get_elapsed_time( + $page['upgrade_start'], + $page['upgrade_end'] + ), + 'SQL_TIME' => number_format( + $page['queries_time'], + 3, + '.', + ' ' + ).' s', + 'NB_QUERIES' => $page['count_queries'] + ) + ); + + array_push( + $page['infos'], + '[security] delete files "upgrade.php", "install.php" and "install" +directory' + ); + + array_push( + $page['infos'], + 'in include/mysql.inc.php, remove +
+define(\'PHPWG_IN_UPGRADE\', true);
+
' + ); + + array_push( + $page['infos'], + 'Perform a maintenance check in [Administration>General>Maintenance] +if you encounter any problem.' + ); + + $template->assign_block_vars('upgrade.infos', array()); + + foreach ($page['infos'] as $info) + { + $template->assign_block_vars( + 'upgrade.infos.info', + array( + 'CONTENT' => $info, + ) + ); + } + + $query = ' +UPDATE '.USER_CACHE_TABLE.' + SET need_update = \'true\' +;'; + pwg_query($query); + } + else + { + die('Hacking attempt'); + } +} + +// +-----------------------------------------------------------------------+ +// | sending html code | +// +-----------------------------------------------------------------------+ + +$template->pparse('upgrade'); +?> -- cgit v1.2.3