]> git.mxchange.org Git - friendica.git/commitdiff
Issue 10518: "last-activity" instead of "login_date"
authorMichael <heluecht@pirati.ca>
Sun, 4 Dec 2022 07:03:11 +0000 (07:03 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 4 Dec 2022 07:03:11 +0000 (07:03 +0000)
13 files changed:
database.sql
src/Console/User.php
src/Model/User.php
src/Module/Moderation/BaseUsers.php
src/Module/Moderation/Users/Active.php
src/Module/Moderation/Users/Blocked.php
src/Module/Moderation/Users/Deleted.php
src/Module/Moderation/Users/Index.php
src/Module/NoScrape.php
src/Security/Authentication.php
src/Worker/PollContacts.php
static/dbstructure.config.php
static/dbview.config.php

index f41defe4284a1efd4f42a09adf53792e792cb897..830eff99142dcfa6b6a539f3d00ae858c6b544d9 100644 (file)
@@ -1,6 +1,6 @@
 -- ------------------------------------------
 -- Friendica 2022.12-dev (Giant Rhubarb)
--- DB_UPDATE_VERSION 1496
+-- DB_UPDATE_VERSION 1497
 -- ------------------------------------------
 
 
@@ -2693,6 +2693,7 @@ CREATE VIEW `owner-view` AS SELECT
        `user`.`language` AS `language`,
        `user`.`register_date` AS `register_date`,
        `user`.`login_date` AS `login_date`,
+       IF (`user`.`last-activity` IS NULL, DATE(`user`.`login_date`), `user`.`last-activity`) AS `last-activity`,
        `user`.`default-location` AS `default-location`,
        `user`.`allow_location` AS `allow_location`,
        `user`.`theme` AS `theme`,
index 25f5ceeb0781f6cfd354c2022d810e44b265e10b..0d06f427ebbe830f203f14a49638c33868a928e6 100644 (file)
@@ -370,7 +370,7 @@ HELP;
                                                $contact['url'],
                                                $contact['email'],
                                                Temporal::getRelativeDate($contact['created']),
-                                               Temporal::getRelativeDate($contact['login_date']),
+                                               Temporal::getRelativeDate($contact['last-activity']),
                                                Temporal::getRelativeDate($contact['last-item']),
                                        ]);
                                }
@@ -396,7 +396,7 @@ HELP;
                        'nickname',
                        'email',
                        'register_date',
-                       'login_date',
+                       'last-activity',
                        'verified',
                        'blocked',
                ];
index 40384b619beb3ec1c7a6c2a0c1fe51c6234630fc..2b8516c255b0d1089a8a121000b2ac0a82c279d6 100644 (file)
@@ -682,6 +682,8 @@ class User
 
                if ($user['last-activity'] != $current_day) {
                        User::update(['last-activity' => $current_day], $uid);
+                       // Set the last actitivy for all identities of the user
+                       DBA::update('user', ['last-activity' => $current_day], ['parent-uid' => $uid, 'account_removed' => false]);
                }
        }
 
@@ -1729,8 +1731,8 @@ class User
                        'active_users_weekly'   => 0,
                ];
 
-               $userStmt = DBA::select('owner-view', ['uid', 'login_date', 'last-item'],
-                       ["`verified` AND `login_date` > ? AND NOT `blocked`
+               $userStmt = DBA::select('owner-view', ['uid', 'last-activity', 'last-item'],
+                       ["`verified` AND `last-activity` > ? AND NOT `blocked`
                        AND NOT `account_removed` AND NOT `account_expired`",
                        DBA::NULL_DATETIME]);
                if (!DBA::isResult($userStmt)) {
@@ -1744,17 +1746,17 @@ class User
                while ($user = DBA::fetch($userStmt)) {
                        $statistics['total_users']++;
 
-                       if ((strtotime($user['login_date']) > $halfyear) || (strtotime($user['last-item']) > $halfyear)
+                       if ((strtotime($user['last-activity']) > $halfyear) || (strtotime($user['last-item']) > $halfyear)
                        ) {
                                $statistics['active_users_halfyear']++;
                        }
 
-                       if ((strtotime($user['login_date']) > $month) || (strtotime($user['last-item']) > $month)
+                       if ((strtotime($user['last-activity']) > $month) || (strtotime($user['last-item']) > $month)
                        ) {
                                $statistics['active_users_monthly']++;
                        }
 
-                       if ((strtotime($user['login_date']) > $week) || (strtotime($user['last-item']) > $week)
+                       if ((strtotime($user['last-activity']) > $week) || (strtotime($user['last-item']) > $week)
                        ) {
                                $statistics['active_users_weekly']++;
                        }
index b78027764691a70913db06a8abb2a109d9dcfaa7..62e41c58c92f1a6ea436e0d274bb538410834c06 100644 (file)
@@ -137,7 +137,7 @@ abstract class BaseUsers extends BaseModeration
                        $user['account_type']     = ($user['page_flags_raw'] == 0) ? $account_types[$user['account-type']] : '';
 
                        $user['register_date'] = Temporal::getRelativeDate($user['register_date']);
-                       $user['login_date']    = Temporal::getRelativeDate($user['login_date']);
+                       $user['login_date']    = Temporal::getRelativeDate($user['last-activity']);
                        $user['lastitem_date'] = Temporal::getRelativeDate($user['last-item']);
                        $user['is_admin']      = in_array($user['email'], $adminlist);
                        $user['is_deletable']  = !$user['account_removed'] && intval($user['uid']) != $this->session->getLocalUserId();
index 922351dc73ed3fd3ee3f5518265e0f671327e3df..8463f413789ab764447c1799fb44ab2081b1b32a 100644 (file)
@@ -100,7 +100,7 @@ class Active extends BaseUsers
                        'name',
                        'email',
                        'register_date',
-                       'login_date',
+                       'last-activity',
                        'last-item',
                        'page-flags',
                ];
index 022262907d75543f5a950a2962127eb4ed6c09e6..e6bb599735fbf813ba8b5204a533d71498c8dc9f 100644 (file)
@@ -100,7 +100,7 @@ class Blocked extends BaseUsers
                        'name',
                        'email',
                        'register_date',
-                       'login_date',
+                       'last-activity',
                        'last-item',
                        'page-flags',
                ];
index 2dd6d6a1b2e5575b8dd7f88d071b7279161cbbf8..8778c0a779f41887c7dcb91a15be7cdd084562a9 100644 (file)
@@ -49,7 +49,7 @@ class Deleted extends BaseUsers
                        'name',
                        'email',
                        'register_date',
-                       'login_date',
+                       'last-activity',
                        'last-item',
                        'page-flags',
                ];
index 06528650cee210b2ae5a4800cd121d077204c99a..e5cc1ae8927a33b463497cc90725c8673a18da13 100644 (file)
@@ -114,7 +114,7 @@ class Index extends BaseUsers
                        'name',
                        'email',
                        'register_date',
-                       'login_date',
+                       'last-activity',
                        'last-item',
                        'page-flags',
                ];
index 84130bd9161578dbfda4704598cf6405b7c68587..bf57ec7765c83ed2825f9e58c3bb860636245e90 100644 (file)
@@ -101,11 +101,10 @@ class NoScrape extends BaseModule
                        $last_active = strtotime($contact['last-item']);
                }
 
-               $condition = ['uid' => $owner['uid']];
-               $user      = DBA::selectFirst('user', ['login_date'], $condition);
+               $user = User::getOwnerDataById($owner['uid']);
                if (DBA::isResult($user)) {
-                       if ($last_active < strtotime($user['login_date'])) {
-                               $last_active = strtotime($user['login_date']);
+                       if ($last_active < strtotime($user['last-activity'])) {
+                               $last_active = strtotime($user['last-activity']);
                        }
                }
                $json_info['last-activity'] = date('o-W', $last_active);
index f550501ede89b915cdde05a97d8e407d1fd08111..5dcc399403004af1fafc9892b8f48aec42eb309d 100644 (file)
@@ -356,7 +356,7 @@ class Authentication
                        $this->dba->update('user', ['last-activity' => DateTimeFormat::utcNow('Y-m-d'), 'login_date' => DateTimeFormat::utcNow()], ['uid' => $user_record['uid']]);
 
                        // Set the login date for all identities of the user
-                       $this->dba->update('user', ['login_date' => DateTimeFormat::utcNow()],
+                       $this->dba->update('user', ['last-activity' => DateTimeFormat::utcNow('Y-m-d'), 'login_date' => DateTimeFormat::utcNow()],
                                ['parent-uid' => $user_record['uid'], 'account_removed' => false]);
 
                        // Regularly update suggestions
index 454b5a9aea46c80335825b4bf39543eb8d7fe808..9aea20e5df95bda974c17597b047059f5ba87c44 100644 (file)
@@ -45,7 +45,7 @@ class PollContacts
 
                if (!empty($abandon_days)) {
                        $condition = DBA::mergeConditions($condition,
-                               ["`uid` != ? AND `uid` IN (SELECT `uid` FROM `user` WHERE NOT `account_expired` AND NOT `account_removed`  AND `login_date` > ?)", 0, DateTimeFormat::utc('now - ' . $abandon_days . ' days')]);
+                               ["`uid` != ? AND `uid` IN (SELECT `uid` FROM `owner-view` WHERE NOT `account_expired` AND NOT `account_removed` 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 `account_expired` AND NOT `account_removed`)", 0]);
index 2979ca80d01aa1a7c606bcf4f1545202dd26cdf0..a7bf84a466fade7a6eb314d21a6a75dc6bf7ee0c 100644 (file)
@@ -55,7 +55,7 @@
 use Friendica\Database\DBA;
 
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1496);
+       define('DB_UPDATE_VERSION', 1497);
 }
 
 return [
index a2e3e1b45f395d028e7bf860217b1bf5aac21640..09566a7fd00af406c47a74024774f3eaee9e27d9 100644 (file)
                        "language" => ["user", "language"],
                        "register_date" => ["user", "register_date"],
                        "login_date" => ["user", "login_date"],
+                       "last-activity" => "IF (`user`.`last-activity` IS NULL, DATE(`user`.`login_date`), `user`.`last-activity`)",
                        "default-location" => ["user", "default-location"],
                        "allow_location" => ["user", "allow_location"],
                        "theme" => ["user", "theme"],