tags/source/rating/locked should only update/log if different than current
This commit is contained in:
parent
7049b3bf4d
commit
3338ff0420
@ -64,7 +64,7 @@ class Ratings implements Extension {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($event instanceof RatingSetEvent) {
|
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) {
|
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;
|
global $database;
|
||||||
|
if($old_rating != $rating){
|
||||||
$database->Execute("UPDATE images SET rating=? WHERE id=?", array($rating, $image_id));
|
$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));
|
log_info("core-image", "Rating for Image #{$image_id} set to: ".$this->theme->rating_to_name($rating));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
add_event_listener(new Ratings());
|
add_event_listener(new Ratings());
|
||||||
?>
|
?>
|
||||||
|
@ -368,25 +368,29 @@ class Image {
|
|||||||
/**
|
/**
|
||||||
* Set the image's source URL
|
* Set the image's source URL
|
||||||
*/
|
*/
|
||||||
public function set_source($source) {
|
public function set_source($source, $old_source) {
|
||||||
global $database;
|
global $database;
|
||||||
if(empty($source)) $source = null;
|
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));
|
$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);
|
log_info("core-image", "Source for Image #{$this->id} set to: ".$source);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function is_locked() {
|
public function is_locked() {
|
||||||
return ($this->locked === true || $this->locked == "Y" || $this->locked == "t");
|
return ($this->locked === true || $this->locked == "Y" || $this->locked == "t");
|
||||||
}
|
}
|
||||||
public function set_locked($tf) {
|
public function set_locked($tf, $old_sln) {
|
||||||
global $database;
|
global $database;
|
||||||
$ln = $tf ? "Y" : "N";
|
$ln = $tf ? "Y" : "N";
|
||||||
$sln = $database->engine->scoreql_to_sql("SCORE_BOOL_$ln");
|
$sln = $database->engine->scoreql_to_sql("SCORE_BOOL_$ln");
|
||||||
$sln = str_replace("'", "", $sln);
|
$sln = str_replace("'", "", $sln);
|
||||||
$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));
|
$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
|
* Set the tags for this image
|
||||||
*/
|
*/
|
||||||
public function set_tags($tags) {
|
public function set_tags($tags, $old_tags) {
|
||||||
global $database;
|
global $database;
|
||||||
$tags = Tag::resolve_list($tags);
|
$tags = Tag::resolve_list($tags);
|
||||||
|
|
||||||
assert(is_array($tags));
|
assert(is_array($tags));
|
||||||
assert(count($tags) > 0);
|
assert(count($tags) > 0);
|
||||||
|
$new_tags = implode(" ", $tags);
|
||||||
|
if($old_tags != $new_tags){
|
||||||
// delete old
|
// delete old
|
||||||
$this->delete_tags_from_image();
|
$this->delete_tags_from_image();
|
||||||
|
|
||||||
// insert each new tags
|
// insert each new tags
|
||||||
foreach($tags as $tag) {
|
foreach($tags as $tag) {
|
||||||
$id = $database->get_one(
|
$id = $database->get_one(
|
||||||
@ -448,6 +452,7 @@ class Image {
|
|||||||
log_info("core-image", "Tags for Image #{$this->id} set to: ".implode(" ", $tags));
|
log_info("core-image", "Tags for Image #{$this->id} set to: ".implode(" ", $tags));
|
||||||
$database->cache->delete("image-{$this->id}-tags");
|
$database->cache->delete("image-{$this->id}-tags");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete this image from the database and disk
|
* Delete this image from the database and disk
|
||||||
|
@ -91,20 +91,19 @@ class TagEdit implements Extension {
|
|||||||
|
|
||||||
if($event instanceof TagSetEvent) {
|
if($event instanceof TagSetEvent) {
|
||||||
if($user->is_admin() || !$event->image->is_locked()) {
|
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($event instanceof SourceSetEvent) {
|
||||||
if($user->is_admin() || !$event->image->is_locked()) {
|
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($event instanceof LockSetEvent) {
|
||||||
if($user->is_admin()) {
|
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->locked);
|
||||||
$event->image->set_locked($event->locked);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user