attach_delete() - remove photo resources even if the attach table row wasn't found.
This commit is contained in:
parent
e843d27f8c
commit
b20cce1408
@ -188,13 +188,12 @@ class Photos extends \Zotlabs\Web\Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if((argc() > 2) && (x($_REQUEST,'delete')) && ($_REQUEST['delete'] === t('Delete Photo'))) {
|
if((argc() > 2) && (x($_REQUEST,'delete')) && ($_REQUEST['delete'] === t('Delete Photo'))) {
|
||||||
|
|
||||||
// same as above but remove single photo
|
// same as above but remove single photo
|
||||||
|
|
||||||
$ob_hash = get_observer_hash();
|
$ob_hash = get_observer_hash();
|
||||||
if(! $ob_hash)
|
if(! $ob_hash)
|
||||||
goaway(z_root() . '/' . $_SESSION['photo_return']);
|
goaway(z_root() . '/' . $_SESSION['photo_return']);
|
||||||
|
|
||||||
$r = q("SELECT id, resource_id FROM photo WHERE ( xchan = '%s' or uid = %d ) AND resource_id = '%s' LIMIT 1",
|
$r = q("SELECT id, resource_id FROM photo WHERE ( xchan = '%s' or uid = %d ) AND resource_id = '%s' LIMIT 1",
|
||||||
dbesc($ob_hash),
|
dbesc($ob_hash),
|
||||||
intval(local_channel()),
|
intval(local_channel()),
|
||||||
|
@ -1279,8 +1279,10 @@ function attach_delete($channel_id, $resource, $is_photo = 0) {
|
|||||||
intval($channel_id)
|
intval($channel_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
if(! $r)
|
if(! $r) {
|
||||||
|
attach_drop_photo($channel_id,$resource);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$cloudpath = get_parent_cloudpath($channel_id, $channel_address, $resource);
|
$cloudpath = get_parent_cloudpath($channel_id, $channel_address, $resource);
|
||||||
$object = get_file_activity_object($channel_id, $resource, $cloudpath);
|
$object = get_file_activity_object($channel_id, $resource, $cloudpath);
|
||||||
@ -1326,19 +1328,10 @@ function attach_delete($channel_id, $resource, $is_photo = 0) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if($r[0]['is_photo']) {
|
if($r[0]['is_photo']) {
|
||||||
$x = q("select id, item_hidden from item where resource_id = '%s' and resource_type = 'photo' and uid = %d",
|
attach_drop_photo($channel_id,$resource);
|
||||||
dbesc($resource),
|
|
||||||
intval($channel_id)
|
|
||||||
);
|
|
||||||
if($x) {
|
|
||||||
drop_item($x[0]['id'],false,(($x[0]['item_hidden']) ? DROPITEM_NORMAL : DROPITEM_PHASE1),true);
|
|
||||||
}
|
|
||||||
q("DELETE FROM photo WHERE uid = %d AND resource_id = '%s'",
|
|
||||||
intval($channel_id),
|
|
||||||
dbesc($resource)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// update the parent folder's lastmodified timestamp
|
// update the parent folder's lastmodified timestamp
|
||||||
$e = q("UPDATE attach SET edited = '%s' WHERE hash = '%s' AND uid = %d",
|
$e = q("UPDATE attach SET edited = '%s' WHERE hash = '%s' AND uid = %d",
|
||||||
dbesc(datetime_convert()),
|
dbesc(datetime_convert()),
|
||||||
@ -1351,6 +1344,24 @@ function attach_delete($channel_id, $resource, $is_photo = 0) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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",
|
||||||
|
dbesc($resource),
|
||||||
|
intval($channel_id)
|
||||||
|
);
|
||||||
|
if($x) {
|
||||||
|
drop_item($x[0]['id'],false,(($x[0]['item_hidden']) ? DROPITEM_NORMAL : DROPITEM_PHASE1),true);
|
||||||
|
}
|
||||||
|
q("DELETE FROM photo WHERE uid = %d AND resource_id = '%s'",
|
||||||
|
intval($channel_id),
|
||||||
|
dbesc($resource)
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns path to file in cloud/.
|
* @brief Returns path to file in cloud/.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user