tags/source/rating/locked should only update/log if different than current

This commit is contained in:
Daku 2012-01-21 00:17:07 +00:00
parent 7049b3bf4d
commit 3338ff0420
3 changed files with 53 additions and 47 deletions

View file

@ -64,7 +64,7 @@ class Ratings implements Extension {
}
if($event instanceof RatingSetEvent) {
$this->set_rating($event->image->id, $event->rating);
$this->set_rating($event->image->id, $event->rating, $event->image->rating);
}
if($event instanceof ImageInfoBoxBuildingEvent) {
@ -205,11 +205,13 @@ class Ratings implements Extension {
}
}
private function set_rating($image_id, $rating) {
private function set_rating($image_id, $rating, $old_rating) {
global $database;
if($old_rating != $rating){
$database->Execute("UPDATE images SET rating=? WHERE id=?", array($rating, $image_id));
log_info("core-image", "Rating for Image #{$image_id} set to: ".$this->theme->rating_to_name($rating));
}
}
}
add_event_listener(new Ratings());
?>

View file

@ -368,25 +368,29 @@ class Image {
/**
* Set the image's source URL
*/
public function set_source($source) {
public function set_source($source, $old_source) {
global $database;
if(empty($source)) $source = null;
if($old_source != $source){
$database->execute("UPDATE images SET source=:source WHERE id=:id", array("source"=>$source, "id"=>$this->id));
log_info("core-image", "Source for Image #{$this->id} set to: ".$source);
}
}
public function is_locked() {
return ($this->locked === true || $this->locked == "Y" || $this->locked == "t");
}
public function set_locked($tf) {
public function set_locked($tf, $old_sln) {
global $database;
$ln = $tf ? "Y" : "N";
$sln = $database->engine->scoreql_to_sql("SCORE_BOOL_$ln");
$sln = str_replace("'", "", $sln);
$sln = str_replace('"', "", $sln);
if($old_sln != $sln){
$database->execute("UPDATE images SET locked=:yn WHERE id=:id", array("yn"=>$sln, "id"=>$this->id));
log_info("core-image", "Locked status of Image #{$this->id} set to: ".$sln);
log_info("core-image", "Setting Image #{$this->id} lock to: {$event->locked}".$sln);
}
}
/**
@ -405,16 +409,16 @@ class Image {
/**
* Set the tags for this image
*/
public function set_tags($tags) {
public function set_tags($tags, $old_tags) {
global $database;
$tags = Tag::resolve_list($tags);
assert(is_array($tags));
assert(count($tags) > 0);
$new_tags = implode(" ", $tags);
if($old_tags != $new_tags){
// delete old
$this->delete_tags_from_image();
// insert each new tags
foreach($tags as $tag) {
$id = $database->get_one(
@ -448,6 +452,7 @@ class Image {
log_info("core-image", "Tags for Image #{$this->id} set to: ".implode(" ", $tags));
$database->cache->delete("image-{$this->id}-tags");
}
}
/**
* Delete this image from the database and disk

View file

@ -91,20 +91,19 @@ class TagEdit implements Extension {
if($event instanceof TagSetEvent) {
if($user->is_admin() || !$event->image->is_locked()) {
$event->image->set_tags($event->tags);
$event->image->set_tags($event->tags, $event->image->get_tag_list());
}
}
if($event instanceof SourceSetEvent) {
if($user->is_admin() || !$event->image->is_locked()) {
$event->image->set_source($event->source);
$event->image->set_source($event->source, $event->image->source);
}
}
if($event instanceof LockSetEvent) {
if($user->is_admin()) {
log_debug("tag_edit", "Setting Image #{$event->image->id} lock to: {$event->locked}");
$event->image->set_locked($event->locked);
$event->image->set_locked($event->locked, $event->image->locked);
}
}