aboutsummaryrefslogtreecommitdiffstats
path: root/include/items.php
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2019-06-13 13:34:04 +0200
committerMario Vavti <mario@mariovavti.com>2019-06-13 13:34:04 +0200
commit801ab611ede45921d1d6869fa65fc3fbf941d666 (patch)
tree9b1f8f24dbd525bd99152a8f58f4e2a384f63ba7 /include/items.php
parentbc34167c8490c2dad5fcd6553b27b5df54449c39 (diff)
downloadvolse-hubzilla-801ab611ede45921d1d6869fa65fc3fbf941d666.tar.gz
volse-hubzilla-801ab611ede45921d1d6869fa65fc3fbf941d666.tar.bz2
volse-hubzilla-801ab611ede45921d1d6869fa65fc3fbf941d666.zip
more work on linked item/resource deletion for photos and events, deprecate the force flag in drop_item() and comment out goaway() in drop_item().
Diffstat (limited to 'include/items.php')
-rwxr-xr-xinclude/items.php115
1 files changed, 48 insertions, 67 deletions
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",