]> git.mxchange.org Git - friendica.git/commitdiff
Changes to make contacts delete all content from the user when a user is deleted.
authorzottel <github@zottel.net>
Fri, 2 Nov 2012 20:43:47 +0000 (21:43 +0100)
committerzottel <github@zottel.net>
Fri, 2 Nov 2012 20:43:47 +0000 (21:43 +0100)
NOTE: I didn't add "AND account_removed = 0" to facebook.php because I don't
have a clone of the addons repository. Please someone do that for me. Thanks.

Please check carefully. I tested locally on my server, but not with other
servers.

15 files changed:
include/Contact.php
include/api.php
include/auth.php
include/delivery.php
include/diaspora.php
include/notifier.php
include/oauth.php
include/poller.php
mod/dfrn_notify.php
mod/openid.php
mod/post.php
mod/profile.php
mod/pubsub.php
mod/receive.php
mod/salmon.php

index ecc271a8e0bf6242b99c33fbb613b8fe3ac6673a..1a7a1676a79bb3925a7ad0a781d025cb863b2fa9 100644 (file)
@@ -22,7 +22,8 @@ function user_remove($uid) {
                $r[0]['nickname']
        );
 
-       q("DELETE FROM `contact` WHERE `uid` = %d", intval($uid));
+       // 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));
        q("DELETE FROM `group` WHERE `uid` = %d", intval($uid));
        q("DELETE FROM `group_member` WHERE `uid` = %d", intval($uid));
@@ -41,7 +42,10 @@ function user_remove($uid) {
        q("DELETE FROM `pconfig` WHERE `uid` = %d", intval($uid));
        q("DELETE FROM `search` WHERE `uid` = %d", intval($uid));
        q("DELETE FROM `spam` WHERE `uid` = %d", intval($uid));
-       q("DELETE FROM `user` WHERE `uid` = %d", intval($uid));
+       // don't delete yet, will be done later when contacts have deleted my stuff
+       // q("DELETE FROM `user` WHERE `uid` = %d", intval($uid));
+       q("UPDATE `user` SET `account_removed` = 1, `account_expires_on` = UTC_TIMESTAMP() WHERE `uid` = %d", intval($uid));
+       proc_run('php', "include/notifier.php", "removeme", $uid);
        if($uid == local_user()) {
                unset($_SESSION['authenticated']);
                unset($_SESSION['uid']);
index 456d984de17fb287276695842fe28b0cfaa73b57..7517abb70c4e44853d200991902ec1c6b15ecafd 100644 (file)
@@ -74,7 +74,7 @@
                // process normal login request
 
                $r = q("SELECT * FROM `user` WHERE ( `email` = '%s' OR `nickname` = '%s' ) 
-                       AND `password` = '%s' AND `blocked` = 0 AND `account_expired` = 0 AND `verified` = 1 LIMIT 1",
+                       AND `password` = '%s' AND `blocked` = 0 AND `account_expired` = 0 AND `account_removed` = 0 AND `verified` = 1 LIMIT 1",
                        dbesc(trim($user)),
                        dbesc(trim($user)),
                        dbesc($encrypted)
index c4f1f08651a286d029ea7c3411b1d2dce9607aac..523de88ce9d839e404f63e2ca0b6ab8b8ec7a07b 100644 (file)
@@ -59,7 +59,7 @@ if((isset($_SESSION)) && (x($_SESSION,'authenticated')) && ((! (x($_POST,'auth-p
                }
 
                $r = q("SELECT `user`.*, `user`.`pubkey` as `upubkey`, `user`.`prvkey` as `uprvkey` 
-               FROM `user` WHERE `uid` = %d AND `blocked` = 0 AND `account_expired` = 0 AND `verified` = 1 LIMIT 1",
+               FROM `user` WHERE `uid` = %d AND `blocked` = 0 AND `account_expired` = 0 AND `account_removed` = 0 AND `verified` = 1 LIMIT 1",
                        intval($_SESSION['uid'])
                );
 
@@ -147,7 +147,7 @@ else {
 
                        $r = q("SELECT `user`.*, `user`.`pubkey` as `upubkey`, `user`.`prvkey` as `uprvkey`  
                                FROM `user` WHERE ( `email` = '%s' OR `nickname` = '%s' ) 
-                               AND `password` = '%s' AND `blocked` = 0 AND `account_expired` = 0 AND `verified` = 1 LIMIT 1",
+                               AND `password` = '%s' AND `blocked` = 0 AND `account_expired` = 0 AND `account_removed` = 0 AND `verified` = 1 LIMIT 1",
                                dbesc(trim($_POST['username'])),
                                dbesc(trim($_POST['username'])),
                                dbesc($encrypted)
index 14226e4fba8a97b3473f12e91a68060ee60af307..613453bc7adec9985087c37b644f759c94b315cc 100644 (file)
@@ -323,7 +323,7 @@ function delivery_run($argv, $argc){
                                                WHERE `contact`.`blocked` = 0 AND `contact`.`pending` = 0
                                                AND `contact`.`network` = '%s' AND `user`.`nickname` = '%s'
                                                $sql_extra
-                                               AND `user`.`account_expired` = 0 LIMIT 1",
+                                               AND `user`.`account_expired` = 0 AND `user`.`account_removed` = 0 LIMIT 1",
                                                dbesc(NETWORK_DFRN),
                                                dbesc($nickname)
                                        );
index c5b724509c0d5858b63ba8686d819297c035edbc..f645aeb39b86a0ea62f24419a30bde0b8937b42e 100755 (executable)
@@ -16,7 +16,7 @@ function diaspora_dispatch_public($msg) {
                return;
        }
 
-       $r = q("SELECT `user`.* FROM `user` WHERE `user`.`uid` IN ( SELECT `contact`.`uid` FROM `contact` WHERE `contact`.`network` = '%s' AND `contact`.`addr` = '%s' ) AND `account_expired` = 0 ",
+       $r = q("SELECT `user`.* FROM `user` WHERE `user`.`uid` IN ( SELECT `contact`.`uid` FROM `contact` WHERE `contact`.`network` = '%s' AND `contact`.`addr` = '%s' ) AND `account_expired` = 0 AND `account_removed` = 0 ",
                dbesc(NETWORK_DIASPORA),
                dbesc($msg['author'])
        );
index 171b55fc37425f0fa513be5266cbfeab0933c7ad..a999c3297b4c55cc3096f723c55b5302a9d2d23a 100644 (file)
@@ -134,6 +134,20 @@ function notifier_run($argv, $argc){
                $recipients[] = $suggest[0]['cid'];
                $item = $suggest[0];
        }
+       elseif($cmd === 'removeme') {
+               $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($item_id));
+               $user = $r[0];
+               $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1", intval($item_id));
+               $self = $r[0];
+               $r = q("SELECT * FROM `contact` WHERE `self` = 0 AND `uid` = %d", intval($item_id));
+               if(! count($r))
+                       return;
+               require_once('include/Contact.php');
+               foreach($r as $contact) {
+                       terminate_friendship($user, $self, $contact);
+               }
+               return;
+       }
        else {
 
                // find ancestors
@@ -575,7 +589,7 @@ function notifier_run($argv, $argc){
                                                        AND `contact`.`pending` = 0
                                                        AND `contact`.`network` = '%s' AND `user`.`nickname` = '%s'
                                                        $sql_extra
-                                                       AND `user`.`account_expired` = 0 LIMIT 1",
+                                                       AND `user`.`account_expired` = 0 AND `user`.`account_removed` = 0 LIMIT 1",
                                                        dbesc(NETWORK_DFRN),
                                                        dbesc($nickname)
                                                );
index 103d4c2fa9458a306f4f37e1600f8d493595678a..28ac4428f0c22844720463b277978d76c9789eb5 100644 (file)
@@ -133,7 +133,7 @@ class FKOAuth1 extends OAuthServer {
        function loginUser($uid){
                logger("FKOAuth1::loginUser $uid");
                $a = get_app();
-               $r = q("SELECT * FROM `user` WHERE uid=%d AND `blocked` = 0 AND `account_expired` = 0 AND `verified` = 1 LIMIT 1",
+               $r = q("SELECT * FROM `user` WHERE uid=%d AND `blocked` = 0 AND `account_expired` = 0 AND `account_removed` = 0 AND `verified` = 1 LIMIT 1",
                        intval($uid)
                );
                if(count($r)){
index fefc9b381d4a6c18d74cdb20eff26b57aaa42a38..ce8399a485baa52970234e31b0a959cb645d0613 100644 (file)
@@ -67,6 +67,16 @@ function poller_run($argv, $argc){
        q("UPDATE user SET `account_expired` = 1 where `account_expired` = 0 
                AND `account_expires_on` != '0000-00-00 00:00:00' 
                AND `account_expires_on` < UTC_TIMESTAMP() ");
+       
+       // delete user and contact records for recently removed accounts
+
+       $r = q("SELECT * FROM `user` WHERE `account_removed` = 1 AND `account_expires_on` < UTC_TIMESTAMP() - INTERVAL 3 DAY");
+       if (count($r)) {
+               foreach($r as $user) {
+                       q("DELETE FROM `contact` WHERE `uid` = %d", intval($user['uid']));
+                       q("DELETE FROM `user` WHERE `uid` = %d", intval($user['uid']));
+               }
+       }
   
        $abandon_days = intval(get_config('system','account_abandon_days'));
        if($abandon_days < 1)
@@ -154,7 +164,7 @@ function poller_run($argv, $argc){
                $sql_extra 
                AND `self` = 0 AND `contact`.`blocked` = 0 AND `contact`.`readonly` = 0 
                AND `contact`.`archive` = 0 
-               AND `user`.`account_expired` = 0 $abandon_sql ORDER BY RAND()",
+               AND `user`.`account_expired` = 0 AND `user`.`account_removed` = 0 $abandon_sql ORDER BY RAND()",
                intval(CONTACT_IS_SHARING),
                intval(CONTACT_IS_FRIEND),
                dbesc(NETWORK_DIASPORA),
index e55da557223c8e9708881e331b16664f89092ea8..476212b7afdb17624ac4a2090836915322101160 100644 (file)
@@ -77,7 +77,7 @@ function dfrn_notify_post(&$a) {
                        FROM `contact` 
                        LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid` 
                        WHERE `contact`.`blocked` = 0 AND `contact`.`pending` = 0 
-                               AND `user`.`nickname` = '%s' AND `user`.`account_expired` = 0 $sql_extra LIMIT 1",
+                               AND `user`.`nickname` = '%s' AND `user`.`account_expired` = 0 AND `user`.`account_removed` = 0 $sql_extra LIMIT 1",
                dbesc($a->argv[1])
        );
 
@@ -220,7 +220,7 @@ function dfrn_notify_content(&$a) {
 
                $r = q("SELECT `contact`.*, `user`.`nickname`, `user`.`page-flags` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid` 
                                WHERE `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `user`.`nickname` = '%s' 
-                               AND `user`.`account_expired` = 0 $sql_extra LIMIT 1",
+                               AND `user`.`account_expired` = 0 AND `user`.`account_removed` = 0 $sql_extra LIMIT 1",
                                dbesc($a->argv[1])
                );
 
index e2cea7d851041211610748b3483a1fcd29193ba9..5d5539f00eb4e696429903179c1ae1b8022136d7 100644 (file)
@@ -27,7 +27,7 @@ function openid_content(&$a) {
 
                        $r = q("SELECT `user`.*, `user`.`pubkey` as `upubkey`, `user`.`prvkey` as `uprvkey` 
                                FROM `user` WHERE `openid` = '%s' AND `blocked` = 0 
-                               AND `account_expired` = 0 AND `verified` = 1 LIMIT 1",
+                               AND `account_expired` = 0 AND `account_removed` = 0 AND `verified` = 1 LIMIT 1",
                                dbesc($authid)
                        );
 
index 4a7e33b23bd9e77a42838a3482608909b19fca31..c0e783a6aaded3cb6ea126bfd177eb50cb76e4df 100644 (file)
@@ -20,7 +20,7 @@ function post_post(&$a) {
        else {
                $nickname = $a->argv[2];
                $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' 
-                               AND `account_expired` = 0 LIMIT 1",
+                               AND `account_expired` = 0 AND `account_removed` = 0 LIMIT 1",
                        dbesc($nickname)
                );
                if(! count($r))
index 6a80909e736c19df277cb435e0fc31f087866f5c..827166f92731135c093061981eec72176c43393b 100644 (file)
@@ -12,7 +12,7 @@ function profile_init(&$a) {
        if($a->argc > 1)
                $which = $a->argv[1];
        else {
-               $r = q("select nickname from user where blocked = 0 and account_expired = 0 and verified = 1 order by rand() limit 1");
+               $r = q("select nickname from user where blocked = 0 and account_expired = 0 and account_removed = 0 and verified = 1 order by rand() limit 1");
                if(count($r)) {
                        goaway($a->get_baseurl() . '/profile/' . $r[0]['nickname']);
                }
index 64fbda289f674145f8abf216eff38f1b6dc1e56a..0e29628b8079bd34392657252582e9d7bd875963 100644 (file)
@@ -44,7 +44,7 @@ function pubsub_init(&$a) {
 
                $subscribe = (($hub_mode === 'subscribe') ? 1 : 0);
 
-               $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `account_expired` = 0 LIMIT 1",
+               $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `account_expired` = 0 AND `account_removed` = 0 LIMIT 1",
                        dbesc($nick)
                );
                if(! count($r)) {
@@ -112,7 +112,7 @@ function pubsub_post(&$a) {
        $nick       = (($a->argc > 1) ? notags(trim($a->argv[1])) : '');
        $contact_id = (($a->argc > 2) ? intval($a->argv[2])       : 0 );
 
-       $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `account_expired` = 0 LIMIT 1",
+       $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `account_expired` = 0 AND `account_removed` = 0 LIMIT 1",
                dbesc($nick)
        );
        if(! count($r))
index 2bd3cc65bcda1b5ae273d9903184981805b8d33a..0523fd9cc5df45812613f3162932c7dd7a1d2a90 100644 (file)
@@ -31,7 +31,7 @@ function receive_post(&$a) {
 
                $guid = $a->argv[2];
 
-               $r = q("SELECT * FROM `user` WHERE `guid` = '%s' AND `account_expired` = 0 LIMIT 1",
+               $r = q("SELECT * FROM `user` WHERE `guid` = '%s' AND `account_expired` = 0 AND `account_removed` = 0 LIMIT 1",
                        dbesc($guid)
                );
                if(! count($r))
index 1e16f9d14ba1d2e6b7b8fff8886b24adbcdef04d..5df1e1c9e541b9d332942fb629e65f42cfdeb8b1 100644 (file)
@@ -30,7 +30,7 @@ function salmon_post(&$a) {
        $nick       = (($a->argc > 1) ? notags(trim($a->argv[1])) : '');
        $mentions   = (($a->argc > 2 && $a->argv[2] === 'mention') ? true : false);
 
-       $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `account_expired` = 0 LIMIT 1",
+       $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `account_expired` = 0 AND `account_removed` = 0 LIMIT 1",
                dbesc($nick)
        );
        if(! count($r))