diff --git a/src/Command/GetArticlesCommand.php b/src/Command/GetArticlesCommand.php index 908832f..23af7ae 100644 --- a/src/Command/GetArticlesCommand.php +++ b/src/Command/GetArticlesCommand.php @@ -5,6 +5,7 @@ namespace App\Command; use App\Service\NostrClient; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -19,10 +20,18 @@ class GetArticlesCommand extends Command parent::__construct(); } - protected function execute(InputInterface $input, OutputInterface $output): int + protected function configure(): void { + $this + ->addArgument('from', InputArgument::REQUIRED, 'From') + ->addArgument('to', InputArgument::REQUIRED, 'To'); + } - $this->nostrClient->getLongFormContent(); + protected function execute(InputInterface $input, OutputInterface $output): int + { + $from = strtotime($input->getArgument('from')); + $to = strtotime($input->getArgument('to')); + $this->nostrClient->getLongFormContent($from, $to); return Command::SUCCESS; } diff --git a/src/Command/NostrEventFromYamlDefinitionCommand.php b/src/Command/NostrEventFromYamlDefinitionCommand.php index e2160ec..b8b0734 100644 --- a/src/Command/NostrEventFromYamlDefinitionCommand.php +++ b/src/Command/NostrEventFromYamlDefinitionCommand.php @@ -5,6 +5,9 @@ declare(strict_types=1); namespace App\Command; use App\Entity\Article; +use App\Enum\IndexStatusEnum; +use App\Factory\ArticleFactory; +use App\Service\NostrClient; use Doctrine\ORM\EntityManagerInterface; use FOS\ElasticaBundle\Persister\ObjectPersisterInterface; use swentel\nostr\Event\Event; @@ -24,7 +27,10 @@ class NostrEventFromYamlDefinitionCommand extends Command { private string $nsec; - public function __construct(private readonly CacheInterface $redisCache, ParameterBagInterface $bag, + public function __construct(private readonly CacheInterface $redisCache, + private readonly NostrClient $client, + private readonly ArticleFactory $factory, + ParameterBagInterface $bag, private readonly ObjectPersisterInterface $itemPersister, private readonly EntityManagerInterface $entityManager) { @@ -95,6 +101,14 @@ class NostrEventFromYamlDefinitionCommand extends Command } } + // crawl relays for all the articles and save to db + $fresh = $this->client->getArticles($articleSlugsList); + foreach ($fresh as $item) { + $article = $this->factory->createFromLongFormContentEvent($item); + $this->entityManager->persist($article); + } + $this->entityManager->flush(); + // look up all articles in the db and push to index whatever you find $articles = $this->entityManager->getRepository(Article::class)->createQueryBuilder('a') ->where('a.slug IN (:slugs)') @@ -102,6 +116,15 @@ class NostrEventFromYamlDefinitionCommand extends Command ->getQuery() ->getResult(); + // mark all of those for indexing + foreach ($articles as $article) { + if ($article->getIndexStatus() === IndexStatusEnum::NOT_INDEXED) { + $article->setIndexStatus(IndexStatusEnum::TO_BE_INDEXED); + $this->entityManager->persist($article); + } + } + $this->entityManager->flush(); + // to elastic if (count($articles) > 0 ) { $this->itemPersister->insertMany($articles); // Insert or skip existing