Centzralized functionality to update and publish profile changes

This commit is contained in:
Michael 2021-06-15 11:12:44 +00:00
parent c9ec2e21b3
commit 0ab24510ef
8 changed files with 125 additions and 69 deletions

View file

@ -1133,6 +1133,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
*