From 7d7af8eb65e39cd1a10473bdaf4426f3b89c53f1 Mon Sep 17 00:00:00 2001 From: iglocska Date: Wed, 13 Nov 2019 14:07:12 +0100 Subject: [PATCH] fix: [tagging] Events will be unpublished when a local tag is removed #5363 --- app/Controller/AttributesController.php | 16 +++++++++------- app/Controller/EventsController.php | 12 +++++++----- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/app/Controller/AttributesController.php b/app/Controller/AttributesController.php index c61fda666..45fccdc5f 100644 --- a/app/Controller/AttributesController.php +++ b/app/Controller/AttributesController.php @@ -3263,15 +3263,17 @@ class AttributesController extends AppController 'fields' => array('Tag.name') )); if ($this->Attribute->AttributeTag->delete($attributeTag['AttributeTag']['id'])) { - $event['Event']['published'] = 0; - $date = new DateTime(); - $event['Event']['timestamp'] = $date->getTimestamp(); - $this->Attribute->Event->save($event); - $this->Attribute->data['Attribute']['timestamp'] = $date->getTimestamp(); - $this->Attribute->save($this->Attribute->data); + if (empty($attributeTag['AttributeTag']['local'])) { + $event['Event']['published'] = 0; + $date = new DateTime(); + $event['Event']['timestamp'] = $date->getTimestamp(); + $this->Attribute->Event->save($event); + $this->Attribute->data['Attribute']['timestamp'] = $date->getTimestamp(); + $this->Attribute->save($this->Attribute->data); + } $log = ClassRegistry::init('Log'); $log->createLogEntry($this->Auth->user(), 'tag', 'Attribute', $id, 'Removed tag (' . $tag_id . ') "' . $tag['Tag']['name'] . '" from attribute (' . $id . ')', 'Attribute (' . $id . ') untagged of Tag (' . $tag_id . ')'); - return new CakeResponse(array('body'=> json_encode(array('saved' => true, 'success' => 'Tag removed.', 'check_publish' => true)), 'status' => 200)); + return new CakeResponse(array('body'=> json_encode(array('saved' => true, 'success' => 'Tag removed.', 'check_publish' => empty($attributeTag['AttributeTag']['local']))), 'status' => 200)); } else { return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'Tag could not be removed.')), 'status' => 200, 'type' => 'json')); } diff --git a/app/Controller/EventsController.php b/app/Controller/EventsController.php index 0c0d8af4c..fb66b45d2 100644 --- a/app/Controller/EventsController.php +++ b/app/Controller/EventsController.php @@ -4034,13 +4034,15 @@ class EventsController extends AppController 'fields' => array('Tag.name') )); if ($this->Event->EventTag->delete($eventTag['EventTag']['id'])) { - $event['Event']['published'] = 0; - $date = new DateTime(); - $event['Event']['timestamp'] = $date->getTimestamp(); - $this->Event->save($event); + if (empty($eventTag['EventTag']['local'])) { + $event['Event']['published'] = 0; + $date = new DateTime(); + $event['Event']['timestamp'] = $date->getTimestamp(); + $this->Event->save($event); + } $log = ClassRegistry::init('Log'); $log->createLogEntry($this->Auth->user(), 'tag', 'Event', $id, 'Removed tag (' . $tag_id . ') "' . $tag['Tag']['name'] . '" from event (' . $id . ')', 'Event (' . $id . ') untagged of Tag (' . $tag_id . ')'); - return new CakeResponse(array('body'=> json_encode(array('saved' => true, 'success' => ($galaxy ? 'Galaxy' : 'Tag') . ' removed.', 'check_publish' => true)), 'status'=>200, 'type' => 'json')); + return new CakeResponse(array('body'=> json_encode(array('saved' => true, 'success' => ($galaxy ? 'Galaxy' : 'Tag') . ' removed.', 'check_publish' => empty($eventTag['EventTag']['local']))), 'status'=>200, 'type' => 'json')); } else { return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => ($galaxy ? 'Galaxy' : 'Tag') . ' could not be removed.')), 'status'=>200, 'type' => 'json')); }