Album id now based on the current microtime #27
This commit is contained in:
parent
029e0e9c43
commit
976635254e
@ -29,20 +29,20 @@ final class Album {
|
|||||||
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
||||||
|
|
||||||
// Properties
|
// Properties
|
||||||
$public = 0;
|
$id = generateID();
|
||||||
$visible = 1;
|
$sysstamp = time();
|
||||||
|
$public = 0;
|
||||||
|
$visible = 1;
|
||||||
|
|
||||||
// Database
|
// Database
|
||||||
$sysstamp = time();
|
$query = Database::prepare(Database::get(), "INSERT INTO ? (id, title, sysstamp, public, visible) VALUES ('?', '?', '?', '?', '?')", array(LYCHEE_TABLE_ALBUMS, $id, $title, $sysstamp, $public, $visible));
|
||||||
$query = Database::prepare(Database::get(), "INSERT INTO ? (title, sysstamp, public, visible) VALUES ('?', '?', '?', '?')", array(LYCHEE_TABLE_ALBUMS, $title, $sysstamp, $public, $visible));
|
$result = Database::execute(Database::get(), $query, __METHOD__, __LINE__);
|
||||||
$result = Database::execute(Database::get(), $query, __METHOD__, __LINE__);
|
|
||||||
$insertID = Database::get()->insert_id;
|
|
||||||
|
|
||||||
// Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
||||||
|
|
||||||
if ($result===false) return false;
|
if ($result===false) return false;
|
||||||
return $insertID;
|
return $id;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,8 @@ final class Database {
|
|||||||
'020700', // 2.7.0
|
'020700', // 2.7.0
|
||||||
'030000', // 3.0.0
|
'030000', // 3.0.0
|
||||||
'030001', // 3.0.1
|
'030001', // 3.0.1
|
||||||
'030003' // 3.0.3
|
'030003', // 3.0.3
|
||||||
|
'030100' // 3.1.0
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -139,8 +139,7 @@ final class Photo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate id
|
// Generate id
|
||||||
$id = str_replace('.', '', microtime(true));
|
$id = generateID();
|
||||||
while(strlen($id)<14) $id .= 0;
|
|
||||||
|
|
||||||
// Set paths
|
// Set paths
|
||||||
$tmp_name = $file['tmp_name'];
|
$tmp_name = $file['tmp_name'];
|
||||||
@ -1149,8 +1148,7 @@ final class Photo {
|
|||||||
while ($photo = $photos->fetch_object()) {
|
while ($photo = $photos->fetch_object()) {
|
||||||
|
|
||||||
// Generate id
|
// Generate id
|
||||||
$id = str_replace('.', '', microtime(true));
|
$id = generateID();
|
||||||
while(strlen($id)<14) $id .= 0;
|
|
||||||
|
|
||||||
// Duplicate entry
|
// Duplicate entry
|
||||||
$values = array(LYCHEE_TABLE_PHOTOS, $id, LYCHEE_TABLE_PHOTOS, $photo->id);
|
$values = array(LYCHEE_TABLE_PHOTOS, $id, LYCHEE_TABLE_PHOTOS, $photo->id);
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
# ------------------------------------------------------------
|
# ------------------------------------------------------------
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS `?` (
|
CREATE TABLE IF NOT EXISTS `?` (
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
`id` bigint(14) NOT NULL,
|
||||||
`title` varchar(100) NOT NULL DEFAULT '',
|
`title` varchar(100) NOT NULL DEFAULT '',
|
||||||
`description` varchar(1000) DEFAULT '',
|
`description` varchar(1000) DEFAULT '',
|
||||||
`sysstamp` int(11) NOT NULL,
|
`sysstamp` int(11) NOT NULL,
|
||||||
|
19
php/database/update_030100.php
Normal file
19
php/database/update_030100.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update to version 3.1.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Lychee\Modules\Database;
|
||||||
|
use Lychee\Modules\Response;
|
||||||
|
|
||||||
|
// Change length of album id field
|
||||||
|
$query = Database::prepare($connection, "ALTER TABLE `?` CHANGE `id` `id` BIGINT(14) NOT NULL", array(LYCHEE_TABLE_ALBUMS));
|
||||||
|
$result = Database::execute($connection, $query, 'update_030100', __LINE__);
|
||||||
|
|
||||||
|
if ($result===false) Response::error('Could not adjust the length of the album id field!');
|
||||||
|
|
||||||
|
// Set version
|
||||||
|
// if (Database::setVersion($connection, '030100')===false) Response::error('Could not update version of database!');
|
||||||
|
|
||||||
|
?>
|
16
php/helpers/generateID.php
Normal file
16
php/helpers/generateID.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
function generateID() {
|
||||||
|
|
||||||
|
// Generate id based on the current microtime
|
||||||
|
$id = str_replace('.', '', microtime(true));
|
||||||
|
|
||||||
|
// Ensure that the id has a length of 14 chars
|
||||||
|
while(strlen($id)<14) $id .= 0;
|
||||||
|
|
||||||
|
// Return the integer value of the id
|
||||||
|
return intval($id);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -20,6 +20,7 @@ require(__DIR__ . '/define.php');
|
|||||||
require(__DIR__ . '/autoload.php');
|
require(__DIR__ . '/autoload.php');
|
||||||
|
|
||||||
require(__DIR__ . '/helpers/fastImageCopyResampled.php');
|
require(__DIR__ . '/helpers/fastImageCopyResampled.php');
|
||||||
|
require(__DIR__ . '/helpers/generateID.php');
|
||||||
require(__DIR__ . '/helpers/getExtension.php');
|
require(__DIR__ . '/helpers/getExtension.php');
|
||||||
require(__DIR__ . '/helpers/getGraphHeader.php');
|
require(__DIR__ . '/helpers/getGraphHeader.php');
|
||||||
require(__DIR__ . '/helpers/getHashedString.php');
|
require(__DIR__ . '/helpers/getHashedString.php');
|
||||||
|
Loading…
Reference in New Issue
Block a user