From 8789f41f8ccb31d0ec9f2c75996511e26abba8bc Mon Sep 17 00:00:00 2001 From: plegall Date: Wed, 19 Apr 2006 20:54:13 +0000 Subject: bug fixed: during installation, upgrades from install/db with complex identifier (X.x) were not correctly inserted. bug fixed: available upgrades from install/db need to be inserted in #upgrade table. deletion: all upgrades from install/db coming from trunk are removed. new: complete upgrade from any previous release from 1.3.0 to 1.5.2 with automatic detection detection of the previous release. git-svn-id: http://piwigo.org/svn/branches/branch-1_6@1209 68402e56-0260-453c-a942-63ccdbb3a9ee --- install/upgrade_1.5.0.php | 169 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) (limited to 'install/upgrade_1.5.0.php') diff --git a/install/upgrade_1.5.0.php b/install/upgrade_1.5.0.php index b386c14a4..711625183 100644 --- a/install/upgrade_1.5.0.php +++ b/install/upgrade_1.5.0.php @@ -37,6 +37,146 @@ else } } +/** + * 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( @@ -297,4 +437,33 @@ INSERT INTO ".CONFIG_TABLE." "; 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); + } +} + ?> \ No newline at end of file -- cgit v1.2.3