]> git.mxchange.org Git - friendica.git/commitdiff
Issue 2518: Remove contact data in the background
authorMichael <heluecht@pirati.ca>
Mon, 28 Nov 2016 21:44:04 +0000 (21:44 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 28 Nov 2016 21:44:04 +0000 (21:44 +0000)
include/Contact.php
include/remove_contact.php [new file with mode: 0644]

index 949feb3564e695057a2313eff75fbbaa01b7d602..d0f4023447f1448962d7f1ffd0bbabfcff3e97ab 100644 (file)
@@ -22,6 +22,7 @@ function user_remove($uid) {
                $r[0]['nickname']
        );
 
+       /// @todo Should be done in a background job since this likely will run into a time out
        // don't delete yet, will be done later when contacts have deleted my stuff
        // q("DELETE FROM `contact` WHERE `uid` = %d", intval($uid));
        q("DELETE FROM `gcign` WHERE `uid` = %d", intval($uid));
@@ -74,25 +75,10 @@ function contact_remove($id) {
                return;
        }
 
-       q("DELETE FROM `contact` WHERE `id` = %d",
-               intval($id)
-       );
-       q("DELETE FROM `item` WHERE `contact-id` = %d ",
-               intval($id)
-       );
-       q("DELETE FROM `photo` WHERE `contact-id` = %d ",
-               intval($id)
-       );
-       q("DELETE FROM `mail` WHERE `contact-id` = %d ",
-               intval($id)
-       );
-       q("DELETE FROM `event` WHERE `cid` = %d ",
-               intval($id)
-       );
-       q("DELETE FROM `queue` WHERE `cid` = %d ",
-               intval($id)
-       );
+       q("DELETE FROM `contact` WHERE `id` = %d", intval($id));
 
+       // Delete the rest in the background
+       proc_run(PRIORITY_LOW, 'include/remove_contact.php', $id);
 }
 
 
diff --git a/include/remove_contact.php b/include/remove_contact.php
new file mode 100644 (file)
index 0000000..153b988
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+/**
+ * @file include/remove_contact.php
+ * @brief Removes orphaned data from deleted contacts
+ */
+require_once("boot.php");
+
+function remove_contact_run($argv, $argc) {
+       global $a, $db;
+
+       if (is_null($a))
+               $a = new App;
+
+       if (is_null($db)) {
+               @include(".htconfig.php");
+               require_once("include/dba.php");
+               $db = new dba($db_host, $db_user, $db_pass, $db_data);
+               unset($db_host, $db_user, $db_pass, $db_data);
+       }
+
+       load_config('config');
+       load_config('system');
+
+       if ($argc != 2) {
+               return;
+       }
+
+       $id = intval($argv[1]);
+
+       // Only delete if the contact doesn't exist (anymore)
+       $r = q("SELECT `id` FROM `contact` WHERE `id` = %d", intval($id));
+       if (dbm::is_result($r)) {
+               return;
+       }
+
+die("Blubb ".$id);
+       q("DELETE FROM `item` WHERE `contact-id` = %d", intval($id));
+
+       q("DELETE FROM `photo` WHERE `contact-id` = %d", intval($id));
+
+       q("DELETE FROM `mail` WHERE `contact-id` = %d", intval($id));
+
+       q("DELETE FROM `event` WHERE `cid` = %d", intval($id));
+
+       q("DELETE FROM `queue` WHERE `cid` = %d", intval($id));
+}
+
+if (array_search(__file__, get_included_files()) === 0) {
+       remove_contact_run($_SERVER["argv"], $_SERVER["argc"]);
+       killme();
+}
+?>