]> git.mxchange.org Git - friendica.git/commitdiff
The query condition for active users are unified
authorMichael <heluecht@pirati.ca>
Fri, 8 Sep 2023 15:01:51 +0000 (15:01 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 8 Sep 2023 15:01:51 +0000 (15:01 +0000)
19 files changed:
mod/lostpass.php
src/Model/Contact.php
src/Model/Profile.php
src/Model/User.php
src/Module/Moderation/BaseUsers.php
src/Module/Moderation/Users/Active.php
src/Module/OStatus/PubSub.php
src/Module/OStatus/PubSubHubBub.php
src/Module/OStatus/Salmon.php
src/Module/Profile/Profile.php
src/Module/Security/OpenID.php
src/Protocol/DFRN.php
src/Protocol/Diaspora.php
src/Worker/Cron.php
src/Worker/Directory.php
src/Worker/ExpireAndRemoveUsers.php
src/Worker/PollContacts.php
src/Worker/UpdatePhotoAlbums.php
src/Worker/UpdateScores.php

index 6505db549723fc540fb89b0257b8400c71eb576e..5eb53ae2f393d0022c365d398f2aa3523dd59dee 100644 (file)
@@ -34,7 +34,7 @@ function lostpass_post(App $a)
                DI::baseUrl()->redirect();
        }
 
-       $condition = ['(`email` = ? OR `nickname` = ?) AND `verified` = 1 AND `blocked` = 0 AND `account_removed` = 0 AND `account_expired` = 0', $loginame, $loginame];
+       $condition = ['(`email` = ? OR `nickname` = ?) AND `verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired`', $loginame, $loginame];
        $user = DBA::selectFirst('user', ['uid', 'username', 'nickname', 'email', 'language'], $condition);
        if (!DBA::isResult($user)) {
                DI::sysmsg()->addNotice(DI::l10n()->t('No valid account found.'));
index 944ff39cd575ba57f390ff914141b8bae8979baa..243b48ad1d2124c6c08724f41f21bbdf1fe293f9 100644 (file)
@@ -750,7 +750,7 @@ class Contact
                $user = DBA::selectFirst(
                        'user',
                        ['uid', 'username', 'nickname', 'pubkey', 'prvkey'],
-                       ['uid' => $uid, 'account_expired' => false]
+                       ['uid' => $uid, 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]
                );
                if (!DBA::isResult($user)) {
                        return false;
@@ -822,7 +822,7 @@ class Contact
                }
 
                $fields = ['uid', 'username', 'nickname', 'page-flags', 'account-type', 'prvkey', 'pubkey'];
-               $user = DBA::selectFirst('user', $fields, ['uid' => $uid, 'account_expired' => false]);
+               $user = DBA::selectFirst('user', $fields, ['uid' => $uid, 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]);
                if (!DBA::isResult($user)) {
                        return false;
                }
index c1a350673e1bafe995bcec7719491f42fa6e0f80..b80c83881adda94b03b4788306bbcd476d7a3019 100644 (file)
@@ -940,7 +940,7 @@ class Profile
                if (!empty($search)) {
                        $publish = (DI::config()->get('system', 'publish_all') ? '' : "AND `publish` ");
                        $searchTerm = '%' . $search . '%';
-                       $condition = ["NOT `blocked` AND NOT `account_removed`
+                       $condition = ["`verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired`
                                $publish
                                AND ((`name` LIKE ?) OR
                                (`nickname` LIKE ?) OR
@@ -953,7 +953,7 @@ class Profile
                                $searchTerm, $searchTerm, $searchTerm, $searchTerm,
                                $searchTerm, $searchTerm, $searchTerm, $searchTerm];
                } else {
-                       $condition = ['blocked' => false, 'account_removed' => false];
+                       $condition = ['verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false];
                        if (!DI::config()->get('system', 'publish_all')) {
                                $condition['publish'] = true;
                        }
index b4df99d82c38ae5d7984c88db4019a658a2ff492..3505f3b7affc27325bb8318d29d693d74243d59a 100644 (file)
@@ -280,8 +280,7 @@ class User
                // List of possible actor names
                $possible_accounts = ['friendica', 'actor', 'system', 'internal'];
                foreach ($possible_accounts as $name) {
-                       if (!DBA::exists('user', ['nickname' => $name, 'account_removed' => false, 'account_expired' => false]) &&
-                               !DBA::exists('userd', ['username' => $name])) {
+                       if (!DBA::exists('user', ['nickname' => $name]) && DBA::exists('userd', ['username' => $name])) {
                                DI::config()->set('system', 'actor_name', $name);
                                return $name;
                        }
@@ -326,7 +325,7 @@ class User
        public static function getByGuid(string $guid, array $fields = [], bool $active = true)
        {
                if ($active) {
-                       $cond = ['guid' => $guid, 'account_expired' => false, 'account_removed' => false];
+                       $cond = ['guid' => $guid, 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false];
                } else {
                        $cond = ['guid' => $guid];
                }
@@ -702,7 +701,7 @@ class User
                                $fields = ['uid', 'nickname', 'password', 'legacy_password'];
                                $condition = [
                                        "(`email` = ? OR `username` = ? OR `nickname` = ?)
-                                       AND NOT `blocked` AND NOT `account_expired` AND NOT `account_removed` AND `verified`",
+                                       AND `verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired`",
                                        $user_info, $user_info, $user_info
                                ];
                                $user = DBA::selectFirst('user', $fields, $condition);
@@ -738,7 +737,7 @@ class User
                if ($user['last-activity'] != $current_day) {
                        User::update(['last-activity' => $current_day], $uid);
                        // Set the last activity for all identities of the user
-                       DBA::update('user', ['last-activity' => $current_day], ['parent-uid' => $uid, 'account_removed' => false]);
+                       DBA::update('user', ['last-activity' => $current_day], ['parent-uid' => $uid, 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]);
                }
        }
 
@@ -1703,7 +1702,7 @@ class User
 
                $identities = [];
 
-               $user = DBA::selectFirst('user', ['uid', 'nickname', 'username', 'parent-uid'], ['uid' => $uid]);
+               $user = DBA::selectFirst('user', ['uid', 'nickname', 'username', 'parent-uid'], ['uid' => $uid, 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]);
                if (!DBA::isResult($user)) {
                        return $identities;
                }
@@ -1720,7 +1719,7 @@ class User
                        $r = DBA::select(
                                'user',
                                ['uid', 'username', 'nickname'],
-                               ['parent-uid' => $user['uid'], 'account_removed' => false]
+                               ['parent-uid' => $user['uid'], 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]
                        );
                        if (DBA::isResult($r)) {
                                $identities = array_merge($identities, DBA::toArray($r));
@@ -1730,7 +1729,7 @@ class User
                        $r = DBA::select(
                                'user',
                                ['uid', 'username', 'nickname'],
-                               ['uid' => $user['parent-uid'], 'account_removed' => false]
+                               ['uid' => $user['parent-uid'], 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]
                        );
                        if (DBA::isResult($r)) {
                                $identities = DBA::toArray($r);
@@ -1740,7 +1739,7 @@ class User
                        $r = DBA::select(
                                'user',
                                ['uid', 'username', 'nickname'],
-                               ['parent-uid' => $user['parent-uid'], 'account_removed' => false]
+                               ['parent-uid' => $user['parent-uid'], 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]
                        );
                        if (DBA::isResult($r)) {
                                $identities = array_merge($identities, DBA::toArray($r));
@@ -1751,7 +1750,7 @@ class User
                        "SELECT `user`.`uid`, `user`.`username`, `user`.`nickname`
                        FROM `manage`
                        INNER JOIN `user` ON `manage`.`mid` = `user`.`uid`
-                       WHERE `user`.`account_removed` = 0 AND `manage`.`uid` = ?",
+                       WHERE NOT `user`.`account_removed` AND `manage`.`uid` = ?",
                        $user['uid']
                );
                if (DBA::isResult($r)) {
@@ -1773,7 +1772,7 @@ class User
                        return false;
                }
 
-               $user = DBA::selectFirst('user', ['parent-uid'], ['uid' => $uid, 'account_removed' => false]);
+               $user = DBA::selectFirst('user', ['parent-uid'], ['uid' => $uid, 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]);
                if (!DBA::isResult($user)) {
                        return false;
                }
@@ -1782,7 +1781,7 @@ class User
                        return true;
                }
 
-               if (DBA::exists('user', ['parent-uid' => $uid, 'account_removed' => false])) {
+               if (DBA::exists('user', ['parent-uid' => $uid, 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false])) {
                        return true;
                }
 
index 2d352dbdc3e1462ec21f1e331a98ccd6c36f9057..33a013961f9a026c4d2fcc5da98f62d05cc61d4f 100644 (file)
@@ -59,7 +59,7 @@ abstract class BaseUsers extends BaseModeration
        protected function getTabsHTML(string $selectedTab): string
        {
                $all     = $this->database->count('user', ["`uid` != ?", 0]);
-               $active  = $this->database->count('user', ["NOT `blocked` AND `verified` AND NOT `account_removed` AND `uid` != ?", 0]);
+               $active  = $this->database->count('user', ["`verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired` AND `uid` != ?", 0]);
                $pending = Register::getPendingCount();
                $blocked = $this->database->count('user', ['blocked' => true, 'verified' => true, 'account_removed' => false]);
                $deleted = $this->database->count('user', ['account_removed' => true]);
index c4805b7b00b8ed98a5f5bf81975737d025e2fe9e..1476578e03faf068352e74076d2768e79ce9a5a0 100644 (file)
@@ -125,7 +125,7 @@ class Active extends BaseUsers
 
                $th_users = array_map(null, [$this->t('Name'), $this->t('Email'), $this->t('Register date'), $this->t('Last login'), $this->t('Last public item'), $this->t('Type')], $valid_orders);
 
-               $count = $this->database->count('user', ["NOT `blocked` AND `verified` AND NOT `account_removed` AND `uid` != ?", 0]);
+               $count = $this->database->count('user', ["`verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired` AND `uid` != ?", 0]);
 
                $t = Renderer::getMarkupTemplate('moderation/users/active.tpl');
                return self::getTabsHTML('active') . Renderer::replaceMacros($t, [
index 5fbc5298369d262132e8d866da26ba9357c2d62c..f1f3266cb81a4f5beb183bc403ffb66e4066b470 100644 (file)
@@ -63,7 +63,7 @@ class PubSub extends \Friendica\BaseModule
                $nickname   = $this->parameters['nickname'] ?? '';
                $contact_id = $this->parameters['cid']      ?? 0;
 
-               $importer = $this->database->selectFirst('user', [], ['nickname' => $nickname, 'account_expired' => false, 'account_removed' => false]);
+               $importer = $this->database->selectFirst('user', [], ['nickname' => $nickname, 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]);
                if (!$importer) {
                        throw new HTTPException\OKException();
                }
@@ -119,7 +119,7 @@ class PubSub extends \Friendica\BaseModule
                $this->logger->notice('Subscription start.', ['from' => $this->request->getRemoteAddress(), 'mode' => $hub_mode, 'nickname' => $nickname]);
                $this->logger->debug('Data: ', ['get' => $request]);
 
-               $owner = $this->database->selectFirst('user', ['uid'], ['nickname' => $nickname, 'account_expired' => false, 'account_removed' => false]);
+               $owner = $this->database->selectFirst('user', ['uid'], ['nickname' => $nickname, 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]);
                if (!$owner) {
                        $this->logger->notice('Local account not found.', ['nickname' => $nickname]);
                        throw new HTTPException\NotFoundException();
index caaa31f98b18646bc4fdd4d1188ba483f28a5c4c..c8fcb4249b814fa79183cf8f75387faad0ad6770 100644 (file)
@@ -111,7 +111,7 @@ class PubSubHubBub extends \Friendica\BaseModule
                }
 
                // fetch user from database given the nickname
-               $condition = ['nickname' => $nickname, 'account_expired' => false, 'account_removed' => false];
+               $condition = ['nickname' => $nickname, 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false];
                $owner     = $this->database->selectFirst('user', ['uid', 'nickname'], $condition);
                if (!$owner) {
                        $this->logger->notice('Local account not found', ['nickname' => $nickname, 'topic' => $hub_topic, 'callback' => $hub_callback]);
index 889d852d961f955437253ca0e8b1403ba299c128..9f064869287aa7e08b4f23792ad21a3f8e92902c 100644 (file)
@@ -74,7 +74,7 @@ class Salmon extends \Friendica\BaseModule
 
                $this->logger->debug('New Salmon', ['nickname' => $nickname, 'xml' => $xml]);
 
-               $importer = $this->database->selectFirst('user', [], ['nickname' => $nickname, 'account_expired' => false, 'account_removed' => false]);
+               $importer = $this->database->selectFirst('user', [], ['nickname' => $nickname, 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]);
                if (!$this->database->isResult($importer)) {
                        throw new HTTPException\InternalServerErrorException();
                }
index 054943c135a71f2a413f931b05a48e2ac8a490ae..99262fcc50db6312083fccdebffcc32af9db43f6 100644 (file)
@@ -81,7 +81,7 @@ class Profile extends BaseProfile
        protected function rawContent(array $request = [])
        {
                if (ActivityPub::isRequest()) {
-                       $user = $this->database->selectFirst('user', ['uid'], ['nickname' => $this->parameters['nickname'] ?? '', 'account_removed' => false]);
+                       $user = $this->database->selectFirst('user', ['uid'], ['nickname' => $this->parameters['nickname'] ?? '', 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]);
                        if ($user) {
                                try {
                                        $data = ActivityPub\Transmitter::getProfile($user['uid'], ActivityPub::isAcceptedRequester($user['uid']));
index e0a13954dd9b55b5ad738816663d1a086ac88c76..3db063f28ca914ab472ea40c34d435b308354dbe 100644 (file)
@@ -60,7 +60,7 @@ class OpenID extends BaseModule
                                //       in commit 8367cadeeffec4b6792a502847304b17ceba5882, so it might
                                //       have left mixed records in the user table
                                //
-                               $condition = ['blocked' => false, 'account_expired' => false, 'account_removed' => false, 'verified' => true,
+                               $condition = ['verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false,
                                              'openid' => [$authId, Strings::normaliseOpenID($authId)]];
 
                                $dba = DI::dba();
index 1fcaaba7f706a7b2c57fc26676fbc2ac8d8791dc..1ab12089de0c0ff588262be44388ddda9b68e425 100644 (file)
@@ -88,7 +88,7 @@ class DFRN
                $contact['senderName'] = $contact['name'];
 
                if ($uid != 0) {
-                       $condition = ['uid' => $uid, 'account_expired' => false, 'account_removed' => false];
+                       $condition = ['uid' => $uid, 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false];
                        $user = DBA::selectFirst('user', [], $condition);
                        if (!DBA::isResult($user)) {
                                return [];
index dd6c2115b5e32714a868bae0ee589465ca76bf31..8bdb878abe10f90bcf0e551ce2fe0a5f826b7844 100644 (file)
@@ -3062,10 +3062,7 @@ class Diaspora
                // If the item belongs to a user, we take this user id.
                if ($item['uid'] == 0) {
                        // @todo Possibly use an administrator account?
-                       $condition = [
-                               'verified' => true, 'blocked' => false,
-                               'account_removed' => false, 'account_expired' => false, 'account-type' => User::ACCOUNT_TYPE_PERSON
-                       ];
+                       $condition = ['verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false, 'account-type' => User::ACCOUNT_TYPE_PERSON];
                        $first_user = DBA::selectFirst('user', ['uid'], $condition, ['order' => ['uid']]);
                        $owner = User::getOwnerDataById($first_user['uid']);
                } else {
index 6ba68d1770d4c071d4bc46f23b312d300cfea75a..accf76d56e1dd6fd7180f45412da3a8983b6cb18 100644 (file)
@@ -145,7 +145,7 @@ class Cron
                        DBA::close($users);
 
                        // Update contact relations for our users
-                       $users = DBA::select('user', ['uid'], ["NOT `account_expired` AND NOT `account_removed` AND `uid` > ?", 0]);
+                       $users = DBA::select('user', ['uid'], ["`verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired` AND `uid` > ?", 0]);
                        while ($user = DBA::fetch($users)) {
                                Worker::add(Worker::PRIORITY_LOW, 'ContactDiscoveryForUser', $user['uid']);
                        }
index b66b662d4c8c4432d937d534d42c9098caf343ff..2d56cb3c0873bfe73b7ff5ac2d63161f98ad69a7 100644 (file)
@@ -62,7 +62,7 @@ class Directory
        }
 
        private static function updateAll() {
-               $users = DBA::select('owner-view', ['url'], ['net-publish' => true, 'account_expired' => false, 'verified' => true]);
+               $users = DBA::select('owner-view', ['url'], ['net-publish' => true, 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]);
                while ($user = DBA::fetch($users)) {
                        Worker::add(Worker::PRIORITY_LOW, 'Directory', $user['url']);
                }
index c04741462d458a2265a1edcfa915b9a3c8a21b97..47c3e9a60f757707a182721f58b684b03c401b4d 100644 (file)
@@ -42,7 +42,7 @@ class ExpireAndRemoveUsers
                DBA::update('user', ['account_expired' => true], $condition);
 
                // Ensure to never remove the user with uid=0
-               DBA::update('user', ['account_expired' => false, 'account_removed' => false,
+               DBA::update('user', ['verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false,
                        'account_expires_on' => DBA::NULL_DATETIME], ['uid' => 0]);
 
                // Remove any freshly expired account
index 81ce0f8f0e7457255c6cf5aa2793e8a6ed0b42ec..80b7ae4456f176650804dd8ac63a6b9572b9d24d 100644 (file)
@@ -45,10 +45,10 @@ class PollContacts
 
                if (!empty($abandon_days)) {
                        $condition = DBA::mergeConditions($condition,
-                               ["`uid` != ? AND `uid` IN (SELECT `uid` FROM `user` WHERE NOT `blocked` AND NOT `account_expired` AND NOT `account_removed` AND `last-activity` > ?)", 0, DateTimeFormat::utc('now - ' . $abandon_days . ' days')]);
+                               ["`uid` != ? AND `uid` IN (SELECT `uid` FROM `user` WHERE `verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired` AND `last-activity` > ?)", 0, DateTimeFormat::utc('now - ' . $abandon_days . ' days')]);
                } else  {
                        $condition = DBA::mergeConditions($condition,
-                               ["`uid` != ? AND `uid` IN (SELECT `uid` FROM `user` WHERE NOT `blocked` AND NOT `account_expired` AND NOT `account_removed`)", 0]);
+                               ["`uid` != ? AND `uid` IN (SELECT `uid` FROM `user` WHERE `verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired`)", 0]);
                }
 
                $contacts = DBA::select('contact', ['id', 'nick', 'name', 'network', 'archive', 'last-update', 'priority', 'rating'], $condition);
index 234ee63135ef30e73f71d97f93695b1bdf3e5227..a0e3bca02778939071ed2f1d9fddff6d08d0b8f1 100644 (file)
@@ -31,7 +31,7 @@ class UpdatePhotoAlbums
 {
        public static function execute()
        {
-               $users = DBA::select('user', ['uid'], ['account_expired' => false, 'account_removed' => false]);
+               $users = DBA::select('user', ['uid'], ['verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]);
                while ($user = DBA::fetch($users)) {
                        Photo::clearAlbumCache($user['uid']);
                }
index 1f02bf4157de7757435ffbe70b31b75b4d721c12..f17027a09d26b3bf063b738b580c4a3ccd058564 100644 (file)
@@ -35,7 +35,7 @@ class UpdateScores
        {
                Logger::notice('Start score update');
 
-               $users = DBA::select('user', ['uid'], ["NOT `account_expired` AND NOT `account_removed` AND `uid` > ?", 0]);
+               $users = DBA::select('user', ['uid'], ["`verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired` AND `uid` > ?", 0]);
                while ($user = DBA::fetch($users)) {
                        Relation::calculateInteractionScore($user['uid']);
                }