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`
|
|
|
|
$result = $database->query("SELECT `key` FROM `lychee_settings` WHERE `key` = 'plugins' LIMIT 1;");
|
|
|
|
if ($result->num_rows===0) {
|
|
|
|
$result = $database->query("INSERT INTO `lychee_settings` (`key`, `value`) VALUES ('plugins', '')");
|
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-04-10 20:42:14 +00:00
|
|
|
if (!$database->query("SELECT `takestamp` FROM `lychee_photos` LIMIT 1;")) {
|
|
|
|
$result = $database->query("ALTER TABLE `lychee_photos` ADD `takestamp` INT(11) DEFAULT NULL");
|
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-04-10 20:42:14 +00:00
|
|
|
if ($database->query("SELECT `takedate`, `taketime` FROM `lychee_photos` LIMIT 1;")) {
|
|
|
|
$result = $database->query("SELECT `id`, `takedate`, `taketime` FROM `lychee_photos` WHERE `takedate` <> '' AND `taketime` <> '';");
|
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()) {
|
|
|
|
$takestamp = strtotime($photo->takedate . $photo->taketime);
|
2014-04-11 08:38:28 +00:00
|
|
|
$database->query("UPDATE `lychee_photos` SET `takestamp` = '$takestamp' WHERE `id` = '$photo->id';");
|
2014-04-10 20:42:14 +00:00
|
|
|
}
|
|
|
|
$result = $database->query("ALTER TABLE `lychee_photos` DROP COLUMN `takedate`;");
|
|
|
|
$result = $database->query("ALTER TABLE `lychee_photos` DROP COLUMN `taketime`;");
|
|
|
|
}
|
|
|
|
|
2014-04-11 22:39:00 +00:00
|
|
|
# Remove `import_name`
|
|
|
|
if ($database->query("SELECT `import_name` FROM `lychee_photos` LIMIT 1;")) {
|
|
|
|
$result = $database->query("ALTER TABLE `lychee_photos` DROP COLUMN `import_name`;");
|
|
|
|
}
|
|
|
|
|
2014-04-11 20:25:03 +00:00
|
|
|
# Remove `sysdate` and `systime`
|
|
|
|
if ($database->query("SELECT `sysdate`, `systime` FROM `lychee_photos` LIMIT 1;")) {
|
|
|
|
$result = $database->query("ALTER TABLE `lychee_photos` DROP COLUMN `sysdate`;");
|
|
|
|
$result = $database->query("ALTER TABLE `lychee_photos` DROP COLUMN `systime`;");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Add `sysstamp`
|
2014-04-11 08:38:28 +00:00
|
|
|
if (!$database->query("SELECT `sysstamp` FROM `lychee_albums` LIMIT 1;")) {
|
|
|
|
$result = $database->query("ALTER TABLE `lychee_albums` ADD `sysstamp` INT(11) DEFAULT NULL");
|
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-04-11 08:38:28 +00:00
|
|
|
if ($database->query("SELECT `sysdate` FROM `lychee_albums` LIMIT 1;")) {
|
|
|
|
$result = $database->query("SELECT `id`, `sysdate` FROM `lychee_albums`;");
|
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()) {
|
|
|
|
$sysstamp = strtotime($album->sysdate);
|
|
|
|
$database->query("UPDATE `lychee_albums` SET `sysstamp` = '$sysstamp' WHERE `id` = '$album->id';");
|
|
|
|
}
|
|
|
|
$result = $database->query("ALTER TABLE `lychee_albums` DROP COLUMN `sysdate`;");
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
$result = $database->query("ALTER TABLE `lychee_albums` CONVERT TO 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
|
|
|
|
$result = $database->query("ALTER TABLE `lychee_photos` CONVERT TO 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
|
|
|
|
$result = $database->query("ALTER TABLE `lychee_settings` CONVERT TO 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
|
|
|
|
2014-04-21 00:19:23 +00:00
|
|
|
# Set album password length to 100 (for longer hashes)
|
|
|
|
$result = $database->query("ALTER TABLE `lychee_albums` CHANGE `password` `password` VARCHAR(100);");
|
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
|
|
|
|
$result = $database->query("ALTER TABLE `lychee_photos` CHANGE `make` `make` VARCHAR(50);");
|
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
|
|
|
|
$result = $database->query("UPDATE lychee_settings SET value = 'ORDER BY takestamp DESC' WHERE `key` = 'sorting' AND `value` LIKE '%UNIX_TIMESTAMP%';");
|
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-04-10 20:42:14 +00:00
|
|
|
$result = $database->query("UPDATE lychee_settings SET value = '020500' WHERE `key` = 'version';");
|
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
|
|
|
|
|
|
|
?>
|