Merge pull request #14189 from annando/blocked-users

Blocked users need to be blocked
This commit is contained in:
Hypolite Petovan 2024-05-29 10:32:06 -04:00 committed by GitHub
commit 83b286fafb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 21 additions and 7 deletions

View file

@ -1,6 +1,6 @@
-- ------------------------------------------ -- ------------------------------------------
-- Friendica 2024.06-dev (Yellow Archangel) -- Friendica 2024.06-dev (Yellow Archangel)
-- DB_UPDATE_VERSION 1563 -- DB_UPDATE_VERSION 1564
-- ------------------------------------------ -- ------------------------------------------

View file

@ -626,11 +626,8 @@ class Contact
*/ */
public static function getPublicIdByUserId(int $uid) public static function getPublicIdByUserId(int $uid)
{ {
$self = DBA::selectFirst('contact', ['url'], ['self' => true, 'uid' => $uid]); $self = self::selectFirstAccountUser(['pid'], ['self' => true, 'uid' => $uid]);
if (!DBA::isResult($self)) { return $self['pid'] ?? false;
return false;
}
return self::getIdForURL($self['url']);
} }
/** /**

View file

@ -1492,6 +1492,12 @@ class User
*/ */
public static function block(int $uid, bool $block = true): bool public static function block(int $uid, bool $block = true): bool
{ {
$self = Contact::getPublicIdByUserId($uid);
if ($block) {
Contact::block($self['id']);
} else {
Contact::unblock($self['id']);
}
return DBA::update('user', ['blocked' => $block], ['uid' => $uid]); return DBA::update('user', ['blocked' => $block], ['uid' => $uid]);
} }

View file

@ -56,7 +56,7 @@ use Friendica\Database\DBA;
// This file is required several times during the test in DbaDefinition which justifies this condition // This file is required several times during the test in DbaDefinition which justifies this condition
if (!defined('DB_UPDATE_VERSION')) { if (!defined('DB_UPDATE_VERSION')) {
define('DB_UPDATE_VERSION', 1563); define('DB_UPDATE_VERSION', 1564);
} }
return [ return [

View file

@ -1467,3 +1467,14 @@ function update_1560()
return Update::FAILED; return Update::FAILED;
} }
} }
function update_1564()
{
$users = DBA::select('user', ['uid'], ['blocked' => true]);
while ($user = DBA::fetch($users)) {
User::block($user['uid']);
}
DBA::close($users);
return Update::SUCCESS;
}