aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2019-06-12 10:07:18 +0200
committerMario Vavti <mario@mariovavti.com>2019-06-12 10:07:18 +0200
commit9ac9c693adaa6d3262e1a8639c83474419059730 (patch)
tree880948a1858b48cd67ec91c668c97bdea9f62b49
parent9b2cd69c0f0b1a57984d4d0e75a77a8f9e8c99a4 (diff)
downloadvolse-hubzilla-9ac9c693adaa6d3262e1a8639c83474419059730.tar.gz
volse-hubzilla-9ac9c693adaa6d3262e1a8639c83474419059730.tar.bz2
volse-hubzilla-9ac9c693adaa6d3262e1a8639c83474419059730.zip
initial support for deleting event items if an event is removed
-rw-r--r--Zotlabs/Module/Channel_calendar.php65
1 files changed, 62 insertions, 3 deletions
diff --git a/Zotlabs/Module/Channel_calendar.php b/Zotlabs/Module/Channel_calendar.php
index 4f08eb27c..fcb3ca58b 100644
--- a/Zotlabs/Module/Channel_calendar.php
+++ b/Zotlabs/Module/Channel_calendar.php
@@ -422,13 +422,72 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
dbesc($event_id),
intval(local_channel())
);
+
if($r) {
- $r = q("update item set resource_type = '', resource_id = '' where resource_type = 'event' and resource_id = '%s' and uid = %d",
+
+ $sync_event['event_deleted'] = 1;
+ build_sync_packet(0,array('event' => array($sync_event)));
+
+ $i = q("select * from item where resource_type = 'event' and resource_id = '%s' and uid = %d",
dbesc($event_id),
intval(local_channel())
);
- $sync_event['event_deleted'] = 1;
- build_sync_packet(0,array('event' => array($sync_event)));
+
+ if ($i) {
+
+ $can_delete = false;
+ $local_delete = true;
+
+ $ob_hash = get_observer_hash();
+ if($ob_hash && ($ob_hash === $i[0]['author_xchan'] || $ob_hash === $i[0]['owner_xchan'] || $ob_hash === $i[0]['source_xchan'])) {
+ $can_delete = true;
+ }
+
+ // The site admin can delete any post/item on the site.
+ // If the item originated on this site+channel the deletion will propagate downstream.
+ // Otherwise just the local copy is removed.
+
+ if(is_site_admin()) {
+ $local_delete = true;
+ if(intval($i[0]['item_origin']))
+ $can_delete = true;
+ }
+
+ if($can_delete || $local_delete) {
+
+ q("update item set resource_type = '', resource_id = '' where resource_type = 'event' and resource_id = '%s' and uid = %d",
+ dbesc($event_id),
+ intval(local_channel())
+ );
+
+ // if this is a different page type or it's just a local delete
+ // but not by the item author or owner, do a simple deletion
+
+ $complex = false;
+
+ if(intval($i[0]['item_type']) || ($local_delete && (! $can_delete))) {
+ drop_item($i[0]['id']);
+ }
+ else {
+ // complex deletion that needs to propagate and be performed in phases
+ drop_item($i[0]['id'],true,DROPITEM_PHASE1);
+ $complex = true;
+ }
+
+ $ii = q("select * from item where id = %d",
+ intval($i[0]['id'])
+ );
+ if($ii) {
+ xchan_query($ii);
+ $sync_item = fetch_post_tags($ii);
+ build_sync_packet($i[0]['uid'],array('item' => array(encode_item($sync_item[0],true))));
+ }
+
+ if($complex) {
+ tag_deliver($i[0]['uid'],$i[0]['id']);
+ }
+ }
+ }
killme();
}
notice( t('Failed to remove event' ) . EOL);