]> git.mxchange.org Git - friendica.git/blobdiff - src/Worker/RemoveContact.php
Merge pull request #6595 from annando/notice
[friendica.git] / src / Worker / RemoveContact.php
index 4098d66bc59648c227fc170b187356c76209b5d7..00027dca40a2e46dd2b78352a274885634ff0519 100644 (file)
@@ -5,21 +5,30 @@
  */
 namespace Friendica\Worker;
 
-use Friendica\Core\Config;
-use dba;
-
-require_once 'include/dba.php';
+use Friendica\Database\DBA;
+use Friendica\Core\Protocol;
+use Friendica\Model\Item;
 
 class RemoveContact {
        public static function execute($id) {
 
-               // Only delete if the contact doesn't exist (anymore)
-               $r = dba::exists('contact', array('id' => $id));
-               if ($r) {
+               // Only delete if the contact is to be deleted
+               $condition = ['network' => Protocol::PHANTOM, 'id' => $id];
+               $contact = DBA::selectFirst('contact', ['uid'], $condition);
+               if (!DBA::isResult($contact)) {
                        return;
                }
 
-               // Now we delete all the depending table entries
-               dba::delete('contact', array('id' => $id));
+               // Now we delete the contact and all depending tables
+               $condition = ['uid' => $contact['uid'], 'contact-id' => $id];
+               do {
+                       $items = Item::select(['id'], $condition, ['limit' => 100]);
+                       while ($item = Item::fetch($items)) {
+                               DBA::delete('item', ['id' => $item['id']]);
+                       }
+                       DBA::close($items);
+               } while (Item::exists($condition));
+
+               DBA::delete('contact', ['id' => $id]);
        }
 }