mirror of
https://github.com/friendica/friendica
synced 2025-04-24 10:30:11 +00:00
Issue 6477: Automatically repair self contact avatar
This commit is contained in:
parent
b48a49b0f5
commit
4ab772ed67
6 changed files with 84 additions and 90 deletions
|
@ -16,6 +16,7 @@ use Friendica\Core\Protocol;
|
|||
use Friendica\Core\System;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Model\Photo;
|
||||
use Friendica\Object\Image;
|
||||
use Friendica\Util\Crypto;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
|
@ -149,10 +150,11 @@ class User
|
|||
* @brief Get owner data by user id
|
||||
*
|
||||
* @param int $uid
|
||||
* @param boolean $check_valid Test if data is invalid and correct it
|
||||
* @return boolean|array
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function getOwnerDataById($uid) {
|
||||
public static function getOwnerDataById($uid, $check_valid = true) {
|
||||
$r = DBA::fetchFirst("SELECT
|
||||
`contact`.*,
|
||||
`user`.`prvkey` AS `uprvkey`,
|
||||
|
@ -180,12 +182,34 @@ class User
|
|||
return false;
|
||||
}
|
||||
|
||||
// Check if the returned data is valid, otherwise fix it. See issue #6122
|
||||
$url = System::baseUrl() . '/profile/' . $r['nickname'];
|
||||
$addr = $r['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3);
|
||||
if (!$check_valid) {
|
||||
return $r;
|
||||
}
|
||||
|
||||
if (($addr != $r['addr']) || ($r['url'] != $url) || ($r['nurl'] != Strings::normaliseLink($r['url']))) {
|
||||
// Check if the returned data is valid, otherwise fix it. See issue #6122
|
||||
|
||||
// Check for correct url and normalised nurl
|
||||
$url = System::baseUrl() . '/profile/' . $r['nickname'];
|
||||
$repair = ($r['url'] != $url) || ($r['nurl'] != Strings::normaliseLink($r['url']));
|
||||
|
||||
if (!$repair) {
|
||||
// Check if "addr" is present and correct
|
||||
$addr = $r['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3);
|
||||
$repair = ($addr != $r['addr']);
|
||||
}
|
||||
|
||||
if (!$repair) {
|
||||
// Check if the avatar field is filled and the photo directs to the correct path
|
||||
$avatar = Photo::selectFirst(['resource-id'], ['uid' => $uid, 'profile' => true]);
|
||||
if (DBA::isResult($avatar)) {
|
||||
$repair = empty($r['avatar']) || !strpos($r['photo'], $avatar['resource-id']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($repair) {
|
||||
Contact::updateSelfFromUserID($uid);
|
||||
// Return the corrected data and avoid a loop
|
||||
$r = self::getOwnerDataById($uid, false);
|
||||
}
|
||||
|
||||
return $r;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue