code optimisations and de-duplication on updating parent commented timestamp
This commit is contained in:
parent
a8d81a68d6
commit
558e3f8042
@ -47,24 +47,17 @@ class Moderate extends \Zotlabs\Web\Controller {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if($r) {
|
if($r) {
|
||||||
|
$item = $r[0];
|
||||||
|
|
||||||
if($action === 'approve') {
|
if($action === 'approve') {
|
||||||
q("update item set item_blocked = 0 where uid = %d and id = %d",
|
q("update item set item_blocked = 0 where uid = %d and id = %d",
|
||||||
intval(local_channel()),
|
intval(local_channel()),
|
||||||
intval($post_id)
|
intval($post_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
// update the parent's commented timestamp
|
$item['item_blocked'] = 0;
|
||||||
|
|
||||||
$z = q("select max(created) as commented from item where parent_mid = '%s' and uid = %d and item_delayed = 0 ",
|
item_update_parent_commented($item);
|
||||||
dbesc($r[0]['parent_mid']),
|
|
||||||
intval(local_channel())
|
|
||||||
);
|
|
||||||
|
|
||||||
q("UPDATE item set commented = '%s', changed = '%s' WHERE id = %d",
|
|
||||||
dbesc(($z) ? $z[0]['commented'] : (datetime_convert())),
|
|
||||||
dbesc(datetime_convert()),
|
|
||||||
intval($r[0]['parent'])
|
|
||||||
);
|
|
||||||
|
|
||||||
notice( t('Comment approved') . EOL);
|
notice( t('Comment approved') . EOL);
|
||||||
}
|
}
|
||||||
@ -72,6 +65,8 @@ class Moderate extends \Zotlabs\Web\Controller {
|
|||||||
drop_item($post_id,false);
|
drop_item($post_id,false);
|
||||||
notice( t('Comment deleted') . EOL);
|
notice( t('Comment deleted') . EOL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// refetch the item after changes have been made
|
||||||
|
|
||||||
$r = q("select * from item where id = %d",
|
$r = q("select * from item where id = %d",
|
||||||
intval($post_id)
|
intval($post_id)
|
||||||
|
@ -1977,31 +1977,7 @@ function item_store($arr, $allow_exec = false, $deliver = true) {
|
|||||||
*/
|
*/
|
||||||
call_hooks('post_remote_end', $arr);
|
call_hooks('post_remote_end', $arr);
|
||||||
|
|
||||||
$update_parent = true;
|
item_update_parent_commented($arr);
|
||||||
|
|
||||||
// update the commented timestamp on the parent - unless this is a moderated comment or a potential clone of an older item
|
|
||||||
// which we don't wish to bring to the surface. As the queue only holds deliveries for 3 days, it's
|
|
||||||
// suspected of being an older cloned item if the creation time is older than that.
|
|
||||||
|
|
||||||
if(intval($arr['item_blocked']) === ITEM_MODERATED)
|
|
||||||
$update_parent = false;
|
|
||||||
|
|
||||||
if($arr['created'] < datetime_convert('','','now - 4 days'))
|
|
||||||
$update_parent = false;
|
|
||||||
|
|
||||||
if($update_parent) {
|
|
||||||
$z = q("select max(created) as commented from item where parent_mid = '%s' and uid = %d and item_delayed = 0 ",
|
|
||||||
dbesc($arr['parent_mid']),
|
|
||||||
intval($arr['uid'])
|
|
||||||
);
|
|
||||||
|
|
||||||
q("UPDATE item set commented = '%s', changed = '%s' WHERE id = %d",
|
|
||||||
dbesc(($z) ? $z[0]['commented'] : (datetime_convert())),
|
|
||||||
dbesc(datetime_convert()),
|
|
||||||
intval($parent_id)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// If _creating_ a deleted item, don't propagate it further or send out notifications.
|
// If _creating_ a deleted item, don't propagate it further or send out notifications.
|
||||||
// We need to store the item details just in case the delete came in before the original post,
|
// We need to store the item details just in case the delete came in before the original post,
|
||||||
@ -2332,6 +2308,36 @@ function item_store_update($arr, $allow_exec = false, $deliver = true) {
|
|||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function item_update_parent_commented($item) {
|
||||||
|
|
||||||
|
|
||||||
|
$update_parent = true;
|
||||||
|
|
||||||
|
// update the commented timestamp on the parent
|
||||||
|
// - unless this is a moderated comment or a potential clone of an older item
|
||||||
|
// which we don't wish to bring to the surface. As the queue only holds deliveries
|
||||||
|
// for 3 days, it's suspected of being an older cloned item if the creation time
|
||||||
|
//is older than that.
|
||||||
|
|
||||||
|
if(intval($item['item_blocked']) === ITEM_MODERATED)
|
||||||
|
$update_parent = false;
|
||||||
|
|
||||||
|
if($item['created'] < datetime_convert('','','now - 4 days'))
|
||||||
|
$update_parent = false;
|
||||||
|
|
||||||
|
if($update_parent) {
|
||||||
|
$z = q("select max(created) as commented from item where parent_mid = '%s' and uid = %d and item_delayed = 0 ",
|
||||||
|
dbesc($item['parent_mid']),
|
||||||
|
intval($item['uid'])
|
||||||
|
);
|
||||||
|
|
||||||
|
q("UPDATE item set commented = '%s', changed = '%s' WHERE id = %d",
|
||||||
|
dbesc(($z) ? $z[0]['commented'] : datetime_convert()),
|
||||||
|
dbesc(datetime_convert()),
|
||||||
|
intval($item['parent'])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function send_status_notifications($post_id,$item) {
|
function send_status_notifications($post_id,$item) {
|
||||||
|
Reference in New Issue
Block a user