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
This commit is contained in:
plegall 2007-03-28 22:06:13 +00:00
parent 7c43a3c62d
commit 0d5216267c
8 changed files with 2273 additions and 0 deletions

130
install/upgrade_1.3.0.php Normal file
View file

@ -0,0 +1,130 @@
<?php
// +-----------------------------------------------------------------------+
// | PhpWebGallery - a PHP based picture gallery |
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
// | branch : BSF (Best So Far)
// | file : $RCSfile$
// | last update : $Date: 2005-01-08 00:10:51 +0100 (sam, 08 jan 2005) $
// | last modifier : $Author: plg $
// | revision : $Revision: 675 $
// +-----------------------------------------------------------------------+
// | 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. |
// +-----------------------------------------------------------------------+
/**
* Upgrade from 1.3.0 to 1.3.1
*/
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!');
}
}
$queries = array(
"
ALTER TABLE phpwebgallery_categories
ADD COLUMN uppercats varchar(255) NOT NULL default ''
;",
"
CREATE TABLE phpwebgallery_user_category (
user_id smallint(5) unsigned NOT NULL default '0'
)
;",
"
ALTER TABLE phpwebgallery_categories
ADD INDEX id (id)
;",
"
ALTER TABLE phpwebgallery_categories
ADD INDEX id_uppercat (id_uppercat)
;",
"
ALTER TABLE phpwebgallery_image_category
ADD INDEX category_id (category_id)
;",
"
ALTER TABLE phpwebgallery_image_category
ADD INDEX image_id (image_id)
;",
);
foreach ($queries as $query)
{
$query = str_replace('phpwebgallery_', PREFIX_TABLE, $query);
pwg_query($query);
}
// 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);
}
mass_updates(
CATEGORIES_TABLE,
array(
'primary' => 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');
?>

606
install/upgrade_1.3.1.php Normal file
View file

@ -0,0 +1,606 @@
<?php
// +-----------------------------------------------------------------------+
// | PhpWebGallery - a PHP based picture gallery |
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
// | branch : BSF (Best So Far)
// | file : $RCSfile$
// | last update : $Date: 2005-01-08 00:10:51 +0100 (sam, 08 jan 2005) $
// | last modifier : $Author: plg $
// | revision : $Revision: 675 $
// +-----------------------------------------------------------------------+
// | 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. |
// +-----------------------------------------------------------------------+
/**
* Upgrade from 1.3.x (x >= 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
<pre style="background-color:lightgray">?&gt;</pre>
insert
<pre style="background-color:lightgray">define(\'PHPWG_INSTALLED\', true);<pre>'
)
);
// now we upgrade from 1.4.0
include_once(PHPWG_ROOT_PATH.'install/upgrade_1.4.0.php');
?>

296
install/upgrade_1.4.0.php Normal file
View file

@ -0,0 +1,296 @@
<?php
// +-----------------------------------------------------------------------+
// | PhpWebGallery - a PHP based picture gallery |
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
// | branch : BSF (Best So Far)
// | file : $RCSfile$
// | last update : $Date: 2006-04-19 22:54:13 +0200 (mer, 19 avr 2006) $
// | last modifier : $Author: plg $
// | revision : $Revision: 1209 $
// +-----------------------------------------------------------------------+
// | 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('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!');
}
}
$last_time = get_moment();
// will the user have to edit include/config_local.inc.php for
// prefix_thumbnail configuration parameter
$query = '
SELECT value
FROM '.CONFIG_TABLE.'
WHERE param = \'prefix_thumbnail\'
;';
list($prefix_thumbnail) = mysql_fetch_array(pwg_query($query));
// delete obsolete configuration
$query = '
DELETE
FROM '.PREFIX_TABLE.'config
WHERE param IN (
\'prefix_thumbnail\',
\'mail_webmaster\',
\'upload_maxfilesize\',
\'upload_maxwidth\',
\'upload_maxheight\',
\'upload_maxwidth_thumbnail\',
\'upload_maxheight_thumbnail\',
\'mail_notification\',
\'use_iptc\',
\'use_exif\',
\'show_iptc\',
\'show_exif\',
\'authorize_remembering\'
)
;';
mysql_query($query);
$queries = array(
"
ALTER TABLE phpwebgallery_categories
CHANGE COLUMN date_last date_last datetime default NULL
;",
"
ALTER TABLE phpwebgallery_comments
ADD COLUMN validation_date datetime default NULL
;",
"
UPDATE phpwebgallery_comments
SET validation_date = date
",
"
ALTER TABLE phpwebgallery_comments
ADD INDEX comments_i1 (image_id)
;",
"
ALTER TABLE phpwebgallery_comments
ADD INDEX comments_i2 (validation_date)
;",
"
ALTER TABLE phpwebgallery_favorites
CHANGE COLUMN user_id user_id smallint(5) NOT NULL default '0'
;",
"
ALTER TABLE phpwebgallery_images
CHANGE COLUMN date_available
date_available datetime NOT NULL default '0000-00-00 00:00:00'
;",
"
ALTER TABLE phpwebgallery_rate
CHANGE COLUMN user_id user_id smallint(5) NOT NULL default '0'
;",
"
ALTER TABLE phpwebgallery_sessions
CHANGE COLUMN user_id user_id smallint(5) NOT NULL default '0'
;",
"
ALTER TABLE phpwebgallery_user_access
CHANGE COLUMN user_id user_id smallint(5) NOT NULL default '0'
;",
"
DROP TABLE phpwebgallery_user_forbidden
;",
"
ALTER TABLE phpwebgallery_user_group
CHANGE COLUMN user_id user_id smallint(5) NOT NULL default '0'
;",
"
ALTER TABLE phpwebgallery_users
CHANGE COLUMN id id smallint(5) NOT NULL auto_increment
;",
"
CREATE TABLE phpwebgallery_caddie (
user_id smallint(5) NOT NULL default '0',
element_id mediumint(8) NOT NULL default '0',
PRIMARY KEY (user_id,element_id)
) TYPE=MyISAM
;",
"
CREATE TABLE phpwebgallery_user_cache (
user_id smallint(5) NOT NULL default '0',
need_update enum('true','false') NOT NULL default 'true',
forbidden_categories text,
PRIMARY KEY (user_id)
) TYPE=MyISAM
;",
"
CREATE TABLE phpwebgallery_user_feed (
id varchar(50) binary NOT NULL default '',
user_id smallint(5) NOT NULL default '0',
last_check datetime default NULL,
PRIMARY KEY (id)
) TYPE=MyISAM
;",
"
CREATE TABLE phpwebgallery_user_infos (
user_id smallint(5) NOT NULL default '0',
nb_image_line tinyint(1) unsigned NOT NULL default '5',
nb_line_page tinyint(3) unsigned NOT NULL default '3',
status enum('admin','guest') NOT NULL default 'guest',
language varchar(50) NOT NULL default 'english',
maxwidth smallint(6) default NULL,
maxheight smallint(6) default NULL,
expand enum('true','false') NOT NULL default 'false',
show_nb_comments enum('true','false') NOT NULL default 'false',
recent_period tinyint(3) unsigned NOT NULL default '7',
template varchar(255) NOT NULL default 'yoga',
registration_date datetime NOT NULL default '0000-00-00 00:00:00',
UNIQUE KEY user_infos_ui1 (user_id)
) TYPE=MyISAM
;"
);
foreach ($queries as $query)
{
$query = str_replace('phpwebgallery_', PREFIX_TABLE, $query);
pwg_query($query);
}
// user datas migration from phpwebgallery_users to phpwebgallery_user_infos
$query = '
SELECT *
FROM '.USERS_TABLE.'
;';
$datas = array();
list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
$result = pwg_query($query);
while ($row = mysql_fetch_array($result))
{
$row['user_id'] = $row['id'];
$row['registration_date'] = $dbnow;
array_push($datas, $row);
}
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
mass_inserts(
USER_INFOS_TABLE,
array(
'user_id',
'nb_image_line',
'nb_line_page',
'status',
'language',
'maxwidth',
'maxheight',
'expand',
'show_nb_comments',
'recent_period',
'template',
'registration_date'
),
$datas
);
$queries = array(
"
UPDATE ".USER_INFOS_TABLE."
SET template = 'yoga'
;",
"
UPDATE ".USER_INFOS_TABLE."
SET language = 'en_UK.iso-8859-1'
WHERE language NOT IN ('en_UK.iso-8859-1', 'fr_FR.iso-8859-1')
;",
"
UPDATE ".CONFIG_TABLE."
SET value = 'en_UK.iso-8859-1'
WHERE param = 'default_language'
AND value NOT IN ('en_UK.iso-8859-1', 'fr_FR.iso-8859-1')
;",
"
UPDATE ".CONFIG_TABLE."
SET value = 'yoga'
WHERE param = 'default_template'
;",
"
INSERT INTO ".CONFIG_TABLE."
(param,value,comment)
VALUES
(
'gallery_title',
'PhpWebGallery demonstration site',
'Title at top of each page and for RSS feed'
)
;",
"
INSERT INTO ".CONFIG_TABLE."
(param,value,comment)
VALUES
(
'gallery_description',
'My photos web site',
'Short description displayed with gallery title'
)
;"
);
foreach ($queries as $query)
{
$query = str_replace('phpwebgallery_', PREFIX_TABLE, $query);
pwg_query($query);
}
if ($prefix_thumbnail != 'TN-')
{
array_push(
$page['infos'],
'the thumbnail prefix configuration parameter was moved to configuration
file, copy config_local.inc.php from "tools" directory to "include" directory
and edit $conf[\'prefix_thumbnail\'] = '.$prefix_thumbnail
);
}
// now we upgrade from 1.5.0 to 1.6.0
include_once(PHPWG_ROOT_PATH.'install/upgrade_1.5.0.php');
?>

473
install/upgrade_1.5.0.php Normal file
View file

@ -0,0 +1,473 @@
<?php
// +-----------------------------------------------------------------------+
// | PhpWebGallery - a PHP based picture gallery |
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
// | branch : BSF (Best So Far)
// | file : $RCSfile$
// | last update : $Date: 2005-10-23 23:02:21 +0200 (dim, 23 oct 2005) $
// | last modifier : $Author: plg $
// | revision : $Revision: 911 $
// +-----------------------------------------------------------------------+
// | 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('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!');
}
}
/**
* replace old style #images.keywords by #tags. Requires a big data
* migration.
*
* @return void
*/
function tag_replace_keywords()
{
// code taken from upgrades 19 and 22
$query = '
CREATE TABLE '.PREFIX_TABLE.'tags (
id smallint(5) UNSIGNED NOT NULL auto_increment,
name varchar(255) BINARY NOT NULL,
url_name varchar(255) BINARY NOT NULL,
PRIMARY KEY (id)
)
;';
pwg_query($query);
$query = '
CREATE TABLE '.PREFIX_TABLE.'image_tag (
image_id mediumint(8) UNSIGNED NOT NULL,
tag_id smallint(5) UNSIGNED NOT NULL,
PRIMARY KEY (image_id,tag_id)
)
;';
pwg_query($query);
//
// Move keywords to tags
//
// each tag label is associated to a numeric identifier
$tag_id = array();
// to each tag id (key) a list of image ids (value) is associated
$tag_images = array();
$current_id = 1;
$query = '
SELECT id, keywords
FROM '.PREFIX_TABLE.'images
WHERE keywords IS NOT NULL
;';
$result = pwg_query($query);
while ($row = mysql_fetch_array($result))
{
foreach(preg_split('/[,]+/', $row['keywords']) as $keyword)
{
if (!isset($tag_id[$keyword]))
{
$tag_id[$keyword] = $current_id++;
}
if (!isset($tag_images[ $tag_id[$keyword] ]))
{
$tag_images[ $tag_id[$keyword] ] = array();
}
array_push(
$tag_images[ $tag_id[$keyword] ],
$row['id']
);
}
}
$datas = array();
foreach ($tag_id as $tag_name => $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='<h1>'.$t.'</h1><p>'.$d.'</p>';
$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');
?>

58
install/upgrade_1.6.0.php Normal file
View file

@ -0,0 +1,58 @@
<?php
// +-----------------------------------------------------------------------+
// | PhpWebGallery - a PHP based picture gallery |
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
// | branch : BSF (Best So Far)
// | file : $RCSfile$
// | last update : $Date: 2005-10-23 23:02:21 +0200 (dim, 23 oct 2005) $
// | last modifier : $Author: plg $
// | revision : $Revision: 911 $
// +-----------------------------------------------------------------------+
// | 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('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!');
}
}
$queries = array(
"
ALTER TABLE ".PREFIX_TABLE."user_infos
ADD auto_login_key varchar(64) NOT NULL
;",
'
ALTER TABLE '.PREFIX_TABLE.'users
CHANGE username username VARCHAR(100) binary NOT NULL
;',
);
foreach ($queries as $query)
{
pwg_query($query);
}
// now we upgrade from 1.6.2
include_once(PHPWG_ROOT_PATH.'install/upgrade_1.6.2.php');
?>

350
install/upgrade_1.6.2.php Normal file
View file

@ -0,0 +1,350 @@
<?php
// +-----------------------------------------------------------------------+
// | PhpWebGallery - a PHP based picture gallery |
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
// | branch : BSF (Best So Far)
// | file : $RCSfile$
// | last update : $Date: 2005-10-23 23:02:21 +0200 (dim, 23 oct 2005) $
// | last modifier : $Author: plg $
// | revision : $Revision: 911 $
// +-----------------------------------------------------------------------+
// | 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('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!');
}
}
$queries = array(
"
ALTER TABLE `".PREFIX_TABLE."categories`
ADD COLUMN `permalink` varchar(64) default NULL
;",
"
ALTER TABLE `".PREFIX_TABLE."categories`
ADD COLUMN `image_order` varchar(128) default NULL
;",
"
ALTER TABLE `".PREFIX_TABLE."categories`
ADD UNIQUE `categories_i3` (`permalink`)
;",
"
ALTER TABLE `".PREFIX_TABLE."groups`
ADD COLUMN `is_default` enum('true','false') NOT NULL default 'false'
;",
"
RENAME TABLE `".PREFIX_TABLE."history` TO `".PREFIX_TABLE."history_backup`
;",
"
CREATE TABLE `".PREFIX_TABLE."history` (
`id` int(10) unsigned NOT NULL auto_increment,
`date` date NOT NULL default '0000-00-00',
`time` time NOT NULL default '00:00:00',
`year` smallint(4) NOT NULL default '0',
`month` tinyint(2) NOT NULL default '0',
`day` tinyint(2) NOT NULL default '0',
`hour` tinyint(2) NOT NULL default '0',
`user_id` smallint(5) NOT NULL default '0',
`IP` varchar(15) NOT NULL default '',
`section` enum('categories','tags','search','list','favorites','most_visited','best_rated','recent_pics','recent_cats') default NULL,
`category_id` smallint(5) default NULL,
`tag_ids` varchar(50) default NULL,
`image_id` mediumint(8) default NULL,
`summarized` enum('true','false') default 'false',
`image_type` enum('picture','high','other') default NULL,
PRIMARY KEY (`id`),
KEY `history_i1` (`summarized`)
) TYPE=MyISAM
;",
"
ALTER TABLE `".PREFIX_TABLE."image_category`
DROP INDEX `image_category_i1`
;",
"
ALTER TABLE `".PREFIX_TABLE."image_category`
ADD INDEX `image_category_i1` (`category_id`)
;",
"
ALTER TABLE `".PREFIX_TABLE."image_category`
DROP INDEX `image_category_i2`
;",
"
ALTER TABLE `".PREFIX_TABLE."images`
ADD COLUMN `high_filesize` mediumint(9) unsigned default NULL
;",
"
ALTER TABLE `".PREFIX_TABLE."user_infos`
CHANGE COLUMN `language`
`language` varchar(50) NOT NULL default 'en_UK.iso-8859-1'
;",
"
ALTER TABLE `".PREFIX_TABLE."user_infos`
DROP COLUMN `auto_login_key`
;",
"
ALTER TABLE `".PREFIX_TABLE."user_infos`
ADD COLUMN `show_nb_hits` enum('true','false') NOT NULL default 'false'
;",
"
ALTER TABLE `".PREFIX_TABLE."user_mail_notification`
DROP INDEX `uidx_check_key`
;",
"
ALTER TABLE `".PREFIX_TABLE."user_mail_notification`
ADD UNIQUE `user_mail_notification_ui1` (`check_key`)
;",
"
CREATE TABLE `".PREFIX_TABLE."history_summary` (
`id` varchar(13) NOT NULL default '',
`year` smallint(4) NOT NULL default '0',
`month` tinyint(2) default NULL,
`day` tinyint(2) default NULL,
`hour` tinyint(2) default NULL,
`nb_pages` int(11) default NULL,
PRIMARY KEY (`id`)
) TYPE=MyISAM
;",
"
CREATE TABLE `".PREFIX_TABLE."old_permalinks` (
`cat_id` smallint(5) unsigned NOT NULL default '0',
`permalink` varchar(64) NOT NULL default '',
`date_deleted` datetime NOT NULL default '0000-00-00 00:00:00',
`last_hit` datetime default NULL,
`hit` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`permalink`)
) TYPE=MyISAM
;",
"
CREATE TABLE `".PREFIX_TABLE."plugins` (
`id` varchar(64) binary NOT NULL default '',
`state` enum('inactive','active') NOT NULL default 'inactive',
`version` varchar(64) NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM
;",
"
CREATE TABLE `".PREFIX_TABLE."user_cache_categories` (
`user_id` smallint(5) NOT NULL default '0',
`cat_id` smallint(5) unsigned NOT NULL default '0',
`max_date_last` datetime default NULL,
`count_images` mediumint(8) unsigned default '0',
`count_categories` mediumint(8) unsigned default '0',
PRIMARY KEY (`user_id`,`cat_id`)
) TYPE=MyISAM
;",
"
CREATE TABLE `".PREFIX_TABLE."ws_access` (
`id` smallint(5) unsigned NOT NULL auto_increment,
`name` varchar(32) NOT NULL default '',
`access` varchar(255) default NULL,
`start` datetime default NULL,
`end` datetime default NULL,
`request` varchar(255) default NULL,
`limit` smallint(5) unsigned default NULL,
`comment` varchar(255) default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `ws_access_ui1` (`name`)
) TYPE=MyISAM COMMENT='Access for Web Services'
;",
"
INSERT INTO ".PREFIX_TABLE."config
(param,value,comment)
VALUES
('show_nb_hits', 'false', 'Show hits count under thumbnails')
;",
"
INSERT INTO ".PREFIX_TABLE."config
(param,value,comment)
VALUES
('history_admin','false','keep a history of administrator visits on your website')
;",
"
INSERT INTO ".PREFIX_TABLE."config
(param,value,comment)
VALUES
('history_guest','true','keep a history of guest visits on your website')
;",
"
INSERT INTO ".PREFIX_TABLE."config
(param,value,comment)
VALUES
('allow_user_registration','true','allow visitors to register?')
;",
"
INSERT INTO ".PREFIX_TABLE."config
(param,value,comment)
VALUES
('secret_key', MD5(RAND()), 'a secret key specific to the gallery for internal use')
;",
"
INSERT INTO ".PREFIX_TABLE."config
(param,value,comment)
VALUES
('nbm_send_html_mail','true','Send mail on HTML format for notification by mail')
;",
"
INSERT INTO ".PREFIX_TABLE."config
(param,value,comment)
VALUES
('nbm_send_recent_post_dates','true','Send recent post by dates for notification by mail')
;",
"
INSERT INTO ".PREFIX_TABLE."config
(param,value,comment)
VALUES
('email_admin_on_new_user','false','Send an email to theadministrators when a user registers')
;",
"
INSERT INTO ".PREFIX_TABLE."config
(param,value,comment)
VALUES
('email_admin_on_comment','false','Send an email to the administrators when a valid comment is entered')
;",
"
INSERT INTO ".PREFIX_TABLE."config
(param,value,comment)
VALUES
('email_admin_on_comment_validation','false','Send an email to the administrators when a comment requires validation')
;",
"
INSERT INTO ".PREFIX_TABLE."config
(param,value,comment)
VALUES
('email_admin_on_picture_uploaded','false','Send an email to the administrators when a picture is uploaded')
;",
"
UPDATE ".PREFIX_TABLE."user_cache
SET need_update = 'true'
;",
);
foreach ($queries as $query)
{
pwg_query($query);
}
$replacements = array(
array('&#039;', '\''),
array('&quot;', '"'),
array('&lt;', '<'),
array('&gt;', '>'),
array('&amp;', '&') // <- 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');
?>

44
template/yoga/upgrade.tpl Normal file
View file

@ -0,0 +1,44 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>PhpWebGallery : Upgrade to {RELEASE}</title>
</head>
<body>
<!-- BEGIN introduction -->
<h1>Welcome to PhpWebGallery upgrade page.</h1>
<p>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
<strong>release {introduction.CURRENT_RELEASE}</strong> (or equivalent).</p>
<p><a href="{introduction.RUN_UPGRADE_URL}">Upgrade from release
{introduction.CURRENT_RELEASE} to {RELEASE}</a></p>
<!-- END introduction -->
<!-- BEGIN upgrade -->
<h1>Upgrade from version {upgrade.VERSION} to {RELEASE}</h1>
<p>Statistics</p>
<ul>
<li>total upgrade time : {upgrade.TOTAL_TIME}</li>
<li>total SQL time : {upgrade.SQL_TIME}</li>
<li>SQL queries : {upgrade.NB_QUERIES}</li>
</ul>
<!-- BEGIN infos -->
<p>Upgrade informations</p>
<ul>
<!-- BEGIN info -->
<li>{upgrade.infos.info.CONTENT}</li>
<!-- END info -->
</ul>
<!-- END infos -->
<!-- END upgrade -->
</body>
</html>

316
upgrade.php Normal file
View file

@ -0,0 +1,316 @@
<?php
// +-----------------------------------------------------------------------+
// | PhpWebGallery - a PHP based picture gallery |
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
// | branch : BSF (Best So Far)
// | file : $RCSfile$
// | last update : $Date: 2006-11-09 23:13:33 +0100 (jeu, 09 nov 2006) $
// | last modifier : $Author: plg $
// | revision : $Revision: 1599 $
// +-----------------------------------------------------------------------+
// | 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('PHPWG_ROOT_PATH', './');
include_once(PHPWG_ROOT_PATH.'include/functions.inc.php');
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
include_once(PHPWG_ROOT_PATH.'admin/include/functions_upgrade.php');
include(PHPWG_ROOT_PATH.'include/template.php');
include(PHPWG_ROOT_PATH.'include/mysql.inc.php');
include(PHPWG_ROOT_PATH . 'include/config_default.inc.php');
@include(PHPWG_ROOT_PATH. 'include/config_local.inc.php');
check_upgrade();
// concerning upgrade, we use the default users table
$conf['users_table'] = $prefixeTable.'users';
include_once(PHPWG_ROOT_PATH.'include/constants.php');
define('PREFIX_TABLE', $prefixeTable);
// Database connection
mysql_connect( $cfgHote, $cfgUser, $cfgPassword )
or die ( "Could not connect to database server" );
mysql_select_db( $cfgBase )
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 |
// +-----------------------------------------------------------------------+
/**
* 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 '<pre>['.get_elapsed_time($last_time, $new_time).']';
echo ' '.$message;
echo '</pre>';
flush();
$last_time = $new_time;
}
// +-----------------------------------------------------------------------+
// | playing zone |
// +-----------------------------------------------------------------------+
// echo implode('<br>', get_tables());
// echo '<pre>'; print_r(get_columns_of(get_tables())); echo '</pre>';
// foreach (get_available_upgrade_ids() as $upgrade_id)
// {
// echo $upgrade_id, '<br>';
// }
// +-----------------------------------------------------------------------+
// | 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
<pre style="background-color:lightgray">
define(\'PHPWG_IN_UPGRADE\', true);
</pre>'
);
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');
?>