If an image has no history, make one with the old tags so the new tags can be reverted.
This commit is contained in:
parent
d37a2bfdd4
commit
cadb3f08ca
1 changed files with 12 additions and 3 deletions
|
@ -201,19 +201,28 @@ class Tag_History implements Extension {
|
||||||
$old_tags = Tag::implode($image->get_tag_array());
|
$old_tags = Tag::implode($image->get_tag_array());
|
||||||
log_debug("tag_history", "adding tag history: [$old_tags] -> [$new_tags]");
|
log_debug("tag_history", "adding tag history: [$old_tags] -> [$new_tags]");
|
||||||
if($new_tags == $old_tags) return;
|
if($new_tags == $old_tags) return;
|
||||||
|
|
||||||
// add a history entry
|
|
||||||
$allowed = $config->get_int("history_limit");
|
$allowed = $config->get_int("history_limit");
|
||||||
if($allowed == 0) return;
|
if($allowed == 0) return;
|
||||||
|
|
||||||
|
// if the image has no history, make one with the old tags
|
||||||
|
$entries = $database->get_one("SELECT COUNT(*) FROM tag_histories WHERE image_id = ?", array($image->id));
|
||||||
|
if($entries == 0){
|
||||||
|
$database->execute("
|
||||||
|
INSERT INTO tag_histories(image_id, tags, user_id, user_ip, date_set)
|
||||||
|
VALUES (?, ?, ?, ?, now())",
|
||||||
|
array($image->id, $old_tags, 1, '127.0.0.1')); // TODO: Pick appropriate user id
|
||||||
|
$entries++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// add a history entry
|
||||||
$row = $database->execute("
|
$row = $database->execute("
|
||||||
INSERT INTO tag_histories(image_id, tags, user_id, user_ip, date_set)
|
INSERT INTO tag_histories(image_id, tags, user_id, user_ip, date_set)
|
||||||
VALUES (?, ?, ?, ?, now())",
|
VALUES (?, ?, ?, ?, now())",
|
||||||
array($image->id, $new_tags, $user->id, $_SERVER['REMOTE_ADDR']));
|
array($image->id, $new_tags, $user->id, $_SERVER['REMOTE_ADDR']));
|
||||||
|
$entries++;
|
||||||
|
|
||||||
// if needed remove oldest one
|
// if needed remove oldest one
|
||||||
if($allowed == -1) return;
|
if($allowed == -1) return;
|
||||||
$entries = $database->get_one("SELECT COUNT(*) FROM tag_histories WHERE image_id = ?", array($image->id));
|
|
||||||
if($entries > $allowed)
|
if($entries > $allowed)
|
||||||
{
|
{
|
||||||
// TODO: Make these queries better
|
// TODO: Make these queries better
|
||||||
|
|
Reference in a new issue