Browse Source

Update commands

imwald
Nuša Pukšič 8 months ago
parent
commit
dfed4b8f9c
  1. 13
      src/Command/GetArticlesCommand.php
  2. 25
      src/Command/NostrEventFromYamlDefinitionCommand.php

13
src/Command/GetArticlesCommand.php

@ -5,6 +5,7 @@ namespace App\Command;
use App\Service\NostrClient; use App\Service\NostrClient;
use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
@ -19,10 +20,18 @@ class GetArticlesCommand extends Command
parent::__construct(); 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; return Command::SUCCESS;
} }

25
src/Command/NostrEventFromYamlDefinitionCommand.php

@ -5,6 +5,9 @@ declare(strict_types=1);
namespace App\Command; namespace App\Command;
use App\Entity\Article; use App\Entity\Article;
use App\Enum\IndexStatusEnum;
use App\Factory\ArticleFactory;
use App\Service\NostrClient;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use FOS\ElasticaBundle\Persister\ObjectPersisterInterface; use FOS\ElasticaBundle\Persister\ObjectPersisterInterface;
use swentel\nostr\Event\Event; use swentel\nostr\Event\Event;
@ -24,7 +27,10 @@ class NostrEventFromYamlDefinitionCommand extends Command
{ {
private string $nsec; 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 ObjectPersisterInterface $itemPersister,
private readonly EntityManagerInterface $entityManager) 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 // look up all articles in the db and push to index whatever you find
$articles = $this->entityManager->getRepository(Article::class)->createQueryBuilder('a') $articles = $this->entityManager->getRepository(Article::class)->createQueryBuilder('a')
->where('a.slug IN (:slugs)') ->where('a.slug IN (:slugs)')
@ -102,6 +116,15 @@ class NostrEventFromYamlDefinitionCommand extends Command
->getQuery() ->getQuery()
->getResult(); ->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 // to elastic
if (count($articles) > 0 ) { if (count($articles) > 0 ) {
$this->itemPersister->insertMany($articles); // Insert or skip existing $this->itemPersister->insertMany($articles); // Insert or skip existing

Loading…
Cancel
Save