]> git.mxchange.org Git - friendica.git/commitdiff
Issue 5260: Ensure that user data is really deleted (#5666)
authorMichael Vogel <icarus@dabo.de>
Sat, 25 Aug 2018 21:48:50 +0000 (21:48 +0000)
committerHypolite Petovan <mrpetovan@eml.cc>
Sat, 25 Aug 2018 21:48:50 +0000 (17:48 -0400)
* Issue 5260: Ensure that user data is really deleted

* Missing files

src/Model/User.php
src/Worker/CronJobs.php
src/Worker/RemoveUser.php [new file with mode: 0644]

index cfb2da997fd70b2530b3366f3cded9aec5c1879d..a43ef06f970619105a9cd8e29f84f86972697aa5 100644 (file)
@@ -730,13 +730,16 @@ class User
                DBA::insert('userd', ['username' => $user['nickname']]);
 
                // The user and related data will be deleted in "cron_expire_and_remove_users" (cronjobs.php)
-               DBA::update('user', ['account_removed' => true, 'account_expires_on' => DateTimeFormat::utcNow()], ['uid' => $uid]);
+               DBA::update('user', ['account_removed' => true, 'account_expires_on' => DateTimeFormat::utc($t . " + 7 day")], ['uid' => $uid]);
                Worker::add(PRIORITY_HIGH, "Notifier", "removeme", $uid);
 
                // Send an update to the directory
                $self = DBA::selectFirst('contact', ['url'], ['uid' => $uid, 'self' => true]);
                Worker::add(PRIORITY_LOW, "Directory", $self['url']);
 
+               // Remove the user relevant data
+               Worker::add(PRIORITY_LOW, "RemoveUser", $uid);
+
                if ($uid == local_user()) {
                        unset($_SESSION['authenticated']);
                        unset($_SESSION['uid']);
index 950dd71af6035f99a7daf62b84332e1533be2bfa..098bce4d96a0407a19be9bdbb3a2b20323fef4ea 100644 (file)
@@ -120,6 +120,12 @@ class CronJobs
                // delete user records for recently removed accounts
                $users = DBA::select('user', ['uid'], ["`account_removed` AND `account_expires_on` < UTC_TIMESTAMP() - INTERVAL 3 DAY"]);
                while ($user = DBA::fetch($users)) {
+                       // Delete the contacts of this user
+                       $self = DBA::selectFirst('contact', ['nurl'], ['self' => true, 'uid' => $user['uid']]);
+                       if (DBA::isResult($self)) {
+                               DBA::delete('contact', ['nurl' => $self['nurl'], 'self' => false]);
+                       }
+
                        DBA::delete('user', ['uid' => $user['uid']]);
                }
        }
diff --git a/src/Worker/RemoveUser.php b/src/Worker/RemoveUser.php
new file mode 100644 (file)
index 0000000..dfa5ccc
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+/**
+ * @file src/Worker/RemoveUser.php
+ * @brief Removes orphaned data from deleted users
+ */
+namespace Friendica\Worker;
+
+use Friendica\Database\DBA;
+use Friendica\Model\Item;
+
+require_once 'include/dba.php';
+
+class RemoveUser {
+       public static function execute($uid)
+       {
+               // Only delete if the user is archived
+               $condition = ['account_removed' => true, 'uid' => $uid];
+               if (!DBA::exists('user', $condition)) {
+                       return;
+               }
+
+               // Now we delete all user items
+               Item::delete(['uid' => $uid], PRIORITY_LOW);
+       }
+}