Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/config/packages/valinor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
valinor:
console:
# When a mapping error occurs during a console command, the output will
# automatically be enhanced to show information about errors. The
# maximum number of errors that will be displayed can be configured
# below, or set to 0 to disable this feature entirely.
mapping_errors_to_output: 15
13 changes: 12 additions & 1 deletion sources/AppBundle/Command/ScrappingMeetupEventsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use AppBundle\Event\Model\Repository\MeetupRepository;
use AppBundle\Indexation\Meetups\MeetupClient;
use CuyZ\Valinor\Mapper\MappingError;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Command\LockableTrait;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -29,11 +30,16 @@ protected function configure(): void
->setName('scrapping-meetup-event')
->setAliases(['s-m-e'])
->setDescription('Récupère les évènements meetup AFUP sur meetup.com pour les afficher sur le site de l\'afup.')
->addOption('refresh-old-meetups', description: 'Mettre à jour les anciens meetups')
;
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
if ($input->getOption('refresh-old-meetups') === true) {
$quantityOfPastEvents = 100;
}

$io = new SymfonyStyle($input, $output);
$io->title('Import des events meetups via scrapping de meetup.com');

Expand All @@ -44,7 +50,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

try {
$meetups = $this->meetupClient->getEvents();
$meetups = $this->meetupClient->getEvents($quantityOfPastEvents ?? null);

$io->progressStart(count($meetups));
foreach ($meetups as $meetup) {
Expand Down Expand Up @@ -73,6 +79,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int

return Command::SUCCESS;
} catch (\Exception $e) {
if ($e instanceof MappingError) {
// Le bundle Valinor affiche automatiquement des détails en cas d'erreur
throw $e;
}

throw new \Exception('Problème lors du scraping ou de la sauvegarde des évènements Meetup', $e->getCode(), $e);
}
}
Expand Down
4 changes: 2 additions & 2 deletions sources/AppBundle/Indexation/Meetups/MeetupClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public function __construct(
/**
* @return Meetup[]
*/
public function getEvents(): array
public function getEvents(?int $quantityOfPastEvents = null): array
{
$response = $this->httpClient->request('POST', '/gql-ext', [
'body' => json_encode([
'query' => $this->getEventsQuery(),
'variables' => [
'quantityUpcoming' => self::QUANTITY_UPCOMING_EVENTS,
'quantityPast' => self::QUANTITY_PAST_EVENTS,
'quantityPast' => $quantityOfPastEvents ?? self::QUANTITY_PAST_EVENTS,
],
]),
]);
Expand Down
Loading