use Friendica\Util\DateTimeFormat;
use Friendica\Util\Images;
use Friendica\Util\Network;
+use Friendica\Util\Proxy;
use Friendica\Util\Strings;
use Friendica\Worker\Delivery;
use ImagickException;
const ACCOUNT_TYPE_NEWS = 2;
const ACCOUNT_TYPE_COMMUNITY = 3;
const ACCOUNT_TYPE_RELAY = 4;
+ const ACCOUNT_TYPE_DELETED = 127;
/**
* @}
*/
$system['sprvkey'] = $system['uprvkey'] = $system['prvkey'];
$system['spubkey'] = $system['upubkey'] = $system['pubkey'];
$system['nickname'] = $system['nick'];
+
+ // Ensure that the user contains data
+ $user = DBA::selectFirst('user', ['prvkey'], ['uid' => 0]);
+ if (empty($user['prvkey'])) {
+ $fields = [
+ 'username' => $system['name'],
+ 'nickname' => $system['nick'],
+ 'register_date' => $system['created'],
+ 'pubkey' => $system['pubkey'],
+ 'prvkey' => $system['prvkey'],
+ 'spubkey' => $system['spubkey'],
+ 'sprvkey' => $system['sprvkey'],
+ 'verified' => true,
+ 'page-flags' => User::PAGE_FLAGS_SOAPBOX,
+ 'account-type' => User::ACCOUNT_TYPE_RELAY,
+ ];
+
+ DBA::update('user', $fields, ['uid' => 0]);
+ }
+
return $system;
}
$system['name'] = 'System Account';
$system['addr'] = $system_actor_name . '@' . DI::baseUrl()->getHostname();
$system['nick'] = $system_actor_name;
- $system['avatar'] = DI::baseUrl() . Contact::DEFAULT_AVATAR_PHOTO;
- $system['photo'] = DI::baseUrl() . Contact::DEFAULT_AVATAR_PHOTO;
- $system['thumb'] = DI::baseUrl() . Contact::DEFAULT_AVATAR_THUMB;
- $system['micro'] = DI::baseUrl() . Contact::DEFAULT_AVATAR_MICRO;
$system['url'] = DI::baseUrl() . '/friendica';
+
+ $system['avatar'] = $system['photo'] = Contact::getDefaultAvatar($system, Proxy::SIZE_SMALL);
+ $system['thumb'] = Contact::getDefaultAvatar($system, Proxy::SIZE_THUMB);
+ $system['micro'] = Contact::getDefaultAvatar($system, Proxy::SIZE_MICRO);
+
$system['nurl'] = Strings::normaliseLink($system['url']);
$system['pubkey'] = $keys['pubkey'];
$system['prvkey'] = $keys['prvkey'];
// List of possible actor names
$possible_accounts = ['friendica', 'actor', 'system', 'internal'];
foreach ($possible_accounts as $name) {
- if (!DBA::exists('user', ['nickname' => $name, 'account_removed' => false, 'expire']) &&
+ if (!DBA::exists('user', ['nickname' => $name, 'account_removed' => false, 'expire' => false]) &&
!DBA::exists('userd', ['username' => $name])) {
DI::config()->set('system', 'actor_name', $name);
return $name;
*/
public static function getById($uid, array $fields = [])
{
- return DBA::selectFirst('user', $fields, ['uid' => $uid]);
+ return !empty($uid) ? DBA::selectFirst('user', $fields, ['uid' => $uid]) : [];
}
/**
/**
* Get owner data by user id
*
- * @param int $uid
- * @param boolean $check_valid Test if data is invalid and correct it
+ * @param int $uid
+ * @param boolean $repairMissing Repair the owner data if it's missing
* @return boolean|array
* @throws Exception
*/
- public static function getOwnerDataById(int $uid, bool $check_valid = true)
+ public static function getOwnerDataById(int $uid, bool $repairMissing = true)
{
if ($uid == 0) {
return self::getSystemAccount();
$owner = DBA::selectFirst('owner-view', [], ['uid' => $uid]);
if (!DBA::isResult($owner)) {
- if (!DBA::exists('user', ['uid' => $uid]) || !$check_valid) {
+ if (!DBA::exists('user', ['uid' => $uid]) || !$repairMissing) {
return false;
}
Contact::createSelfFromUserId($uid);
return false;
}
- if (!$check_valid) {
+ if (!$repairMissing) {
return $owner;
}
* @return array
* @throws HTTPException\NotFoundException
*/
- private static function getAuthenticationInfo($user_info)
+ public static function getAuthenticationInfo($user_info)
{
$user = null;
return false;
}
+ // Delete the avatar
+ Photo::delete(['uid' => $register['uid']]);
+
return DBA::delete('user', ['uid' => $register['uid']]) &&
Register::deleteByHash($register['hash']);
}