. * */ namespace Friendica\Console; use Friendica\App\BaseURL; use Friendica\Contact\Avatar; use Friendica\Core\L10n; use Friendica\Model\Contact; use Friendica\Model\Photo; use Friendica\Util\Images; use Friendica\Object\Image; /** * tool to control the list of ActivityPub relay servers from the CLI * * With this script you can access the relay servers of your node from * the CLI. */ class MoveToAvatarCache extends \Asika\SimpleConsole\Console { protected $helpOptions = ['h', 'help', '?']; /** * @var $dba Friendica\Database\Database */ private $dba; /** * @var $baseurl Friendica\App\BaseURL */ private $baseurl; /** * @var L10n */ private $l10n; protected function getHelp() { $help = <<dba = $dba; $this->baseurl = $baseurl; $this->l10n = $l10n; } protected function doExecute() { $condition = ["`avatar` != ? AND `photo` LIKE ? AND `uid` = ? AND `uri-id` != ? AND NOT `uri-id` IS NULL", '', $this->baseurl->get() . '/photo/%', 0, 0]; $count = 0; $total = $this->dba->count('contact', $condition); $contacts = $this->dba->select('contact', ['id', 'avatar', 'photo', 'uri-id', 'url', 'avatar'], $condition, ['order' => ['id' => true]]); while ($contact = $this->dba->fetch($contacts)) { echo ++$count . '/' . $total . "\t" . $contact['id'] . "\t" . $contact['url'] . "\t"; $resourceid = Photo::ridFromURI($contact['photo']); if (empty($resourceid)) { echo $this->l10n->t('no resource') . "\n"; continue; } echo '1'; $photo = Photo::selectFirst([], ['resource-id' => $resourceid], ['order' => ['scale']]); if (empty($photo)) { echo $this->l10n->t('no photo') . "\n"; continue; } echo '2'; $imgdata = Photo::getImageDataForPhoto($photo); if (empty($imgdata)) { echo $this->l10n->t('no image data') . "\n"; continue; } echo '3'; $image = new Image($imgdata, Images::getMimeTypeByData($imgdata)); if (!$image->isValid()) { echo $this->l10n->t('invalid image') . "\n"; continue; } echo '4'; $fields = Avatar::storeAvatarByImage($contact, $image); echo '5'; Contact::update($fields, ['uri-id' => $contact['uri-id']]); echo '6'; Photo::delete(['resource-id' => $resourceid]); echo ' '.$fields['photo'] . "\n"; } return 0; } }