mirror of
https://github.com/friendica/friendica
synced 2025-04-22 23:50:13 +00:00
Merge remote-tracking branch 'upstream/2021.06-rc' into public-timeline
This commit is contained in:
commit
ebd4f59d02
34 changed files with 273 additions and 103 deletions
|
@ -623,6 +623,7 @@ class Contact
|
|||
*
|
||||
* @param int $uid
|
||||
* @param boolean $update_avatar Force the avatar update
|
||||
* @return bool "true" if updated
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function updateSelfFromUserID($uid, $update_avatar = false)
|
||||
|
@ -632,20 +633,20 @@ class Contact
|
|||
'photo', 'thumb', 'micro', 'addr', 'request', 'notify', 'poll', 'confirm', 'poco'];
|
||||
$self = DBA::selectFirst('contact', $fields, ['uid' => $uid, 'self' => true]);
|
||||
if (!DBA::isResult($self)) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
$fields = ['nickname', 'page-flags', 'account-type', 'prvkey', 'pubkey'];
|
||||
$user = DBA::selectFirst('user', $fields, ['uid' => $uid, 'account_expired' => false]);
|
||||
if (!DBA::isResult($user)) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
$fields = ['name', 'photo', 'thumb', 'about', 'address', 'locality', 'region',
|
||||
'country-name', 'pub_keywords', 'xmpp', 'net-publish'];
|
||||
$profile = DBA::selectFirst('profile', $fields, ['uid' => $uid]);
|
||||
if (!DBA::isResult($profile)) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
$file_suffix = 'jpg';
|
||||
|
@ -724,6 +725,8 @@ class Contact
|
|||
'thumb' => DI::baseUrl() . '/photo/avatar/' . $uid .'.' . $file_suffix];
|
||||
DBA::update('profile', $fields, ['uid' => $uid]);
|
||||
}
|
||||
|
||||
return $update;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -29,8 +29,10 @@ use Friendica\Core\Hook;
|
|||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\Search;
|
||||
use Friendica\Core\Session;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Protocol\Activity;
|
||||
|
@ -84,6 +86,71 @@ class Profile
|
|||
return DBA::selectToArray('profile', $fields, ['uid' => $uid]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a profile entry and distribute the changes if needed
|
||||
*
|
||||
* @param array $fields
|
||||
* @param integer $uid
|
||||
* @return boolean
|
||||
*/
|
||||
public static function update(array $fields, int $uid): bool
|
||||
{
|
||||
$old_owner = User::getOwnerDataById($uid);
|
||||
if (empty($old_owner)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!DBA::update('profile', $fields, ['uid' => $uid])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$update = Contact::updateSelfFromUserID($uid);
|
||||
|
||||
$owner = User::getOwnerDataById($uid);
|
||||
if (empty($owner)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($old_owner['name'] != $owner['name']) {
|
||||
User::update(['username' => $owner['name']], $uid);
|
||||
}
|
||||
|
||||
$profile_fields = ['postal-code', 'dob', 'prv_keywords', 'homepage'];
|
||||
foreach ($profile_fields as $field) {
|
||||
if ($old_owner[$field] != $owner[$field]) {
|
||||
$update = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($update) {
|
||||
self::publishUpdate($uid, ($old_owner['net-publish'] != $owner['net-publish']));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish a changed profile
|
||||
* @param int $uid
|
||||
* @param bool $force Force publishing to the directory
|
||||
*/
|
||||
public static function publishUpdate(int $uid, bool $force = false)
|
||||
{
|
||||
$owner = User::getOwnerDataById($uid);
|
||||
if (empty($owner)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($owner['net-publish'] || $force) {
|
||||
// Update global directory in background
|
||||
if (Search::getGlobalDirectory()) {
|
||||
Worker::add(PRIORITY_LOW, 'Directory', $owner['url']);
|
||||
}
|
||||
}
|
||||
|
||||
Worker::add(PRIORITY_LOW, 'ProfileUpdate', $uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a formatted location string from the given profile array
|
||||
*
|
||||
|
|
|
@ -1138,6 +1138,42 @@ class User
|
|||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a user entry and distribute the changes if needed
|
||||
*
|
||||
* @param array $fields
|
||||
* @param integer $uid
|
||||
* @return boolean
|
||||
*/
|
||||
public static function update(array $fields, int $uid): bool
|
||||
{
|
||||
$old_owner = self::getOwnerDataById($uid);
|
||||
if (empty($old_owner)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!DBA::update('user', $fields, ['uid' => $uid])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$update = Contact::updateSelfFromUserID($uid);
|
||||
|
||||
$owner = self::getOwnerDataById($uid);
|
||||
if (empty($owner)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($old_owner['name'] != $owner['name']) {
|
||||
Profile::update(['name' => $owner['name']], $uid);
|
||||
}
|
||||
|
||||
if ($update) {
|
||||
Profile::publishUpdate($uid);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets block state for a given user
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue