nsec = $bag->get('nsec'); parent::__construct(); } protected function configure(): void { $this ->addArgument('folder', InputArgument::REQUIRED, 'The folder location to start scanning from.'); } protected function execute(InputInterface $input, OutputInterface $output): int { $folder = $input->getArgument('folder'); // Use Symfony Finder to locate YAML files recursively $finder = new Finder(); $finder->files() ->in($folder) ->name('*.yaml') ->name('*.yml'); if (!$finder->hasResults()) { $output->writeln('No YAML files found in the specified directory.'); return Command::SUCCESS; } $articleSlugsList = []; foreach ($finder as $file) { $filePath = $file->getRealPath(); $output->writeln("Processing file: $filePath"); $yamlContent = Yaml::parseFile($filePath); // This parses the YAML file try { // Deserialize YAML content into an Event object $event = new Event(); $event->setKind(30040); $tags = $yamlContent['tags']; $event->setTags($tags); $items = array_filter($tags, function ($tag) { return ($tag[0] === 'a'); }); foreach ($items as $one) { $parts = explode(':', $one[1]); $articleSlugsList[] = end($parts); } $signer = new Sign(); $signer->signEvent($event, $this->nsec); // Save to cache $slug = array_filter($tags, function ($tag) { return ($tag[0] === 'd'); }); // Generate a Redis key $cacheKey = 'magazine-' . $slug[0][1]; $cacheItem = $this->redisCache->getItem($cacheKey); $cacheItem->set($event); $this->redisCache->save($cacheItem); $output->writeln("Saved index."); } catch (\Exception $e) { $output->writeln("Error deserializing YAML in file: $filePath. Message: {$e->getMessage()}"); continue; } } // crawl relays for all the articles and save to db $fresh = $this->client->getArticles($articleSlugsList); $articles = []; foreach ($fresh as $item) { $article = $this->factory->createFromLongFormContentEvent($item); $this->entityManager->persist($article); $articles[] = $article; } $this->entityManager->flush(); $output->writeln('Articles saved to database.'); $output->writeln('Conversion complete.'); return Command::SUCCESS; } }