-- ------------------------------------------
-- Friendica 2022.05-dev (Siberian Iris)
--- DB_UPDATE_VERSION 1450
+-- DB_UPDATE_VERSION 1451
-- ------------------------------------------
'$network_link' => $network_link,
'$network_avatar' => $network_avatar,
'$network' => DI::l10n()->t('Network:'),
- '$account_type' => Contact::getAccountType($contact),
+ '$account_type' => Contact::getAccountType($contact['contact-type']),
'$follow' => DI::l10n()->t('Follow'),
'$follow_link' => $follow_link,
'$unfollow' => DI::l10n()->t('Unfollow'),
*
* The function can be called with either the user or the contact array
*
- * @param array $contact contact or user array
+ * @param int $type type of contact or account
* @return string
*/
- public static function getAccountType(array $contact)
- {
- // There are several fields that indicate that the contact or user is a forum
- // "page-flags" is a field in the user table,
- // "forum" and "prv" are used in the contact table. They stand for User::PAGE_FLAGS_COMMUNITY and User::PAGE_FLAGS_PRVGROUP.
- if ((isset($contact['page-flags']) && (intval($contact['page-flags']) == User::PAGE_FLAGS_COMMUNITY))
- || (isset($contact['page-flags']) && (intval($contact['page-flags']) == User::PAGE_FLAGS_PRVGROUP))
- || (isset($contact['forum']) && intval($contact['forum']))
- || (isset($contact['prv']) && intval($contact['prv']))
- || (isset($contact['community']) && intval($contact['community']))
- ) {
- $type = self::TYPE_COMMUNITY;
- } else {
- $type = self::TYPE_PERSON;
- }
-
- // The "contact-type" (contact table) and "account-type" (user table) are more general then the chaos from above.
- if (isset($contact["contact-type"])) {
- $type = $contact["contact-type"];
- }
-
- if (isset($contact["account-type"])) {
- $type = $contact["account-type"];
- }
-
+ public static function getAccountType(int $type)
+ {
switch ($type) {
case self::TYPE_ORGANISATION:
$account_type = DI::l10n()->t("Organisation");
*/
public static function isForum($contactid)
{
- $fields = ['contact-type', 'forum', 'prv'];
+ $fields = ['contact-type'];
$condition = ['id' => $contactid];
$contact = DBA::selectFirst('contact', $fields, $condition);
if (!DBA::isResult($contact)) {
}
// Is it a forum?
- return (($contact['contact-type'] == self::TYPE_COMMUNITY) || $contact['forum'] || $contact['prv']);
+ return ($contact['contact-type'] == self::TYPE_COMMUNITY);
}
/**
}
// Fetch the account type
- $account_type = Contact::getAccountType($profile);
+ $account_type = Contact::getAccountType($profile['account-type']);
if (!empty($profile['address']) || !empty($profile['location'])) {
$location = DI::l10n()->t('Location:');
'details' => $contact['location'],
'tags' => $contact['keywords'],
'about' => $contact['about'],
- 'account_type' => Model\Contact::getAccountType($contact),
+ 'account_type' => Model\Contact::getAccountType($contact['contact-type']),
'sparkle' => $sparkle,
'itemurl' => ($contact['addr'] ?? '') ?: $contact['url'],
'network' => ContactSelector::networkToName($contact['network'], $contact['url'], $contact['protocol'], $contact['gsid']),
'network_link' => Strings::formatNetworkName($contact['network'], $contact['url']),
'tags' => $contact['keywords'],
'bd' => $contact['bd'] <= DBA::NULL_DATE ? '' : $contact['bd'],
- 'account_type' => Contact::getAccountType($contact),
+ 'account_type' => Contact::getAccountType($contact['contact-type']),
'actions' => $actions,
],
]);
'$url' => $url,
'$profileurllabel' => $this->t('Profile URL'),
'$profileurl' => $contact['url'],
- '$account_type' => Contact::getAccountType($contact),
+ '$account_type' => Contact::getAccountType($contact['contact-type']),
'$location' => BBCode::convertForUriId($contact['uri-id'] ?? 0, $contact['location']),
'$location_label' => $this->t('Location:'),
'$xmpp' => BBCode::convertForUriId($contact['uri-id'] ?? 0, $contact['xmpp']),
if (self::$forumContactId) {
// If self::$forumContactId belongs to a communitity forum or a privat goup,.add a mention to the status editor
- $condition = ["`id` = ? AND (`forum` OR `prv`)", self::$forumContactId];
+ $condition = ["`id` = ? AND `contact-type` = ?", self::$forumContactId, Contact::TYPE_COMMUNITY];
$contact = DBA::selectFirst('contact', ['addr'], $condition);
if (!empty($contact['addr'])) {
$content = '!' . $contact['addr'];
'img_hover' => $contact['name'],
'name' => $contact['name'],
'details' => $details,
- 'account_type' => Model\Contact::getAccountType($contact),
+ 'account_type' => Model\Contact::getAccountType($contact['contact-type']),
'profile' => $profile,
'location' => $location_e,
'tags' => $contact['pub_keywords'],
foreach ($mentioned as $mention) {
$condition = ['uid' => $owner["uid"], 'nurl' => Strings::normaliseLink($mention)];
- $contact = DBA::selectFirst('contact', ['forum', 'prv'], $condition);
+ $contact = DBA::selectFirst('contact', ['contact-type'], $condition);
- if (DBA::isResult($contact) && ($contact["forum"] || $contact["prv"])) {
+ if (DBA::isResult($contact) && ($contact['contact-type'] == Contact::TYPE_COMMUNITY)) {
XML::addElement(
$doc,
$entry,
use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) {
- define('DB_UPDATE_VERSION', 1450);
+ define('DB_UPDATE_VERSION', 1451);
}
return [
use Friendica\Model\Photo;
use Friendica\Model\Post;
use Friendica\Model\Profile;
+use Friendica\Model\User;
use Friendica\Security\PermissionSet\Repository\PermissionSet;
use Friendica\Worker\Delivery;
return Update::SUCCESS;
}
+
+function update_1451()
+{
+ DBA::update('user', ['account-type' => User::ACCOUNT_TYPE_COMMUNITY], ['page-flags' => [User::PAGE_FLAGS_COMMUNITY, User::PAGE_FLAGS_PRVGROUP]]);
+ DBA::update('contact', ['contact-type' => Contact::TYPE_COMMUNITY], ["`forum` OR `prv`"]);
+
+ return Update::SUCCESS;
+}