use Friendica\Model\Notification;
use Friendica\Model\Photo;
use Friendica\Model\Post;
+use Friendica\Model\Profile;
use Friendica\Model\User;
use Friendica\Model\Verb;
use Friendica\Network\HTTPException;
Contact::updateSelfFromUserID(api_user(), true);
// Update global directory in background
- $url = DI::baseUrl() . '/profile/' . DI::app()->user['nickname'];
- if ($url && strlen(DI::config()->get('system', 'directory'))) {
- Worker::add(PRIORITY_LOW, "Directory", $url);
- }
-
- Worker::add(PRIORITY_LOW, 'ProfileUpdate', api_user());
+ Profile::publishUpdate(api_user());
// output for client
if ($data) {
DBA::update('contact', ['about' => $_POST['description']], ['id' => $api_user['id']]);
}
- Worker::add(PRIORITY_LOW, 'ProfileUpdate', $local_user);
- // Update global directory in background
- if ($api_user['url'] && strlen(DI::config()->get('system', 'directory'))) {
- Worker::add(PRIORITY_LOW, "Directory", $api_user['url']);
- }
+ Profile::publishUpdate($local_user);
return api_account_verify_credentials($type);
}
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\DI;
-use Friendica\Model\Contact;
use Friendica\Model\Group;
use Friendica\Model\Notification;
+use Friendica\Model\Profile;
use Friendica\Model\User;
use Friendica\Module\BaseSettings;
use Friendica\Module\Security\Login;
$fields['openidserver'] = '';
}
- if (!DBA::update('user', $fields, ['uid' => local_user()])) {
+ $profile_fields = ['publish' => $publish, 'net-publish' => $net_publish, 'hide-friends' => $hide_friends];
+
+ if (!User::update($fields, local_user()) || !Profile::update($profile_fields, local_user())) {
notice(DI::l10n()->t('Settings were not updated.'));
}
// clear session language
unset($_SESSION['language']);
- q("UPDATE `profile`
- SET `publish` = %d,
- `name` = '%s',
- `net-publish` = %d,
- `hide-friends` = %d
- WHERE `uid` = %d",
- intval($publish),
- DBA::escape($username),
- intval($net_publish),
- intval($hide_friends),
- intval(local_user())
- );
-
- Contact::updateSelfFromUserID(local_user());
-
- if (($old_visibility != $net_publish) || ($page_flags != $old_page_flags)) {
- // Update global directory in background
- $url = $_SESSION['my_url'];
- if ($url && strlen(DI::config()->get('system', 'directory'))) {
- Worker::add(PRIORITY_LOW, "Directory", $url);
- }
- }
-
- Worker::add(PRIORITY_LOW, 'ProfileUpdate', local_user());
-
DI::baseUrl()->redirect('settings');
return; // NOTREACHED
}
*
* @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)
'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';
'thumb' => DI::baseUrl() . '/photo/avatar/' . $uid .'.' . $file_suffix];
DBA::update('profile', $fields, ['uid' => $uid]);
}
+ return $update;
}
/**
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;
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);
+ }
+
+ return true;
+ }
+
+ /**
+ * Publish a changed profile
+ * @param int $uid
+ */
+ public static function publishUpdate(int $uid)
+ {
+ $owner = User::getOwnerDataById($uid);
+ if (empty($owner)) {
+ return;
+ }
+ if ($owner['net-publish']) {
+ // 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
*
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
*
return;
}
- $namechanged = $profile['name'] != $name;
-
$about = Strings::escapeTags(trim($_POST['about']));
$address = Strings::escapeTags(trim($_POST['address']));
$locality = Strings::escapeTags(trim($_POST['locality']));
DI::profileField()->saveCollection($profileFields);
- $result = DBA::update(
- 'profile',
+ $result = Profile::update(
[
'name' => $name,
'about' => $about,
'pub_keywords' => $pub_keywords,
'prv_keywords' => $prv_keywords,
],
- ['uid' => local_user()]
+ local_user()
);
if (!$result) {
notice(DI::l10n()->t('Profile couldn\'t be updated.'));
return;
}
-
- if ($namechanged) {
- DBA::update('user', ['username' => $name], ['uid' => local_user()]);
- }
-
- Contact::updateSelfFromUserID(local_user());
-
- // Update global directory in background
- if (Session::get('my_url') && strlen(DI::config()->get('system', 'directory'))) {
- Worker::add(PRIORITY_LOW, 'Directory', Session::get('my_url'));
- }
-
- Worker::add(PRIORITY_LOW, 'ProfileUpdate', local_user());
}
public static function content(array $parameters = [])
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Photo;
+use Friendica\Model\Profile;
use Friendica\Module\BaseSettings;
use Friendica\Network\HTTPException;
Contact::updateSelfFromUserID(local_user(), true);
info(DI::l10n()->t('Shift-reload the page or clear browser cache if the new photo does not display immediately.'));
- // Update global directory in background
- if ($path && strlen(DI::config()->get('system', 'directory'))) {
- Worker::add(PRIORITY_LOW, 'Directory', DI::baseUrl()->get() . '/' . $path);
- }
- Worker::add(PRIORITY_LOW, 'ProfileUpdate', local_user());
+ // Update global directory in background
+ Profile::publishUpdate(local_user());
} else {
notice(DI::l10n()->t('Unable to process image'));
}
Contact::updateSelfFromUserID(local_user(), true);
// Update global directory in background
- if (Session::get('my_url') && strlen(DI::config()->get('system', 'directory'))) {
- Worker::add(PRIORITY_LOW, 'Directory', Session::get('my_url'));
- }
+ Profile::publishUpdate(local_user());
info(DI::l10n()->t('Profile picture successfully updated.'));
use Friendica\Model\Notification;
use Friendica\Model\Photo;
use Friendica\Model\Post;
+use Friendica\Model\Profile;
use Friendica\Model\Storage;
use Friendica\Worker\Delivery;
DBA::update('profile', [$translateKey => $key], ['id' => $data['id']]);
Logger::notice('Updated contact', ['action' => 'update', 'contact' => $data['id'], "$translateKey" => $key,
'was' => $data[$translateKey]]);
- Worker::add(PRIORITY_LOW, 'ProfileUpdate', $data['id']);
+
Contact::updateSelfFromUserID($data['id']);
+ Profile::publishUpdate($data['id']);
$success++;
}
}
{
$users = DBA::select('user', ['uid']);
while ($user = DBA::fetch($users)) {
- Contact::updateSelfFromUserID($user['uid']);
+ if (Contact::updateSelfFromUserID($user['uid'])) {
+ Profile::publishUpdate($user['uid']);
+ }
}
DBA::close($users);