* @copyright 2018, Maxence Lange * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . * */ namespace OCA\Social\Command; use daita\MySmallPhpTools\Exceptions\CacheItemNotFoundException; use OC\Core\Command\Base; use OCA\Social\AP; use OCA\Social\Exceptions\ItemUnknownException; use OCA\Social\Exceptions\RedundancyLimitException; use OCA\Social\Exceptions\SocialAppConfigException; use OCA\Social\Model\ActivityPub\Actor\Person; use OCA\Social\Model\ActivityPub\Stream; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Output\OutputInterface; class ExtendedBase extends Base { protected ?OutputInterface $output = null; protected bool $asJson = false; protected function outputActor(Person $actor): void { if ($this->asJson) { $this->output->writeln(json_encode($actor, JSON_PRETTY_PRINT)); } $this->output->writeln('Account: ' . $actor->getAccount()); $this->output->writeln('Id: ' . $actor->getId()); $this->output->writeln(''); } /** * @param Stream[] $streams */ protected function outputStreams(array $streams) { if ($this->asJson) { $this->output->writeln(json_encode($streams, JSON_PRETTY_PRINT)); } $table = new Table($this->output); $table->setHeaders(['Id', 'Source', 'Type', 'Author', 'Content']); $table->render(); $this->output->writeln(''); foreach ($streams as $item) { $objectId = $item->getObjectId(); $cache = $item->getCache(); $content = ''; $author = ''; if ($objectId !== '' && $cache->hasItem($objectId)) { try { $cachedObject = $cache->getItem($objectId) ->getObject(); /** @var Stream $cachedItem */ $cachedItem = AP::$activityPub->getItemFromData($cachedObject); $content = $cachedItem->getContent(); $author = $cachedItem->getActor() ->getAccount(); } catch (CacheItemNotFoundException $e) { } catch (ItemUnknownException $e) { } catch (RedundancyLimitException $e) { } catch (SocialAppConfigException $e) { } } else { $content = $item->getContent(); $author = $item->getActor() ->getAccount(); } $table->appendRow( [ '' . $item->getId() . '', '' . $item->getActor() ->getAccount() . '', $item->getType(), '' . $author . '', $content, ] ); } } /** * @param Stream $stream */ protected function outputStream(Stream $stream) { $actor = $stream->getActor(); $this->output->writeln('id: ' . $stream->getId() . ''); $this->output->writeln( 'author: ' . $actor->getAccount() . '' ); $this->output->writeln('type: ' . $stream->getType() . ''); } }