2014-04-10 20:42:14 +00:00
< ? php
###
# @name Update to version 2.5
# @author Tobias Reich
# @copyright 2014 by Tobias Reich
###
2014-04-11 20:25:03 +00:00
# Add `plugins`
2014-08-30 05:05:26 +00:00
$query = Database :: prepare ( $database , " SELECT `key` FROM `?` WHERE `key` = 'plugins' LIMIT 1 " , array ( LYCHEE_TABLE_SETTINGS ));
2014-08-29 21:49:52 +00:00
$result = $database -> query ( $query );
2014-04-11 20:25:03 +00:00
if ( $result -> num_rows === 0 ) {
2014-08-30 05:05:26 +00:00
$query = Database :: prepare ( $database , " INSERT INTO `?` (`key`, `value`) VALUES ('plugins', '') " , array ( LYCHEE_TABLE_SETTINGS ));
2014-08-29 21:49:52 +00:00
$result = $database -> query ( $query );
2014-05-31 09:58:39 +00:00
if ( ! $result ) {
Log :: error ( $database , 'update_020500' , __LINE__ , 'Could not update database (' . $database -> error . ')' );
return false ;
}
2014-04-11 20:25:03 +00:00
}
# Add `takestamp`
2014-08-30 05:05:26 +00:00
$query = Database :: prepare ( $database , " SELECT `takestamp` FROM `?` LIMIT 1; " , array ( LYCHEE_TABLE_PHOTOS ));
2014-08-29 21:49:52 +00:00
if ( ! $database -> query ( $query )) {
2014-08-30 05:05:26 +00:00
$query = Database :: prepare ( $database , " ALTER TABLE `?` ADD `takestamp` INT(11) DEFAULT NULL " , array ( LYCHEE_TABLE_PHOTOS ));
2014-08-29 21:49:52 +00:00
$result = $database -> query ( $query );
2014-05-31 09:58:39 +00:00
if ( ! $result ) {
Log :: error ( $database , 'update_020500' , __LINE__ , 'Could not update database (' . $database -> error . ')' );
return false ;
}
2014-04-10 20:42:14 +00:00
}
2014-04-11 20:25:03 +00:00
# Convert to `takestamp`
2014-08-30 05:05:26 +00:00
$query = Database :: prepare ( $database , " SELECT `takedate`, `taketime` FROM `?` LIMIT 1; " , array ( LYCHEE_TABLE_PHOTOS ));
2014-08-29 21:49:52 +00:00
if ( $database -> query ( $query )) {
2014-08-30 05:05:26 +00:00
$query = Database :: prepare ( $database , " SELECT `id`, `takedate`, `taketime` FROM `?` WHERE `takedate` <> '' AND `taketime` <> '' " , array ( LYCHEE_TABLE_PHOTOS ));
2014-08-29 21:49:52 +00:00
$result = $database -> query ( $query );
2014-05-31 09:58:39 +00:00
if ( ! $result ) {
Log :: error ( $database , 'update_020500' , __LINE__ , 'Could not update database (' . $database -> error . ')' );
return false ;
}
2014-04-10 20:42:14 +00:00
while ( $photo = $result -> fetch_object ()) {
2014-08-29 21:49:52 +00:00
$takestamp = strtotime ( $photo -> takedate . $photo -> taketime );
2014-08-30 05:05:26 +00:00
$query = Database :: prepare ( $database , " UPDATE `?` SET `takestamp` = '?' WHERE `id` = '?' " , array ( LYCHEE_TABLE_PHOTOS , $takestamp , $photo -> id ));
2014-08-29 21:49:52 +00:00
$database -> query ( $query );
2014-04-10 20:42:14 +00:00
}
2014-08-30 05:05:26 +00:00
$query = Database :: prepare ( $database , " ALTER TABLE `?` DROP COLUMN `takedate`; " , array ( LYCHEE_TABLE_PHOTOS ));
2014-08-29 21:49:52 +00:00
$result = $database -> query ( $query );
2014-08-30 05:05:26 +00:00
$query = Database :: prepare ( $database , " ALTER TABLE `?` DROP COLUMN `taketime` " , array ( LYCHEE_TABLE_PHOTOS ));
2014-08-29 21:49:52 +00:00
$result = $database -> query ( $query );
2014-04-10 20:42:14 +00:00
}
2014-04-11 22:39:00 +00:00
# Remove `import_name`
2014-08-30 05:05:26 +00:00
$query = Database :: prepare ( $database , " SELECT `import_name` FROM `?` LIMIT 1 " , array ( LYCHEE_TABLE_PHOTOS ));
2014-08-29 21:49:52 +00:00
if ( $database -> query ( $query )) {
2014-08-30 05:05:26 +00:00
$query = Database :: prepare ( $database , " ALTER TABLE `?` DROP COLUMN `import_name` " , array ( LYCHEE_TABLE_PHOTOS ));
2014-08-29 21:49:52 +00:00
$result = $database -> query ( $query );
2014-04-11 22:39:00 +00:00
}
2014-04-11 20:25:03 +00:00
# Remove `sysdate` and `systime`
2014-08-30 05:05:26 +00:00
$query = Database :: prepare ( $database , " SELECT `sysdate`, `systime` FROM `?` LIMIT 1 " , array ( LYCHEE_TABLE_PHOTOS ));
2014-08-29 21:49:52 +00:00
if ( $database -> query ( $query )) {
2014-08-30 05:05:26 +00:00
$query = Database :: prepare ( $database , " ALTER TABLE `?` DROP COLUMN `sysdate` " , array ( LYCHEE_TABLE_PHOTOS ));
2014-08-29 21:49:52 +00:00
$result = $database -> query ( $query );
2014-08-30 05:05:26 +00:00
$query = Database :: prepare ( $database , " ALTER TABLE `?` DROP COLUMN `systime` " , array ( LYCHEE_TABLE_PHOTOS ));
2014-08-29 21:49:52 +00:00
$result = $database -> query ( $query );
2014-04-11 20:25:03 +00:00
}
# Add `sysstamp`
2014-08-30 05:05:26 +00:00
$query = Database :: prepare ( $database , " SELECT `sysstamp` FROM `?` LIMIT 1 " , array ( LYCHEE_TABLE_ALBUMS ));
2014-08-29 21:49:52 +00:00
if ( ! $database -> query ( $query )) {
2014-08-30 05:05:26 +00:00
$query = Database :: prepare ( $database , " ALTER TABLE `?` ADD `sysstamp` INT(11) DEFAULT NULL " , array ( LYCHEE_TABLE_ALBUMS ));
2014-08-29 21:49:52 +00:00
$result = $database -> query ( $query );
2014-05-31 09:58:39 +00:00
if ( ! $result ) {
Log :: error ( $database , 'update_020500' , __LINE__ , 'Could not update database (' . $database -> error . ')' );
return false ;
}
2014-04-11 08:38:28 +00:00
}
2014-04-11 20:25:03 +00:00
# Convert to `sysstamp`
2014-08-30 05:05:26 +00:00
$query = Database :: prepare ( $database , " SELECT `sysdate` FROM `?` LIMIT 1 " , array ( LYCHEE_TABLE_ALBUMS ));
2014-08-29 21:49:52 +00:00
if ( $database -> query ( $query )) {
2014-08-30 05:05:26 +00:00
$query = Database :: prepare ( $database , " SELECT `id`, `sysdate` FROM `?` " , array ( LYCHEE_TABLE_ALBUMS ));
2014-08-29 21:49:52 +00:00
$result = $database -> query ( $query );
2014-05-31 09:58:39 +00:00
if ( ! $result ) {
Log :: error ( $database , 'update_020500' , __LINE__ , 'Could not update database (' . $database -> error . ')' );
return false ;
}
2014-04-11 08:38:28 +00:00
while ( $album = $result -> fetch_object ()) {
2014-08-29 21:49:52 +00:00
$sysstamp = strtotime ( $album -> sysdate );
2014-08-30 05:05:26 +00:00
$query = Database :: prepare ( $database , " UPDATE `?` SET `sysstamp` = '?' WHERE `id` = '?' " , array ( LYCHEE_TABLE_ALBUMS , $sysstamp , $album -> id ));
2014-08-29 21:49:52 +00:00
$database -> query ( $query );
2014-04-11 08:38:28 +00:00
}
2014-08-30 05:05:26 +00:00
$query = Database :: prepare ( $database , " ALTER TABLE `?` DROP COLUMN `sysdate` " , array ( LYCHEE_TABLE_ALBUMS ));
2014-08-29 21:49:52 +00:00
$result = $database -> query ( $query );
2014-04-11 08:38:28 +00:00
}
2014-04-11 20:25:03 +00:00
# Set character of database
$result = $database -> query ( " ALTER DATABASE $dbName CHARACTER SET utf8 COLLATE utf8_general_ci; " );
2014-05-31 09:58:39 +00:00
if ( ! $result ) {
Log :: error ( $database , 'update_020500' , __LINE__ , 'Could not update database (' . $database -> error . ')' );
return false ;
}
2014-04-11 20:25:03 +00:00
# Set character
2014-08-30 05:05:26 +00:00
$query = Database :: prepare ( $database , " ALTER TABLE `?` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci " , array ( LYCHEE_TABLE_ALBUMS ));
2014-08-29 21:49:52 +00:00
$result = $database -> query ( $query );
2014-05-31 09:58:39 +00:00
if ( ! $result ) {
Log :: error ( $database , 'update_020500' , __LINE__ , 'Could not update database (' . $database -> error . ')' );
return false ;
}
2014-04-11 20:25:03 +00:00
# Set character
2014-08-30 05:05:26 +00:00
$query = Database :: prepare ( $database , " ALTER TABLE `?` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci " , array ( LYCHEE_TABLE_PHOTOS ));
2014-08-29 21:49:52 +00:00
$result = $database -> query ( $query );
2014-05-31 09:58:39 +00:00
if ( ! $result ) {
Log :: error ( $database , 'update_020500' , __LINE__ , 'Could not update database (' . $database -> error . ')' );
return false ;
}
2014-04-11 20:25:03 +00:00
# Set character
2014-08-30 05:05:26 +00:00
$query = Database :: prepare ( $database , " ALTER TABLE `?` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci " , array ( LYCHEE_TABLE_SETTINGS ));
2014-08-29 21:49:52 +00:00
$result = $database -> query ( $query );
2014-05-31 09:58:39 +00:00
if ( ! $result ) {
Log :: error ( $database , 'update_020500' , __LINE__ , 'Could not update database (' . $database -> error . ')' );
return false ;
}
2014-04-11 20:25:03 +00:00
2014-04-21 00:19:23 +00:00
# Set album password length to 100 (for longer hashes)
2014-08-30 05:05:26 +00:00
$query = Database :: prepare ( $database , " ALTER TABLE `?` CHANGE `password` `password` VARCHAR(100) " , array ( LYCHEE_TABLE_ALBUMS ));
2014-08-29 21:49:52 +00:00
$result = $database -> query ( $query );
2014-05-31 09:58:39 +00:00
if ( ! $result ) {
Log :: error ( $database , 'update_020500' , __LINE__ , 'Could not update database (' . $database -> error . ')' );
return false ;
}
2014-04-21 00:19:23 +00:00
2014-04-25 14:41:35 +00:00
# Set make length to 50
2014-08-30 05:05:26 +00:00
$query = Database :: prepare ( $database , " ALTER TABLE `?` CHANGE `make` `make` VARCHAR(50) " , array ( LYCHEE_TABLE_PHOTOS ));
2014-08-29 21:49:52 +00:00
$result = $database -> query ( $query );
2014-05-31 09:58:39 +00:00
if ( ! $result ) {
Log :: error ( $database , 'update_020500' , __LINE__ , 'Could not update database (' . $database -> error . ')' );
return false ;
}
2014-04-25 14:41:35 +00:00
2014-05-06 17:57:59 +00:00
# Reset sorting
2014-08-30 05:05:26 +00:00
$query = Database :: prepare ( $database , " UPDATE ? SET value = 'ORDER BY takestamp DESC' WHERE `key` = 'sorting' AND `value` LIKE '%UNIX_TIMESTAMP%' " , array ( LYCHEE_TABLE_SETTINGS ));
2014-08-29 21:49:52 +00:00
$result = $database -> query ( $query );
2014-05-31 09:58:39 +00:00
if ( ! $result ) {
Log :: error ( $database , 'update_020500' , __LINE__ , 'Could not update database (' . $database -> error . ')' );
return false ;
}
2014-05-06 17:57:59 +00:00
2014-04-11 20:25:03 +00:00
# Set version
2014-08-30 05:05:26 +00:00
$query = Database :: prepare ( $database , " UPDATE ? SET value = '020500' WHERE `key` = 'version' " , array ( LYCHEE_TABLE_SETTINGS ));
2014-08-29 21:49:52 +00:00
$result = $database -> query ( $query );
2014-05-31 09:58:39 +00:00
if ( ! $result ) {
Log :: error ( $database , 'update_020500' , __LINE__ , 'Could not update database (' . $database -> error . ')' );
return false ;
}
2014-04-10 20:42:14 +00:00
?>