diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/attach.php | 7 | ||||
-rwxr-xr-x | include/items.php | 115 |
2 files changed, 53 insertions, 69 deletions
diff --git a/include/attach.php b/include/attach.php index f169e0669..80efe0838 100644 --- a/include/attach.php +++ b/include/attach.php @@ -1514,12 +1514,15 @@ function attach_delete($channel_id, $resource, $is_photo = 0) { function attach_drop_photo($channel_id,$resource) { - $x = q("select id, item_hidden from item where resource_id = '%s' and resource_type = 'photo' and uid = %d", + $x = q("select id, item_hidden from item where resource_id = '%s' and resource_type = 'photo' and uid = %d and item_deleted = 0", dbesc($resource), intval($channel_id) ); + if($x) { - drop_item($x[0]['id'],false,(($x[0]['item_hidden']) ? DROPITEM_NORMAL : DROPITEM_PHASE1),true); + $stage = (($x[0]['item_hidden']) ? DROPITEM_NORMAL : DROPITEM_PHASE1); + $interactive = (($x[0]['item_hidden']) ? false : true); + drop_item($x[0]['id'], $interactive, $stage); } $r = q("SELECT content FROM photo WHERE resource_id = '%s' AND uid = %d AND os_storage = 1", diff --git a/include/items.php b/include/items.php index b6d8eb652..35a5a6124 100755 --- a/include/items.php +++ b/include/items.php @@ -3663,7 +3663,7 @@ function retain_item($id) { ); } -function drop_items($items,$interactive = false,$stage = DROPITEM_NORMAL,$force = false) { +function drop_items($items,$interactive = false,$stage = DROPITEM_NORMAL) { $uid = 0; if(! local_channel() && ! remote_channel()) @@ -3671,7 +3671,7 @@ function drop_items($items,$interactive = false,$stage = DROPITEM_NORMAL,$force if(count($items)) { foreach($items as $item) { - $owner = drop_item($item,$interactive,$stage,$force); + $owner = drop_item($item,$interactive,$stage); if($owner && ! $uid) $uid = $owner; } @@ -3694,12 +3694,7 @@ function drop_items($items,$interactive = false,$stage = DROPITEM_NORMAL,$force // $stage = 1 => set deleted flag on the item and perform intial notifications // $stage = 2 => perform low level delete at a later stage -function drop_item($id,$interactive = true,$stage = DROPITEM_NORMAL,$force = false) { - - // These resource types have linked items that should only be removed at the same time - // as the linked resource; if we encounter one set it to item_hidden rather than item_deleted. - - $linked_resource_types = [ 'photo' ]; +function drop_item($id,$interactive = true,$stage = DROPITEM_NORMAL) { // locate item to be deleted @@ -3711,13 +3706,11 @@ function drop_item($id,$interactive = true,$stage = DROPITEM_NORMAL,$force = fal if(! $interactive) return 0; notice( t('Item not found.') . EOL); - goaway(z_root() . '/' . $_SESSION['return_url']); + //goaway(z_root() . '/' . $_SESSION['return_url']); } $item = $r[0]; - $linked_item = (($item['resource_id'] && $item['resource_type'] && in_array($item['resource_type'], $linked_resource_types)) ? true : false); - $ok_to_delete = false; // system deletion @@ -3740,26 +3733,12 @@ function drop_item($id,$interactive = true,$stage = DROPITEM_NORMAL,$force = fal if($ok_to_delete) { - if ($item['resource_type'] === 'event') { - $x = q("delete from event where event_hash = '%s' and uid = %d", - dbesc($item['resource_id']), - intval($item['uid']) - ); - } - // set the deleted flag immediately on this item just in case the // hook calls a remote process which loops. We'll delete it properly in a second. - if(($linked_item) && (! $force)) { - $r = q("UPDATE item SET item_hidden = 1 WHERE id = %d", - intval($item['id']) - ); - } - else { - $r = q("UPDATE item SET item_deleted = 1 WHERE id = %d", - intval($item['id']) - ); - } + $r = q("UPDATE item SET item_deleted = 1 WHERE id = %d", + intval($item['id']) + ); $arr = [ 'item' => $item, @@ -3799,14 +3778,13 @@ function drop_item($id,$interactive = true,$stage = DROPITEM_NORMAL,$force = fal if((intval($item['item_wall']) && ($stage != DROPITEM_PHASE2)) || ($stage == DROPITEM_PHASE1)) { Master::Summon([ 'Notifier','drop',$notify_id ]); } - - goaway(z_root() . '/' . $_SESSION['return_url']); + //goaway(z_root() . '/' . $_SESSION['return_url']); } else { if(! $interactive) return 0; notice( t('Permission denied.') . EOL); - goaway(z_root() . '/' . $_SESSION['return_url']); + //goaway(z_root() . '/' . $_SESSION['return_url']); } } @@ -3821,14 +3799,9 @@ function drop_item($id,$interactive = true,$stage = DROPITEM_NORMAL,$force = fal * @param boolean $force * @return boolean */ -function delete_item_lowlevel($item, $stage = DROPITEM_NORMAL, $force = false) { - - //$linked_item = (($item['resource_id']) ? true : false); - - $linked_resource_types = [ 'photo' ]; - $linked_item = (($item['resource_id'] && $item['resource_type'] && in_array($item['resource_type'], $linked_resource_types)) ? true : false); +function delete_item_lowlevel($item, $stage = DROPITEM_NORMAL) { - logger('item: ' . $item['id'] . ' stage: ' . $stage . ' force: ' . $force, LOGGER_DATA); + logger('item: ' . $item['id'] . ' stage: ' . $stage, LOGGER_DATA); switch($stage) { case DROPITEM_PHASE2: @@ -3841,42 +3814,50 @@ function delete_item_lowlevel($item, $stage = DROPITEM_NORMAL, $force = false) { break; case DROPITEM_PHASE1: - if($linked_item && ! $force) { - $r = q("UPDATE item SET item_hidden = 1, - changed = '%s', edited = '%s' WHERE id = %d", - dbesc(datetime_convert()), - dbesc(datetime_convert()), - intval($item['id']) - ); - } - else { - $r = q("UPDATE item set item_deleted = 1, changed = '%s', edited = '%s' where id = %d", - dbesc(datetime_convert()), - dbesc(datetime_convert()), - intval($item['id']) - ); - } - + $r = q("UPDATE item set item_deleted = 1, changed = '%s', edited = '%s' where id = %d", + dbesc(datetime_convert()), + dbesc(datetime_convert()), + intval($item['id']) + ); break; case DROPITEM_NORMAL: default: - if($linked_item && ! $force) { - $r = q("UPDATE item SET item_hidden = 1, - changed = '%s', edited = '%s' WHERE id = %d", - dbesc(datetime_convert()), - dbesc(datetime_convert()), - intval($item['id']) - ); - } - else { - $r = q("DELETE FROM item WHERE id = %d", - intval($item['id']) - ); - } + $r = q("DELETE FROM item WHERE id = %d", + intval($item['id']) + ); break; } + // immediately remove local linked resources + + if($item['resource_type'] === 'event') { + $r = q("SELECT * FROM event WHERE event_hash = '%s' AND uid = %d LIMIT 1", + dbesc($item['resource_id']), + intval($item['uid']) + ); + + $sync_data = $r[0]; + + $x = q("delete from event where event_hash = '%s' and uid = %d", + dbesc($item['resource_id']), + intval($item['uid']) + ); + + if($x) { + $sync_data['event_deleted'] = 1; + build_sync_packet($item['uid'], ['event' => [$syncsync_data]]); + } + } + + if($item['resource_type'] === 'photo') { + attach_delete($item['uid'], $item['resource_id'], true ); + $channel = channelx_by_n($item['uid']); + $sync_data = attach_export_data($channel, $item['resource_id'], true); + if($sync_data) + build_sync_packet($item['uid'], ['file' => [$sync_data]]); + } + // immediately remove any undesired profile likes. q("delete from likes where iid = %d and channel_id = %d", |