- if (DBM::is_result($r)) {
- q("DELETE FROM `attach` WHERE `uid` = %d AND `id` = '%s'",
- intval(local_user()),
- dbesc($video_id)
- );
- $i = q("SELECT * FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1",
- dbesc($video_id),
- intval(local_user())
- );
- //echo "<pre>"; var_dump($i); killme();
- if (DBM::is_result($i)) {
- q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
- dbesc(DateTimeFormat::utcNow()),
- dbesc(DateTimeFormat::utcNow()),
- dbesc($i[0]['uri']),
- intval(local_user())
- );
- Term::insertFromItemUri($i[0]['uri'], local_user());
- delete_thread_uri($i[0]['uri'], local_user());
-
- $url = System::baseUrl();
- $drop_id = intval($i[0]['id']);
-
- if ($i[0]['visible']) {
- Worker::add(PRIORITY_HIGH, "Notifier", "drop", $drop_id);
- }
- }
+ // delete items where the attach is used
+ Item::deleteForUser(['`attach` LIKE ? AND `uid` = ?',
+ '%attach/' . $video_id . '%',
+ local_user()
+ ], local_user());