Merge pull request #13588 from annando/issue-13511
Issue 13511: Ensure static community user settings
This commit is contained in:
commit
104ce7c64f
5 changed files with 47 additions and 27 deletions
|
@ -1,6 +1,6 @@
|
||||||
-- ------------------------------------------
|
-- ------------------------------------------
|
||||||
-- Friendica 2023.09-rc (Giant Rhubarb)
|
-- Friendica 2023.09-rc (Giant Rhubarb)
|
||||||
-- DB_UPDATE_VERSION 1538
|
-- DB_UPDATE_VERSION 1539
|
||||||
-- ------------------------------------------
|
-- ------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -343,6 +343,35 @@ class User
|
||||||
return DBA::selectFirst('user', $fields, ['nickname' => $nickname]);
|
return DBA::selectFirst('user', $fields, ['nickname' => $nickname]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set static settings for community user accounts
|
||||||
|
*
|
||||||
|
* @param integer $uid
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function setCommunityUserSettings(int $uid)
|
||||||
|
{
|
||||||
|
$user = self::getById($uid, ['account-type', 'page-flags']);
|
||||||
|
if ($user['account-type'] != User::ACCOUNT_TYPE_COMMUNITY) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DI::pConfig()->set($uid, 'system', 'unlisted', true);
|
||||||
|
|
||||||
|
$fields = [
|
||||||
|
'allow_cid' => '',
|
||||||
|
'allow_gid' => $user['page-flags'] == User::PAGE_FLAGS_PRVGROUP ? '<' . Circle::FOLLOWERS . '>' : '',
|
||||||
|
'deny_cid' => '',
|
||||||
|
'deny_gid' => '',
|
||||||
|
'blockwall' => true,
|
||||||
|
'hidewall' => true,
|
||||||
|
];
|
||||||
|
|
||||||
|
User::update($fields, $uid);
|
||||||
|
|
||||||
|
Profile::update(['hide-friends' => true], $uid);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the user id of a given profile URL
|
* Returns the user id of a given profile URL
|
||||||
*
|
*
|
||||||
|
|
|
@ -199,6 +199,7 @@ class Account extends BaseSettings
|
||||||
DI::sysmsg()->addNotice(DI::l10n()->t('Settings were not updated.'));
|
DI::sysmsg()->addNotice(DI::l10n()->t('Settings were not updated.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
User::setCommunityUserSettings(DI::userSession()->getLocalUserId());
|
||||||
DI::baseUrl()->redirect($redirectUrl);
|
DI::baseUrl()->redirect($redirectUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,37 +322,16 @@ class Account extends BaseSettings
|
||||||
$page_flags = User::PAGE_FLAGS_COMMUNITY;
|
$page_flags = User::PAGE_FLAGS_COMMUNITY;
|
||||||
}
|
}
|
||||||
|
|
||||||
$fields = [];
|
$fields = [
|
||||||
$profile_fields = [];
|
|
||||||
|
|
||||||
if ($account_type == User::ACCOUNT_TYPE_COMMUNITY) {
|
|
||||||
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'system', 'unlisted', true);
|
|
||||||
|
|
||||||
$fields = [
|
|
||||||
'allow_cid' => '',
|
|
||||||
'allow_gid' => $page_flags == User::PAGE_FLAGS_PRVGROUP ?
|
|
||||||
'<' . Circle::FOLLOWERS . '>'
|
|
||||||
: '',
|
|
||||||
'deny_cid' => '',
|
|
||||||
'deny_gid' => '',
|
|
||||||
'blockwall' => true,
|
|
||||||
'blocktags' => true,
|
|
||||||
];
|
|
||||||
|
|
||||||
$profile_fields = [
|
|
||||||
'hide-friends' => true,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
$fields = array_merge($fields, [
|
|
||||||
'page-flags' => $page_flags,
|
'page-flags' => $page_flags,
|
||||||
'account-type' => $account_type,
|
'account-type' => $account_type,
|
||||||
]);
|
];
|
||||||
|
|
||||||
if (!User::update($fields, DI::userSession()->getLocalUserId()) || !empty($profile_fields) && !Profile::update($profile_fields, DI::userSession()->getLocalUserId())) {
|
if (!User::update($fields, DI::userSession()->getLocalUserId())) {
|
||||||
DI::sysmsg()->addNotice(DI::l10n()->t('Settings were not updated.'));
|
DI::sysmsg()->addNotice(DI::l10n()->t('Settings were not updated.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
User::setCommunityUserSettings(DI::userSession()->getLocalUserId());
|
||||||
DI::baseUrl()->redirect($redirectUrl);
|
DI::baseUrl()->redirect($redirectUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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', 1538);
|
define('DB_UPDATE_VERSION', 1539);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
11
update.php
11
update.php
|
@ -1398,5 +1398,16 @@ function update_1535()
|
||||||
}
|
}
|
||||||
DI::config()->delete('system', 'compute_group_counts');
|
DI::config()->delete('system', 'compute_group_counts');
|
||||||
|
|
||||||
|
return Update::SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
function update_1539()
|
||||||
|
{
|
||||||
|
$users = DBA::select('user', ['uid'], ['account-type' => User::ACCOUNT_TYPE_COMMUNITY]);
|
||||||
|
while ($user = DBA::fetch($users)) {
|
||||||
|
User::setCommunityUserSettings($user['uid']);
|
||||||
|
}
|
||||||
|
DBA::close($users);
|
||||||
|
|
||||||
return Update::SUCCESS;
|
return Update::SUCCESS;
|
||||||
}
|
}
|
Loading…
Reference in a new issue