- $r = q("UPDATE `item` SET `deleted` = 1, `title` = '', `body` = '', `edited` = '%s', `changed` = '%s' WHERE `id` = %d",
- dbesc(datetime_convert()),
- dbesc(datetime_convert()),
- intval($item['id'])
- );
- create_tags_from_item($item['id']);
- create_files_from_item($item['id']);
- delete_thread($item['id'], $item['parent-uri']);
-
- // clean up categories and tags so they don't end up as orphans
-
- $matches = false;
- $cnt = preg_match_all('/<(.*?)>/',$item['file'],$matches,PREG_SET_ORDER);
- if ($cnt) {
- foreach($matches as $mtch) {
- file_tag_unsave_file($item['uid'],$item['id'],$mtch[1],true);
- }
- }
-
- $matches = false;
-
- $cnt = preg_match_all('/\[(.*?)\]/',$item['file'],$matches,PREG_SET_ORDER);
- if ($cnt) {
- foreach($matches as $mtch) {
- file_tag_unsave_file($item['uid'],$item['id'],$mtch[1],false);
- }
- }
-
- // If item is a link to a photo resource, nuke all the associated photos
- // (visitors will not have photo resources)
- // This only applies to photos uploaded from the photos page. Photos inserted into a post do not
- // generate a resource-id and therefore aren't intimately linked to the item.
-
- if (strlen($item['resource-id'])) {
- q("DELETE FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ",
- dbesc($item['resource-id']),
- intval($item['uid'])
- );
- // ignore the result
- }
-
- // If item is a link to an event, nuke the event record.
-
- if (intval($item['event-id'])) {
- q("DELETE FROM `event` WHERE `id` = %d AND `uid` = %d",
- intval($item['event-id']),
- intval($item['uid'])
- );
- // ignore the result
- }
-
- // If item has attachments, drop them
-
- foreach(explode(",",$item['attach']) as $attach){
- preg_match("|attach/(\d+)|", $attach, $matches);
- q("DELETE FROM `attach` WHERE `id` = %d AND `uid` = %d",
- intval($matches[1]),
- local_user()
- );
- // ignore the result
- }
-
-
- // clean up item_id and sign meta-data tables
-
- /*
- // Old code - caused very long queries and warning entries in the mysql logfiles:
-
- $r = q("DELETE FROM item_id where iid in (select id from item where parent = %d and uid = %d)",
- intval($item['id']),
- intval($item['uid'])
- );
-
- $r = q("DELETE FROM sign where iid in (select id from item where parent = %d and uid = %d)",
- intval($item['id']),
- intval($item['uid'])
- );
- */
-
- // The new code splits the queries since the mysql optimizer really has bad problems with subqueries
-
- // Creating list of parents
- $r = q("select id from item where parent = %d and uid = %d",
- intval($item['id']),
- intval($item['uid'])
- );
-
- $parentid = "";
-
- foreach ($r AS $row) {
- if ($parentid != "")
- $parentid .= ", ";
-
- $parentid .= $row["id"];
- }
-
- // Now delete them
- if ($parentid != "") {
- $r = q("DELETE FROM item_id where iid in (%s)", dbesc($parentid));
-
- $r = q("DELETE FROM sign where iid in (%s)", dbesc($parentid));
- }
-
- // If it's the parent of a comment thread, kill all the kids
-
- if ($item['uri'] == $item['parent-uri']) {
- $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s', `body` = '' , `title` = ''
- WHERE `parent-uri` = '%s' AND `uid` = %d ",
- dbesc(datetime_convert()),
- dbesc(datetime_convert()),
- dbesc($item['parent-uri']),
- intval($item['uid'])
- );
- create_tags_from_itemuri($item['parent-uri'], $item['uid']);
- create_files_from_itemuri($item['parent-uri'], $item['uid']);
- delete_thread_uri($item['parent-uri'], $item['uid']);
- // ignore the result
- } else {
- // ensure that last-child is set in case the comment that had it just got wiped.
- q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d ",
- dbesc(datetime_convert()),
- dbesc($item['parent-uri']),
- intval($item['uid'])
- );
- // who is the last child now?
- $r = q("SELECT `id` FROM `item` WHERE `parent-uri` = '%s' AND `type` != 'activity' AND `deleted` = 0 AND `uid` = %d ORDER BY `edited` DESC LIMIT 1",
- dbesc($item['parent-uri']),
- intval($item['uid'])
- );
- if (dbm::is_result($r)) {
- q("UPDATE `item` SET `last-child` = 1 WHERE `id` = %d",
- intval($r[0]['id'])
- );
- }
- }
-
- $drop_id = intval($item['id']);
-
- // send the notification upstream/downstream as the case may be
-
- proc_run(PRIORITY_HIGH,"include/notifier.php", "drop", $drop_id);
-
- if (! $interactive)
- return $owner;
- goaway(App::get_baseurl() . '/' . $_SESSION['return_url']);