Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get last meetup event command #46

Merged
merged 11 commits into from
Oct 20, 2020
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
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ REDIS_URL=redis://redis
MEETUP_KEY=
SLACK_TOKEN=
SLACK_TEAMID=
#MEETUP_EVENTS_URL='https://www.meetup.com/es/PHP-The-Right-Way/events/'
MEETUP_EVENTS_URL='tests/fixtures/meetup_response_example.html'
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ APP_SECRET='$ecretf0rt3st'
SYMFONY_DEPRECATIONS_HELPER=999999
PANTHER_APP_ENV=panther
DATABASE_URL=mysql://root:toor@db:3306/phpmx
MEETUP_EVENTS_URL='tests/fixtures/meetup_response_example.html'
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ yarn-error.log
.phpunit.result.cache
/phpunit.xml
###< symfony/phpunit-bridge ###

###> env/ide ###
.idea/
###< env/ide ###

69 changes: 35 additions & 34 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,41 @@
"type": "project",
"license": "proprietary",
"require": {
"php": "^7.1.3",
"ext-ctype": "*",
"ext-iconv": "*",
"dms/meetup-api-client": "^2.3",
"doctrine/doctrine-migrations-bundle": "^2.0",
"easycorp/easyadmin-bundle": "^2.1",
"friendsofsymfony/ckeditor-bundle": "^2.1",
"google/recaptcha": "^1.2",
"gravatarphp/gravatar": "^2.0",
"jaybizzle/crawler-detect": "^1.2",
"mattketmo/email-checker": "^1.5",
"php-http/guzzle6-adapter": "^2.0",
"php-http/httplug-bundle": "^1.16",
"predis/predis": "^1.1",
"presta/sitemap-bundle": "^1.7",
"sensio/framework-extra-bundle": "^5.3",
"snc/redis-bundle": "^2.1",
"symfony/cache": "4.4.*",
"symfony/config": "4.4.*",
"symfony/console": "4.4.*",
"symfony/dotenv": "4.4.*",
"symfony/flex": "^1.1",
"symfony/framework-bundle": "4.4.*",
"symfony/mercure-bundle": "^0.1.1",
"symfony/monolog-bundle": "^3.4",
"symfony/security-csrf": "4.2.*",
"symfony/swiftmailer-bundle": "^3.2",
"symfony/templating": "4.4.*",
"symfony/twig-bundle": "4.4.*",
"symfony/web-link": "4.4.*",
"symfony/webpack-encore-bundle": "^1.6",
"symfony/yaml": "4.4.*",
"wrapi/slack": "^1.0"
},
"php": "^7.1.3",
"ext-ctype": "*",
"ext-iconv": "*",
"dms/meetup-api-client": "^2.3",
"doctrine/doctrine-migrations-bundle": "^2.0",
"easycorp/easyadmin-bundle": "^2.1",
"friendsofsymfony/ckeditor-bundle": "^2.1",
"google/recaptcha": "^1.2",
"gravatarphp/gravatar": "^2.0",
"jaybizzle/crawler-detect": "^1.2",
"mattketmo/email-checker": "^1.5",
"php-http/guzzle6-adapter": "^2.0",
"php-http/httplug-bundle": "^1.16",
"predis/predis": "^1.1",
"presta/sitemap-bundle": "^1.7",
"sensio/framework-extra-bundle": "^5.3",
"snc/redis-bundle": "^2.1",
"symfony/cache": "4.4.*",
"symfony/config": "4.4.*",
"symfony/console": "4.4.*",
"symfony/dom-crawler": "4.4.*",
"symfony/dotenv": "4.4.*",
"symfony/flex": "^1.1",
"symfony/framework-bundle": "4.4.*",
"symfony/mercure-bundle": "^0.1.1",
"symfony/monolog-bundle": "^3.4",
"symfony/security-csrf": "4.2.*",
"symfony/swiftmailer-bundle": "^3.2",
"symfony/templating": "4.4.*",
"symfony/twig-bundle": "4.4.*",
"symfony/web-link": "4.4.*",
"symfony/webpack-encore-bundle": "^1.6",
"symfony/yaml": "4.4.*",
"wrapi/slack": "^1.0"
},
"config": {
"preferred-install": {
"*": "dist"
Expand Down
145 changes: 80 additions & 65 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ parameters:
SLACK_TOKEN: '%env(SLACK_TOKEN)%'
SLACK_TEAMID: '%env(SLACK_TEAMID)%'
google_recaptcha_site_key: '%env(GOOGLE_RECAPTCHA_SITE_KEY)%'
meetup_events_url: '%env(MEETUP_EVENTS_URL)%'

services:
# default configuration for services in *this* file
Expand Down Expand Up @@ -36,6 +37,15 @@ services:
tags:
- { name: 'console.command', command: 'phpmx:slack:sync' }

App\Service\GetLatestMeetupEventFromCrawler:
public: true
class: App\Service\GetLatestMeetupEventFromCrawler
arguments:
- '@App\Service\CrawlNode'
- '%meetup_events_url%'

App\Contracts\GetLastMeetupEventInterface: '@App\Service\GetLatestMeetupEventFromCrawler'

App\EventListener\SendLoginEmail:
tags:
- { name: doctrine.event_subscriber, event: postPersist }
Expand Down
92 changes: 92 additions & 0 deletions src/Command/PhpmxGetLastMeetupEventCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

namespace App\Command;

use App\Contracts\GetLastMeetupEventInterface;
use App\Entity\MeetupEvent;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

class PhpmxGetLastMeetupEventCommand extends Command
{
const SUCCESSFUL_EXECUTED_STATUS = 1;
javleds marked this conversation as resolved.
Show resolved Hide resolved

protected static $defaultName = 'phpmx:meetup:last-event';

/** @var GetLastMeetupEventInterface */
private $getLastMeetupEvent;

/** @var EntityManagerInterface */
private $em;

public function __construct(GetLastMeetupEventInterface $getLastMeetupEvent, EntityManagerInterface $em)
{
parent::__construct();

$this->getLastMeetupEvent = $getLastMeetupEvent;
$this->em = $em;
}

protected function configure()
{
$this->setDescription('Get the latest event from the meetup page.');
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$latestEvent = $this->getLastMeetupEvent->handle();

if (!$latestEvent) {
$io->warning('Command executed but no event was retrieved.');

return self::SUCCESSFUL_EXECUTED_STATUS;
}

/** @var MeetupEvent $cachedEvent */
$cachedEvent = $this->em->getRepository(MeetupEvent::class)
->findOneBy([
'meetupId' => $latestEvent->getMeetupId(),
]);

if ($cachedEvent) {
$cachedEvent
->setMeetupId($latestEvent->getMeetupId())
->setTitle($latestEvent->getTitle())
->setScheduledAt($latestEvent->getScheduledAt())
->setPlace($latestEvent->getPlace())
->setDescription($latestEvent->getDescription())
->setImage($latestEvent->getImage())
->setAttendingCount($latestEvent->getAttendingCount())
->setSpeaker($latestEvent->getSpeaker())
->setUrl($latestEvent->getUrl());

$this->em->persist($cachedEvent);
$this->em->flush();

$io->success(
sprintf(
'Cached event was updated successfully, details: %s',
$cachedEvent
)
);

return self::SUCCESSFUL_EXECUTED_STATUS;
}

$this->em->persist($latestEvent);
$this->em->flush();

$io->success(
sprintf(
'Event retrieved and persisted, details: %s.',
$latestEvent
)
);

return self::SUCCESSFUL_EXECUTED_STATUS;
}
}
Loading