try and sort out the item delete mess
This commit is contained in:
parent
8c3efd20f4
commit
a6d8668a5f
8
boot.php
8
boot.php
@ -329,6 +329,12 @@ define ( 'UPDATE_FLAGS_FORCED', 0x0002);
|
|||||||
define ( 'UPDATE_FLAGS_DELETED', 0x1000);
|
define ( 'UPDATE_FLAGS_DELETED', 0x1000);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
define ( 'DROPITEM_NORMAL', 0);
|
||||||
|
define ( 'DROPITEM_PHASE1', 1);
|
||||||
|
define ( 'DROPITEM_PHASE2', 2);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum number of "people who like (or don't like) this" that we will list by name
|
* Maximum number of "people who like (or don't like) this" that we will list by name
|
||||||
*/
|
*/
|
||||||
@ -511,6 +517,8 @@ define ( 'ITEM_DELAYED_PUBLISH', 0x0080);
|
|||||||
define ( 'ITEM_BUILDBLOCK', 0x0100); // Named thusly to make sure nobody confuses this with ITEM_BLOCKED
|
define ( 'ITEM_BUILDBLOCK', 0x0100); // Named thusly to make sure nobody confuses this with ITEM_BLOCKED
|
||||||
define ( 'ITEM_PDL', 0x0200); // Page Description Language - e.g. Comanche
|
define ( 'ITEM_PDL', 0x0200); // Page Description Language - e.g. Comanche
|
||||||
define ( 'ITEM_BUG', 0x0400); // Is a bug, can be used by the internal bug tracker
|
define ( 'ITEM_BUG', 0x0400); // Is a bug, can be used by the internal bug tracker
|
||||||
|
define ( 'ITEM_PENDING_REMOVE', 0x0800); // deleted, notification period has lapsed
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Item Flags
|
* Item Flags
|
||||||
*/
|
*/
|
||||||
|
@ -7,10 +7,20 @@ function expire_run($argv, $argc){
|
|||||||
|
|
||||||
cli_startup();
|
cli_startup();
|
||||||
|
|
||||||
|
$r = q("select id from item where (item_restrict & %d) and not (item_restrict & %d) and changed < UTC_TIMESTAMP() - INTERVAL 10 DAY",
|
||||||
|
intval(ITEM_DELETED),
|
||||||
|
intval(ITEM_PENDING_REMOVE)
|
||||||
|
);
|
||||||
|
if($r) {
|
||||||
|
foreach($r as $rr) {
|
||||||
|
drop_item($rr['id'],false,DROPITEM_PHASE2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// physically remove anything that has been deleted for more than two months
|
// physically remove anything that has been deleted for more than two months
|
||||||
|
|
||||||
$r = q("delete from item where ( item_flags & %d ) and changed < UTC_TIMESTAMP() - INTERVAL 60 DAY",
|
$r = q("delete from item where ( item_restrict & %d ) and changed < UTC_TIMESTAMP() - INTERVAL 36 DAY",
|
||||||
intval(ITEM_DELETED)
|
intval(ITEM_PENDING_REMOVE)
|
||||||
);
|
);
|
||||||
|
|
||||||
// make this optional as it could have a performance impact on large sites
|
// make this optional as it could have a performance impact on large sites
|
||||||
@ -42,6 +52,8 @@ function expire_run($argv, $argc){
|
|||||||
if($expire_days)
|
if($expire_days)
|
||||||
item_expire($x['channel_id'],$expire_days);
|
item_expire($x['channel_id'],$expire_days);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3493,7 +3493,12 @@ function drop_items($items) {
|
|||||||
// permissions to carry out this act. If it is non-interactive, we are deleting something at the
|
// permissions to carry out this act. If it is non-interactive, we are deleting something at the
|
||||||
// system's request and do not check permission. This is very important to know.
|
// system's request and do not check permission. This is very important to know.
|
||||||
|
|
||||||
function drop_item($id,$interactive = true) {
|
// Some deletion requests (those coming from remote sites) must be staged.
|
||||||
|
// $stage = 0 => unstaged
|
||||||
|
// $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) {
|
||||||
|
|
||||||
$a = get_app();
|
$a = get_app();
|
||||||
|
|
||||||
@ -3503,7 +3508,7 @@ function drop_item($id,$interactive = true) {
|
|||||||
intval($id)
|
intval($id)
|
||||||
);
|
);
|
||||||
|
|
||||||
if((! $r) || ($r[0]['item_restrict'] & ITEM_DELETED)) {
|
if((! $r) || (($r[0]['item_restrict'] & ITEM_DELETED) && ($stage === DROPITEM_NORMAL))) {
|
||||||
if(! $interactive)
|
if(! $interactive)
|
||||||
return 0;
|
return 0;
|
||||||
notice( t('Item not found.') . EOL);
|
notice( t('Item not found.') . EOL);
|
||||||
@ -3537,7 +3542,7 @@ function drop_item($id,$interactive = true) {
|
|||||||
intval($item['id'])
|
intval($item['id'])
|
||||||
);
|
);
|
||||||
|
|
||||||
$arr = array('item' => $item);
|
$arr = array('item' => $item, 'interactive' => $interactive, 'stage' => $stage);
|
||||||
call_hooks('drop_item', $arr );
|
call_hooks('drop_item', $arr );
|
||||||
|
|
||||||
$notify_id = intval($item['id']);
|
$notify_id = intval($item['id']);
|
||||||
@ -3548,10 +3553,10 @@ function drop_item($id,$interactive = true) {
|
|||||||
);
|
);
|
||||||
if($items) {
|
if($items) {
|
||||||
foreach($items as $i)
|
foreach($items as $i)
|
||||||
delete_item_lowlevel($i);
|
delete_item_lowlevel($i,$stage);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
delete_item_lowlevel($item);
|
delete_item_lowlevel($item,$stage);
|
||||||
|
|
||||||
if(! $interactive)
|
if(! $interactive)
|
||||||
return 1;
|
return 1;
|
||||||
@ -3559,7 +3564,7 @@ function drop_item($id,$interactive = true) {
|
|||||||
// send the notification upstream/downstream as the case may be
|
// send the notification upstream/downstream as the case may be
|
||||||
// only send notifications to others if this is the owner's wall item.
|
// only send notifications to others if this is the owner's wall item.
|
||||||
|
|
||||||
if($item['item_flags'] & ITEM_WALL)
|
if(($item['item_flags'] & ITEM_WALL) && ($stage != DROPITEM_PHASE2))
|
||||||
proc_run('php','include/notifier.php','drop',$notify_id);
|
proc_run('php','include/notifier.php','drop',$notify_id);
|
||||||
|
|
||||||
goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
|
goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
|
||||||
@ -3578,15 +3583,47 @@ function drop_item($id,$interactive = true) {
|
|||||||
// It merely destroys all resources associated with an item.
|
// It merely destroys all resources associated with an item.
|
||||||
// Please do not use without a suitable wrapper.
|
// Please do not use without a suitable wrapper.
|
||||||
|
|
||||||
function delete_item_lowlevel($item) {
|
function delete_item_lowlevel($item,$stage = DROPITEM_NORMAL) {
|
||||||
|
|
||||||
$r = q("UPDATE item SET item_restrict = ( item_restrict | %d ), title = '', body = '',
|
|
||||||
changed = '%s', edited = '%s' WHERE id = %d LIMIT 1",
|
switch($stage) {
|
||||||
intval(ITEM_DELETED),
|
case DROPITEM_PHASE2:
|
||||||
dbesc(datetime_convert()),
|
$r = q("UPDATE item SET item_restrict = ( item_restrict | %d ), body = '', title = '',
|
||||||
dbesc(datetime_convert()),
|
changed = '%s', edited = '%s' WHERE id = %d LIMIT 1",
|
||||||
intval($item['id'])
|
intval(ITEM_PENDING_REMOVE),
|
||||||
);
|
dbesc(datetime_convert()),
|
||||||
|
dbesc(datetime_convert()),
|
||||||
|
intval($item['id'])
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DROPITEM_PHASE1:
|
||||||
|
$r = q("UPDATE item SET item_restrict = ( item_restrict | %d ),
|
||||||
|
changed = '%s', edited = '%s' WHERE id = %d LIMIT 1",
|
||||||
|
intval(ITEM_DELETED),
|
||||||
|
dbesc(datetime_convert()),
|
||||||
|
dbesc(datetime_convert()),
|
||||||
|
intval($item['id'])
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DROPITEM_NORMAL:
|
||||||
|
default:
|
||||||
|
$r = q("UPDATE item SET item_restrict = ( item_restrict | %d ), body = '', title = '',
|
||||||
|
changed = '%s', edited = '%s' WHERE id = %d LIMIT 1",
|
||||||
|
intval(ITEM_DELETED),
|
||||||
|
dbesc(datetime_convert()),
|
||||||
|
dbesc(datetime_convert()),
|
||||||
|
intval($item['id'])
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// network deletion request. Keep the message structure so that we can deliver delete notifications.
|
||||||
|
// Come back after several days (or perhaps a month) to do the lowlevel delete (DROPITEM_PHASE2).
|
||||||
|
|
||||||
|
if($stage == DROPITEM_PHASE1)
|
||||||
|
return true;
|
||||||
|
|
||||||
$r = q("delete from term where otype = %d and oid = %d limit 1",
|
$r = q("delete from term where otype = %d and oid = %d limit 1",
|
||||||
intval(TERM_OBJ_POST),
|
intval(TERM_OBJ_POST),
|
||||||
|
@ -1597,10 +1597,10 @@ function delete_imported_item($sender,$item,$uid) {
|
|||||||
// We can't reverse the order because drop_item refuses to run if the item already has the deleted flag set and we need to
|
// We can't reverse the order because drop_item refuses to run if the item already has the deleted flag set and we need to
|
||||||
// set that flag prior to calling tag_deliver.
|
// set that flag prior to calling tag_deliver.
|
||||||
|
|
||||||
// One possibility would be to set the deleted flag, call both tag_deliver and the notifier to notify downstream channels
|
// Use phased deletion to set the deleted flag, call both tag_deliver and the notifier to notify downstream channels
|
||||||
// and then clean up after ourselves with a cron job after a day or two to do the delete_item_lowlevel().
|
// and then clean up after ourselves with a cron job after several days to do the delete_item_lowlevel() (DROPITEM_PHASE2).
|
||||||
|
|
||||||
drop_item($r[0]['uid'],false);
|
drop_item($r[0]['id'],false, DROPITEM_PHASE1);
|
||||||
|
|
||||||
tag_deliver($uid,$r[0]['id']);
|
tag_deliver($uid,$r[0]['id']);
|
||||||
|
|
||||||
|
14
mod/item.php
14
mod/item.php
@ -890,9 +890,19 @@ function item_content(&$a) {
|
|||||||
|
|
||||||
require_once('include/security.php');
|
require_once('include/security.php');
|
||||||
|
|
||||||
if(($a->argc == 3) && ($a->argv[1] === 'drop') && intval($a->argv[2])) {
|
if((argc() == 3) && (argv(1) === 'drop') && intval(argv(2))) {
|
||||||
require_once('include/items.php');
|
require_once('include/items.php');
|
||||||
drop_item($a->argv[2]);
|
$i = q("select id, item_restrict from item where id = %d and uid = %d limit 1",
|
||||||
|
intval(argv(2))
|
||||||
|
);
|
||||||
|
if($i) {
|
||||||
|
if($i[0]['item_restrict'])
|
||||||
|
drop_item($i[0]['id']);
|
||||||
|
else {
|
||||||
|
drop_item($i[0]['id'],true,DROPITEM_PHASE1);
|
||||||
|
tag_deliver($uid,$i[0]['id']);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user