diff options
author | plegall <plg@piwigo.org> | 2005-01-06 22:16:21 +0000 |
---|---|---|
committer | plegall <plg@piwigo.org> | 2005-01-06 22:16:21 +0000 |
commit | 79c440d8bbd9c36778d421e6348fa43091efaadf (patch) | |
tree | e7ec011ad5057e41d77f1768b86c524b817329d3 | |
parent | 22e0536a05bbb6bca313dd05225bc4bb1963e0dc (diff) |
- upgrade scripts added for releases 1.3.x
- my_error function moved from admin/include/functions.php to
include/functions.inc.php
- because MySQL temporary tables are not always authorized on creation, use
a temporary table name (with the current microsecond) on a non temporary
table (in mass_updates function)
- ability to retrieve distant full directories (usefull in upgrade scripts)
- global variables $count_queries and $queries_time moved into global array
$page
- get_cat_display_name displays category names in correct order : the one
given by uppercats
- function setup_style simplified
- default value for configuration parameter "show_nb_comments" set to false
(less queries by default)
git-svn-id: http://piwigo.org/svn/trunk@672 68402e56-0260-453c-a942-63ccdbb3a9ee
-rw-r--r-- | admin/include/functions.php | 78 | ||||
-rw-r--r-- | include/functions.inc.php | 43 | ||||
-rw-r--r-- | include/functions_category.inc.php | 13 | ||||
-rw-r--r-- | include/functions_user.inc.php | 5 | ||||
-rw-r--r-- | include/page_tail.php | 10 | ||||
-rw-r--r-- | install/config.sql | 2 | ||||
-rw-r--r-- | install/upgrade_1.3.0.php | 401 | ||||
-rw-r--r-- | install/upgrade_1.3.1.php | 363 | ||||
-rw-r--r-- | install/upgrade_1.3.2.php | 362 | ||||
-rw-r--r-- | install/upgrade_1.3.3.php | 362 | ||||
-rw-r--r-- | install/upgrade_1.3.4.php | 362 | ||||
-rw-r--r-- | upgrade.php | 187 |
12 files changed, 2129 insertions, 59 deletions
diff --git a/admin/include/functions.php b/admin/include/functions.php index d8aa31cc9..a90b8307e 100644 --- a/admin/include/functions.php +++ b/admin/include/functions.php @@ -767,22 +767,6 @@ function get_fs_directories($path, $recursive = true) return $dirs; } -// my_error returns (or send to standard output) the message concerning the -// error occured for the last mysql query. -function my_error($header, $echo = true) -{ - $error = $header.'<span style="font-weight:bold;">N°= '.mysql_errno(); - $error.= ' -->> '.mysql_error()."</span><br /><br />\n"; - if ($echo) - { - echo $error; - } - else - { - return $error; - } -} - /** * inserts multiple lines in a table * @@ -910,18 +894,21 @@ DESCRIBE '.$tablename.' array_push($columns, $column); } } + + $temporary_tablename = $tablename.'_'.micro_seconds(); + $query = ' -CREATE TEMPORARY TABLE '.$tablename.'_temporary +CREATE TABLE '.$temporary_tablename.' ( '.implode(",\n", $columns).', PRIMARY KEY (id) ) ;'; pwg_query($query); - mass_inserts($tablename.'_temporary', $all_fields, $datas); + mass_inserts($temporary_tablename, $all_fields, $datas); // update of images table by joining with temporary table $query = ' -UPDATE '.$tablename.' AS t1, '.$tablename.'_temporary AS t2 +UPDATE '.$tablename.' AS t1, '.$temporary_tablename.' AS t2 SET '.implode("\n , ", array_map( create_function('$s', 'return "t1.$s = t2.$s";') @@ -933,7 +920,7 @@ UPDATE '.$tablename.' AS t1, '.$tablename.'_temporary AS t2 ;'; pwg_query($query); $query = ' -DROP TABLE '.$tablename.'_temporary +DROP TABLE '.$temporary_tablename.' ;'; pwg_query($query); } @@ -1193,12 +1180,23 @@ SELECT id, dir $cat_dirs[$row['id']] = $row['dir']; } - // filling $uppercats_array : to each category id the uppercats list is - // associated - $uppercats_array = array(); + // caching galleries_url + $query = ' +SELECT id, galleries_url + FROM '.SITES_TABLE.' +;'; + $result = pwg_query($query); + $galleries_url = array(); + while ($row = mysql_fetch_array($result)) + { + $galleries_url[$row['id']] = $row['galleries_url']; + } + + // categories : id, site_id, uppercats + $categories = array(); $query = ' -SELECT id, uppercats +SELECT id, uppercats, site_id FROM '.CATEGORIES_TABLE.' WHERE id IN ( '.wordwrap(implode(', ', $cat_ids), 80, "\n").') @@ -1206,25 +1204,18 @@ SELECT id, uppercats $result = pwg_query($query); while ($row = mysql_fetch_array($result)) { - $uppercats_array[$row['id']] = $row['uppercats']; + array_push($categories, $row); } - $query = ' -SELECT galleries_url - FROM '.SITES_TABLE.' - WHERE id = 1 -'; - $row = mysql_fetch_array(pwg_query($query)); - $basedir = $row['galleries_url']; - // filling $cat_fulldirs $cat_fulldirs = array(); - foreach ($uppercats_array as $cat_id => $uppercats) + foreach ($categories as $category) { - $uppercats = str_replace(',', '/', $uppercats); - $cat_fulldirs[$cat_id] = $basedir.preg_replace('/(\d+)/e', - "\$cat_dirs['$1']", - $uppercats); + $uppercats = str_replace(',', '/', $category['uppercats']); + $cat_fulldirs[$category['id']] = $galleries_url[$category['site_id']]; + $cat_fulldirs[$category['id']].= preg_replace('/(\d+)/e', + "\$cat_dirs['$1']", + $uppercats); } return $cat_fulldirs; @@ -1317,4 +1308,15 @@ function get_fs($path, $recursive = true) } return $fs; } + +/** + * stupidly returns the current microsecond since Unix epoch + */ +function micro_seconds() +{ + $t1 = explode(' ', microtime()); + $t2 = explode('.', $t1[0]); + $t2 = $t1[1].substr($t2[1], 0, 6); + return $t2; +} ?> diff --git a/include/functions.inc.php b/include/functions.inc.php index 999b4f8b8..c7f42ab0c 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -486,21 +486,31 @@ function pwg_write_debug() function pwg_query($query) { - global $conf,$count_queries,$queries_time; + global $conf,$page; $start = get_moment(); - $result = mysql_query($query); + $result = mysql_query($query) or my_error($query."\n"); $time = get_moment() - $start; - $count_queries++; - $queries_time+= $time; + + if (!isset($page['count_queries'])) + { + $page['count_queries'] = 0; + $page['queries_time'] = 0; + } + + $page['count_queries']++; + $page['queries_time']+= $time; if ($conf['show_queries']) { $output = ''; - $output.= '<pre>['.$count_queries.'] '."\n".$query; - $output.= "\n".'(this query time : '.number_format( $time, 3, '.', ' ').' s)</b>'; - $output.= "\n".'(total SQL time : '.number_format( $queries_time, 3, '.', ' ').' s)'; + $output.= '<pre>['.$page['count_queries'].'] '; + $output.= "\n".$query; + $output.= "\n".'(this query time : '; + $output.= number_format($time, 3, '.', ' ').' s)</b>'; + $output.= "\n".'(total SQL time : '; + $output.= number_format($page['queries_time'], 3, '.', ' ').' s)'; $output.= '</pre>'; echo $output; @@ -624,4 +634,23 @@ function get_thumbnail_src($path, $tn_ext = '') return $src; } + +// my_error returns (or send to standard output) the message concerning the +// error occured for the last mysql query. +function my_error($header, $echo = true) +{ + $error = '<pre>'; + $error.= $header; + $error.= '[mysql error '.mysql_errno().'] '; + $error.= mysql_error(); + $error.= '</pre>'; + if ($echo) + { + echo $error; + } + else + { + return $error; + } +} ?> diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php index 287075d43..cb532c01a 100644 --- a/include/functions_category.inc.php +++ b/include/functions_category.inc.php @@ -221,18 +221,23 @@ SELECT '.implode(',', $infos).' } $cat['comment'] = nl2br($cat['comment']); - $cat['name'] = array(); - + $names = array(); $query = ' SELECT name,id FROM '.CATEGORIES_TABLE.' WHERE id IN ('.$cat['uppercats'].') - ORDER BY id ASC ;'; $result = pwg_query($query); while($row = mysql_fetch_array($result)) { - $cat['name'][$row['id']] = $row['name']; + $names[$row['id']] = $row['name']; + } + + // category names must be in the same order than uppercats list + $cat['name'] = array(); + foreach (explode(',', $cat['uppercats']) as $cat_id) + { + $cat['name'][$cat_id] = $names[$cat_id]; } return $cat; diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php index 750f4602f..2a44c785a 100644 --- a/include/functions_user.inc.php +++ b/include/functions_user.inc.php @@ -208,10 +208,7 @@ function check_login_authorization($guest_allowed = true) function setup_style($style) { - $template_path = 'template/' ; - $template_name = $style ; - $template = new Template(PHPWG_ROOT_PATH . $template_path . $template_name); - return $template; + return new Template(PHPWG_ROOT_PATH.'template/'.$style); } function getuserdata($user) diff --git a/include/page_tail.php b/include/page_tail.php index e8b4ae349..f5c5eaf3f 100644 --- a/include/page_tail.php +++ b/include/page_tail.php @@ -42,17 +42,17 @@ if ($conf['show_gt']) { $time = get_elapsed_time($t2, get_moment()); - if (!isset($count_queries)) + if (!isset($page['count_queries'])) { - $count_queries = 0; - $queries_time = 0; + $page['count_queries'] = 0; + $page['queries_time'] = 0; } $template->assign_block_vars( 'debug', array('TIME' => $time, - 'NB_QUERIES' => $count_queries, - 'SQL_TIME' => number_format($queries_time, 3, '.', ' ').' s')); + 'NB_QUERIES' => $page['count_queries'], + 'SQL_TIME' => number_format($page['queries_time'],3,'.',' ').' s')); } // diff --git a/install/config.sql b/install/config.sql index 0a356516a..77439982e 100644 --- a/install/config.sql +++ b/install/config.sql @@ -20,7 +20,7 @@ INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('nb_image_line',' INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('nb_line_page','3','Number of rows displayed per page'); INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('recent_period','7','Period within which pictures are displayed as new (in days)'); INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('auto_expand','false','Auto expand of the category tree'); -INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('show_nb_comments','true','Show the number of comments under the thumbnails'); +INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('show_nb_comments','false','Show the number of comments under the thumbnails'); INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('use_iptc','false','Use IPTC data during database synchronization with files metadata'); INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('use_exif','true','Use EXIF data during database synchronization with files metadata'); INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('show_iptc','false','Show IPTC metadata on picture.php if asked by user'); diff --git a/install/upgrade_1.3.0.php b/install/upgrade_1.3.0.php new file mode 100644 index 000000000..1beaeb651 --- /dev/null +++ b/install/upgrade_1.3.0.php @@ -0,0 +1,401 @@ +<?php +// +-----------------------------------------------------------------------+ +// | PhpWebGallery - a PHP based picture gallery | +// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | +// | Copyright (C) 2003-2004 PhpWebGallery Team - http://phpwebgallery.net | +// +-----------------------------------------------------------------------+ +// | branch : BSF (Best So Far) +// | file : $RCSfile$ +// | last update : $Date$ +// | last modifier : $Author$ +// | revision : $Revision$ +// +-----------------------------------------------------------------------+ +// | This program is free software; you can redistribute it and/or modify | +// | it under the terms of the GNU General Public License as published by | +// | the Free Software Foundation | +// | | +// | This program is distributed in the hope that it will be useful, but | +// | WITHOUT ANY WARRANTY; without even the implied warranty of | +// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | +// | General Public License for more details. | +// | | +// | You should have received a copy of the GNU General Public License | +// | along with this program; if not, write to the Free Software | +// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | +// | USA. | +// +-----------------------------------------------------------------------+ + +if (!defined('IN_UPGRADE') or !IN_UPGRADE) +{ + die('Hacking attempt!'); +} + +$last_time = get_moment(); + +// 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', + ADD COLUMN commentable enum('true','false') NOT NULL default 'true', + ADD COLUMN uppercats varchar(255) NOT NULL default '', + ADD COLUMN global_rank varchar(255) default NULL, + 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, + 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 '', + ADD COLUMN path varchar(255) NOT NULL default '', + ADD COLUMN date_metadata_update date default NULL, + ADD COLUMN average_rate float(5,2) unsigned default NULL, + ADD COLUMN representative_ext varchar(4) default NULL, + DROP INDEX storage_category_id, + ADD INDEX images_i1 (storage_category_id), + ADD INDEX images_i2 (date_available), + ADD INDEX images_i3 (average_rate), + ADD INDEX images_i4 (hit), + 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, + ADD UNIQUE sites_ui1 (galleries_url) +;", + + " +ALTER TABLE phpwebgallery_users + DROP COLUMN long_period, + DROP COLUMN short_period, + ADD COLUMN recent_period tinyint(3) unsigned NOT NULL default '7', + DROP INDEX username, + 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); +} + +$new_time = get_moment(); +echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; +echo ' Basic database structure upgrade done</pre>'; +flush(); +$last_time = $new_time; + +execute_sqlfile(PHPWG_ROOT_PATH.'install/config.sql', + 'phpwebgallery_', + PREFIX_TABLE); + +$queries = array( + " +UPDATE phpwebgallery_config + SET value = '".$save['prefix_thumbnail']."' + WHERE param = 'prefix_thumbnail' +;", + + " +UPDATE phpwebgallery_config + SET value = '".$save['mail_webmaster']."' + WHERE param = 'mail_webmaster' +;" + ); + +foreach ($queries as $query) +{ + $query = str_replace('phpwebgallery_', PREFIX_TABLE, $query); + pwg_query($query); +} + +$new_time = get_moment(); +echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; +echo ' Saved configuration information restored</pre>'; +flush(); +$last_time = $new_time; + +// filling the new column categories.uppercats +$id_uppercats = array(); + +$query = ' +SELECT id, id_uppercat + FROM '.CATEGORIES_TABLE.' +;'; +$result = pwg_query($query); +while ($row = mysql_fetch_array($result)) +{ + if (!isset($row['id_uppercat']) or $row['id_uppercat'] == '') + { + $row['id_uppercat'] = 'NULL'; + } + $id_uppercats[$row['id']] = $row['id_uppercat']; +} + +$datas = array(); + +foreach (array_keys($id_uppercats) as $id) +{ + $data = array(); + $data['id'] = $id; + $uppercats = array(); + + array_push($uppercats, $id); + while (isset($id_uppercats[$id]) and $id_uppercats[$id] != 'NULL') + { + array_push($uppercats, $id_uppercats[$id]); + $id = $id_uppercats[$id]; + } + $data['uppercats'] = implode(',', array_reverse($uppercats)); + + array_push($datas, $data); +} + +$fields = array('primary' => array('id'), 'update' => array('uppercats')); +mass_updates(CATEGORIES_TABLE, $fields, $datas); + +$new_time = get_moment(); +echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; +echo ' filling the new column categories.uppercats</pre>'; +flush(); +$last_time = $new_time; + +// refresh calculated datas +ordering(); +update_global_rank(); +update_category(); + +$new_time = get_moment(); +echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; +echo ' Calculated data updated (categories.rank, categories.global_rank, +categories.date_last, categories.representative_picture_id, +categories.nb_images)</pre>'; +flush(); +$last_time = $new_time; + +// 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); +} + +$new_time = get_moment(); +echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; +echo ' new column images.path filled</pre>'; +flush(); +$last_time = $new_time; + +// 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); +} + +$new_time = get_moment(); +echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; +echo ' all sub-categories of private categories become private</pre>'; +flush(); +$last_time = $new_time; + +$infos = array( + '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 +<pre style="background-color:lightgray">?></pre> +insert +<pre style="background-color:lightgray">define(\'PHPWG_INSTALLED\', true);<pre>' + + ); + +?>
\ 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..f6395bc45 --- /dev/null +++ b/install/upgrade_1.3.1.php @@ -0,0 +1,363 @@ +<?php +// +-----------------------------------------------------------------------+ +// | PhpWebGallery - a PHP based picture gallery | +// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | +// | Copyright (C) 2003-2004 PhpWebGallery Team - http://phpwebgallery.net | +// +-----------------------------------------------------------------------+ +// | branch : BSF (Best So Far) +// | file : $RCSfile$ +// | last update : $Date$ +// | last modifier : $Author$ +// | revision : $Revision$ +// +-----------------------------------------------------------------------+ +// | This program is free software; you can redistribute it and/or modify | +// | it under the terms of the GNU General Public License as published by | +// | the Free Software Foundation | +// | | +// | This program is distributed in the hope that it will be useful, but | +// | WITHOUT ANY WARRANTY; without even the implied warranty of | +// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | +// | General Public License for more details. | +// | | +// | You should have received a copy of the GNU General Public License | +// | along with this program; if not, write to the Free Software | +// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | +// | USA. | +// +-----------------------------------------------------------------------+ + +if (!defined('IN_UPGRADE') or !IN_UPGRADE) +{ + die('Hacking attempt!'); +} + +$last_time = get_moment(); + +// 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', + ADD COLUMN commentable enum('true','false') NOT NULL default 'true', + ADD COLUMN global_rank varchar(255) default NULL, + DROP INDEX id, + DROP INDEX id_uppercat, + 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, + 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 + DROP INDEX image_id, + DROP INDEX category_id, + 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 '', + ADD COLUMN path varchar(255) NOT NULL default '', + ADD COLUMN date_metadata_update date default NULL, + ADD COLUMN average_rate float(5,2) unsigned default NULL, + ADD COLUMN representative_ext varchar(4) default NULL, + DROP INDEX storage_category_id, + ADD INDEX images_i1 (storage_category_id), + ADD INDEX images_i2 (date_available), + ADD INDEX images_i3 (average_rate), + ADD INDEX images_i4 (hit), + 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, + ADD UNIQUE sites_ui1 (galleries_url) +;", + + " +DROP TABLE phpwebgallery_user_category +;", + + " +ALTER TABLE phpwebgallery_users + DROP COLUMN long_period, + DROP COLUMN short_period, + DROP COLUMN forbidden_categories, + ADD COLUMN recent_period tinyint(3) unsigned NOT NULL default '7', + DROP INDEX username, + 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); +} + +$new_time = get_moment(); +echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; +echo ' Basic database structure upgrade done</pre>'; +flush(); +$last_time = $new_time; + +execute_sqlfile(PHPWG_ROOT_PATH.'install/config.sql', + 'phpwebgallery_', + PREFIX_TABLE); + +$queries = array( + " +UPDATE phpwebgallery_config + SET value = '".$save['prefix_thumbnail']."' + WHERE param = 'prefix_thumbnail' +;", + + " +UPDATE phpwebgallery_config + SET value = '".$save['mail_webmaster']."' + WHERE param = 'mail_webmaster' +;" + ); + +foreach ($queries as $query) +{ + $query = str_replace('phpwebgallery_', PREFIX_TABLE, $query); + pwg_query($query); +} + +$new_time = get_moment(); +echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; +echo ' Saved configuration information restored</pre>'; +flush(); +$last_time = $new_time; + +ordering(); +update_global_rank(); +update_category(); + +$new_time = get_moment(); +echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; +echo ' Calculated data updated (categories.rank, categories.global_rank, +categories.date_last, categories.representative_picture_id, +categories.nb_images)</pre>'; +flush(); +$last_time = $new_time; + +// 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); +} + +$new_time = get_moment(); +echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; +echo ' new column images.path filled</pre>'; +flush(); +$last_time = $new_time; + +// 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); +} + +$new_time = get_moment(); +echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; +echo ' all sub-categories of private categories become private</pre>'; +flush(); +$last_time = $new_time; + +$infos = array( + '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 +<pre style="background-color:lightgray">?></pre> +insert +<pre style="background-color:lightgray">define(\'PHPWG_INSTALLED\', true);<pre>' + + ); + +?>
\ No newline at end of file diff --git a/install/upgrade_1.3.2.php b/install/upgrade_1.3.2.php new file mode 100644 index 000000000..179324265 --- /dev/null +++ b/install/upgrade_1.3.2.php @@ -0,0 +1,362 @@ +<?php +// +-----------------------------------------------------------------------+ +// | PhpWebGallery - a PHP based picture gallery | +// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | +// | Copyright (C) 2003-2004 PhpWebGallery Team - http://phpwebgallery.net | +// +-----------------------------------------------------------------------+ +// | branch : BSF (Best So Far) +// | file : $RCSfile$ +// | last update : $Date$ +// | last modifier : $Author$ +// | revision : $Revision$ +// +-----------------------------------------------------------------------+ +// | This program is free software; you can redistribute it and/or modify | +// | it under the terms of the GNU General Public License as published by | +// | the Free Software Foundation | +// | | +// | This program is distributed in the hope that it will be useful, but | +// | WITHOUT ANY WARRANTY; without even the implied warranty of | +// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | +// | General Public License for more details. | +// | | +// | You should have received a copy of the GNU General Public License | +// | along with this program; if not, write to the Free Software | +// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | +// | USA. | +// +-----------------------------------------------------------------------+ + +if (!defined('IN_UPGRADE') or !IN_UPGRADE) +{ + die('Hacking attempt!'); +} + +$last_time = get_moment(); + +// 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', + ADD COLUMN commentable enum('true','false') NOT NULL default 'true', + ADD COLUMN global_rank varchar(255) default NULL, + DROP INDEX id_uppercat, + 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, + 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 + DROP INDEX image_id, + DROP INDEX category_id, + 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 '', + ADD COLUMN path varchar(255) NOT NULL default '', + ADD COLUMN date_metadata_update date default NULL, + ADD COLUMN average_rate float(5,2) unsigned default NULL, + ADD COLUMN representative_ext varchar(4) default NULL, + DROP INDEX storage_category_id, + ADD INDEX images_i1 (storage_category_id), + ADD INDEX images_i2 (date_available), + ADD INDEX images_i3 (average_rate), + ADD INDEX images_i4 (hit), + 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, + ADD UNIQUE sites_ui1 (galleries_url) +;", + + " +DROP TABLE phpwebgallery_user_category +;", + + " +ALTER TABLE phpwebgallery_users + DROP COLUMN long_period, + DROP COLUMN short_period, + DROP COLUMN forbidden_categories, + ADD COLUMN recent_period tinyint(3) unsigned NOT NULL default '7', + DROP INDEX username, + 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); +} + +$new_time = get_moment(); +echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; +echo ' Basic database structure upgrade done</pre>'; +flush(); +$last_time = $new_time; + +execute_sqlfile(PHPWG_ROOT_PATH.'install/config.sql', + 'phpwebgallery_', + PREFIX_TABLE); + +$queries = array( + " +UPDATE phpwebgallery_config + SET value = '".$save['prefix_thumbnail']."' + WHERE param = 'prefix_thumbnail' +;", + + " +UPDATE phpwebgallery_config + SET value = '".$save['mail_webmaster']."' + WHERE param = 'mail_webmaster' +;" + ); + +foreach ($queries as $query) +{ + $query = str_replace('phpwebgallery_', PREFIX_TABLE, $query); + pwg_query($query); +} + +$new_time = get_moment(); +echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; +echo ' Saved configuration information restored</pre>'; +flush(); +$last_time = $new_time; + +ordering(); +update_global_rank(); +update_category(); + +$new_time = get_moment(); +echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; +echo ' Calculated data updated (categories.rank, categories.global_rank, +categories.date_last, categories.representative_picture_id, +categories.nb_images)</pre>'; +flush(); +$last_time = $new_time; + +// 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); +} + +$new_time = get_moment(); +echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; +echo ' new column images.path filled</pre>'; +flush(); +$last_time = $new_time; + +// 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); +} + +$new_time = get_moment(); +echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; +echo ' all sub-categories of private categories become private</pre>'; +flush(); +$last_time = $new_time; + +$infos = array( + '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 +<pre style="background-color:lightgray">?></pre> +insert +<pre style="background-color:lightgray">define(\'PHPWG_INSTALLED\', true);<pre>' + + ); + +?>
\ No newline at end of file diff --git a/install/upgrade_1.3.3.php b/install/upgrade_1.3.3.php new file mode 100644 index 000000000..179324265 --- /dev/null +++ b/install/upgrade_1.3.3.php @@ -0,0 +1,362 @@ +<?php +// +-----------------------------------------------------------------------+ +// | PhpWebGallery - a PHP based picture gallery | +// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | +// | Copyright (C) 2003-2004 PhpWebGallery Team - http://phpwebgallery.net | +// +-----------------------------------------------------------------------+ +// | branch : BSF (Best So Far) +// | file : $RCSfile$ +// | last update : $Date$ +// | last modifier : $Author$ +// | revision : $Revision$ +// +-----------------------------------------------------------------------+ +// | This program is free software; you can redistribute it and/or modify | +// | it under the terms of the GNU General Public License as published by | +// | the Free Software Foundation | +// | | +// | This program is distributed in the hope that it will be useful, but | +// | WITHOUT ANY WARRANTY; without even the implied warranty of | +// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | +// | General Public License for more details. | +// | | +// | You should have received a copy of the GNU General Public License | +// | along with this program; if not, write to the Free Software | +// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | +// | USA. | +// +-----------------------------------------------------------------------+ + +if (!defined('IN_UPGRADE') or !IN_UPGRADE) +{ + die('Hacking attempt!'); +} + +$last_time = get_moment(); + +// 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', + ADD COLUMN commentable enum('true','false') NOT NULL default 'true', + ADD COLUMN global_rank varchar(255) default NULL, + DROP INDEX id_uppercat, + 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, + 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 + DROP INDEX image_id, + DROP INDEX category_id, + 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 '', + ADD COLUMN path varchar(255) NOT NULL default '', + ADD COLUMN date_metadata_update date default NULL, + ADD COLUMN average_rate float(5,2) unsigned default NULL, + ADD COLUMN representative_ext varchar(4) default NULL, + DROP INDEX storage_category_id, + ADD INDEX images_i1 (storage_category_id), + ADD INDEX images_i2 (date_available), + ADD INDEX images_i3 (average_rate), + ADD INDEX images_i4 (hit), + 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, + ADD UNIQUE sites_ui1 (galleries_url) +;", + + " +DROP TABLE phpwebgallery_user_category +;", + + " +ALTER TABLE phpwebgallery_users + DROP COLUMN long_period, + DROP COLUMN short_period, + DROP COLUMN forbidden_categories, + ADD COLUMN recent_period tinyint(3) unsigned NOT NULL default '7', + DROP INDEX username, + 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); +} + +$new_time = get_moment(); +echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; +echo ' Basic database structure upgrade done</pre>'; +flush(); +$last_time = $new_time; + +execute_sqlfile(PHPWG_ROOT_PATH.'install/config.sql', + 'phpwebgallery_', + PREFIX_TABLE); + +$queries = array( + " +UPDATE phpwebgallery_config + SET value = '".$save['prefix_thumbnail']."' + WHERE param = 'prefix_thumbnail' +;", + + " +UPDATE phpwebgallery_config + SET value = '".$save['mail_webmaster']."' + WHERE param = 'mail_webmaster' +;" + ); + +foreach ($queries as $query) +{ + $query = str_replace('phpwebgallery_', PREFIX_TABLE, $query); + pwg_query($query); +} + +$new_time = get_moment(); +echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; +echo ' Saved configuration information restored</pre>'; +flush(); +$last_time = $new_time; + +ordering(); +update_global_rank(); +update_category(); + +$new_time = get_moment(); +echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; +echo ' Calculated data updated (categories.rank, categories.global_rank, +categories.date_last, categories.representative_picture_id, +categories.nb_images)</pre>'; +flush(); +$last_time = $new_time; + +// 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); +} + +$new_time = get_moment(); +echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; +echo ' new column images.path filled</pre>'; +flush(); +$last_time = $new_time; + +// 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); +} + +$new_time = get_moment(); +echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; +echo ' all sub-categories of private categories become private</pre>'; +flush(); +$last_time = $new_time; + +$infos = array( + '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 +<pre style="background-color:lightgray">?></pre> +insert +<pre style="background-color:lightgray">define(\'PHPWG_INSTALLED\', true);<pre>' + + ); + +?>
\ No newline at end of file diff --git a/install/upgrade_1.3.4.php b/install/upgrade_1.3.4.php new file mode 100644 index 000000000..179324265 --- /dev/null +++ b/install/upgrade_1.3.4.php @@ -0,0 +1,362 @@ +<?php +// +-----------------------------------------------------------------------+ +// | PhpWebGallery - a PHP based picture gallery | +// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | +// | Copyright (C) 2003-2004 PhpWebGallery Team - http://phpwebgallery.net | +// +-----------------------------------------------------------------------+ +// | branch : BSF (Best So Far) +// | file : $RCSfile$ +// | last update : $Date$ +// | last modifier : $Author$ +// | revision : $Revision$ +// +-----------------------------------------------------------------------+ +// | This program is free software; you can redistribute it and/or modify | +// | it under the terms of the GNU General Public License as published by | +// | the Free Software Foundation | +// | | +// | This program is distributed in the hope that it will be useful, but | +// | WITHOUT ANY WARRANTY; without even the implied warranty of | +// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | +// | General Public License for more details. | +// | | +// | You should have received a copy of the GNU General Public License | +// | along with this program; if not, write to the Free Software | +// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | +// | USA. | +// +-----------------------------------------------------------------------+ + +if (!defined('IN_UPGRADE') or !IN_UPGRADE) +{ + die('Hacking attempt!'); +} + +$last_time = get_moment(); + +// 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', + ADD COLUMN commentable enum('true','false') NOT NULL default 'true', + ADD COLUMN global_rank varchar(255) default NULL, + DROP INDEX id_uppercat, + 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, + 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 + DROP INDEX image_id, + DROP INDEX category_id, + 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 '', + ADD COLUMN path varchar(255) NOT NULL default '', + ADD COLUMN date_metadata_update date default NULL, + ADD COLUMN average_rate float(5,2) unsigned default NULL, + ADD COLUMN representative_ext varchar(4) default NULL, + DROP INDEX storage_category_id, + ADD INDEX images_i1 (storage_category_id), + ADD INDEX images_i2 (date_available), + ADD INDEX images_i3 (average_rate), + ADD INDEX images_i4 (hit), + 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, + ADD UNIQUE sites_ui1 (galleries_url) +;", + + " +DROP TABLE phpwebgallery_user_category +;", + + " +ALTER TABLE phpwebgallery_users + DROP COLUMN long_period, + DROP COLUMN short_period, + DROP COLUMN forbidden_categories, + ADD COLUMN recent_period tinyint(3) unsigned NOT NULL default '7', + DROP INDEX username, + 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); +} + +$new_time = get_moment(); +echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; +echo ' Basic database structure upgrade done</pre>'; +flush(); +$last_time = $new_time; + +execute_sqlfile(PHPWG_ROOT_PATH.'install/config.sql', + 'phpwebgallery_', + PREFIX_TABLE); + +$queries = array( + " +UPDATE phpwebgallery_config + SET value = '".$save['prefix_thumbnail']."' + WHERE param = 'prefix_thumbnail' +;", + + " +UPDATE phpwebgallery_config + SET value = '".$save['mail_webmaster']."' + WHERE param = 'mail_webmaster' +;" + ); + +foreach ($queries as $query) +{ + $query = str_replace('phpwebgallery_', PREFIX_TABLE, $query); + pwg_query($query); +} + +$new_time = get_moment(); +echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; +echo ' Saved configuration information restored</pre>'; +flush(); +$last_time = $new_time; + +ordering(); +update_global_rank(); +update_category(); + +$new_time = get_moment(); +echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; +echo ' Calculated data updated (categories.rank, categories.global_rank, +categories.date_last, categories.representative_picture_id, +categories.nb_images)</pre>'; +flush(); +$last_time = $new_time; + +// 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); +} + +$new_time = get_moment(); +echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; +echo ' new column images.path filled</pre>'; +flush(); +$last_time = $new_time; + +// 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); +} + +$new_time = get_moment(); +echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; +echo ' all sub-categories of private categories become private</pre>'; +flush(); +$last_time = $new_time; + +$infos = array( + '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 +<pre style="background-color:lightgray">?></pre> +insert +<pre style="background-color:lightgray">define(\'PHPWG_INSTALLED\', true);<pre>' + + ); + +?>
\ No newline at end of file diff --git a/upgrade.php b/upgrade.php new file mode 100644 index 000000000..748832617 --- /dev/null +++ b/upgrade.php @@ -0,0 +1,187 @@ +<?php +// +-----------------------------------------------------------------------+ +// | PhpWebGallery - a PHP based picture gallery | +// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | +// | Copyright (C) 2003-2004 PhpWebGallery Team - http://phpwebgallery.net | +// +-----------------------------------------------------------------------+ +// | branch : BSF (Best So Far) +// | file : $RCSfile$ +// | last update : $Date$ +// | last modifier : $Author$ +// | revision : $Revision$ +// +-----------------------------------------------------------------------+ +// | This program is free software; you can redistribute it and/or modify | +// | it under the terms of the GNU General Public License as published by | +// | the Free Software Foundation | +// | | +// | This program is distributed in the hope that it will be useful, but | +// | WITHOUT ANY WARRANTY; without even the implied warranty of | +// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | +// | General Public License for more details. | +// | | +// | You should have received a copy of the GNU General Public License | +// | along with this program; if not, write to the Free Software | +// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | +// | USA. | +// +-----------------------------------------------------------------------+ + +define('IN_UPGRADE', true); +define('PHPWG_ROOT_PATH', './'); + +include_once(PHPWG_ROOT_PATH.'include/functions.inc.php'); +include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); +include(PHPWG_ROOT_PATH.'include/template.php'); +include(PHPWG_ROOT_PATH.'include/mysql.inc.php'); +include_once(PHPWG_ROOT_PATH.'include/constants.php'); +define('PREFIX_TABLE', $table_prefix); + +$conf['show_queries'] = false; + +// Database connection +mysql_connect( $dbhost, $dbuser, $dbpasswd ) +or die ( "Could not connect to database server" ); +mysql_select_db( $dbname ) +or die ( "Could not connect to database" ); +// +-----------------------------------------------------------------------+ +// | tricky output | +// +-----------------------------------------------------------------------+ +echo '<!-- This is an HTML comment given in order to make IE outputs'; +echo ' the code.'."\n"; +echo ' Indeed, IE doesn\'t start to send output until a limit'; +echo ' of XXX bytes '."\n"; +echo str_repeat( ' ', 80 )."\n"; +echo str_repeat( ' ', 80 )."\n"; +echo str_repeat( ' ', 80 )."\n"; +echo '-->'."\n"; +flush(); +// +-----------------------------------------------------------------------+ +// | functions | +// +-----------------------------------------------------------------------+ + +/** + * loads an sql file and executes all queries + * + * Before executing a query, $replaced is... replaced by $replacing. This is + * useful when the SQL file contains generic words. Drop table queries are + * not executed. + * + * @param string filepath + * @param string replaced + * @param string replacing + * @return void + */ +function execute_sqlfile($filepath, $replaced, $replacing) +{ + $sql_lines = file($filepath); + $query = ''; + foreach ($sql_lines as $sql_line) + { + $sql_line = trim($sql_line); + if (preg_match('/(^--|^$)/', $sql_line)) + { + continue; + } + $query.= ' '.$sql_line; + // if we reached the end of query, we execute it and reinitialize the + // variable "query" + if (preg_match('/;$/', $sql_line)) + { + $query = trim($query); + $query = str_replace($replaced, $replacing, $query); + // we don't execute "DROP TABLE" queries + if (!preg_match('/^DROP TABLE/i', $query)) + { + mysql_query($query); + } + $query = ''; + } + } +} +// +-----------------------------------------------------------------------+ +// | template initialization | +// +-----------------------------------------------------------------------+ +$template = setup_style('default'); +$template->set_filenames(array('upgrade'=>'upgrade.tpl')); +$template->assign_vars(array('RELEASE'=>PHPWG_VERSION)); +// +-----------------------------------------------------------------------+ +// | versions upgradable | +// +-----------------------------------------------------------------------+ +$versions = array(); +$path = PHPWG_ROOT_PATH.'install'; +if ($contents = opendir($path)) +{ + while (($node = readdir($contents)) !== false) + { + if (is_file($path.'/'.$node) + and preg_match('/^upgrade_(.*?)\.php$/', $node, $match)) + { + array_push($versions, $match[1]); + } + } +} +natcasesort($versions); +// +-----------------------------------------------------------------------+ +// | upgrade choice | +// +-----------------------------------------------------------------------+ +if (!isset($_GET['version'])) +{ + $template->assign_block_vars('choices', array()); + foreach ($versions as $version) + { + $template->assign_block_vars( + 'choices.choice', + array( + 'URL' => PHPWG_ROOT_PATH.'upgrade.php?version='.$version, + 'VERSION' => $version + )); + } +} +// +-----------------------------------------------------------------------+ +// | upgrade launch | +// +-----------------------------------------------------------------------+ +else +{ + $upgrade_file = $path.'/upgrade_'.$_GET['version'].'.php'; + if (is_file($upgrade_file)) + { + $page['upgrade_start'] = get_moment(); + include($upgrade_file); + $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'] + )); + + if (!isset($infos)) + { + $infos = array(); + } + array_push( + $infos, + '[security] delete files "upgrade.php", "install.php" and "install" +directory'); + + $template->assign_block_vars('upgrade.infos', array()); + + foreach ($infos as $info) + { + $template->assign_block_vars('upgrade.infos.info', + array('CONTENT' => $info)); + } + } + else + { + die('Hacking attempt'); + } +} +// +-----------------------------------------------------------------------+ +// | sending html code | +// +-----------------------------------------------------------------------+ +$template->pparse('upgrade'); +?>
\ No newline at end of file |