Fetch untweeted tweets, store retweet time
This commit is contained in:
parent
2c5e1cf756
commit
5624f86e38
|
@ -6,6 +6,7 @@ use App\Entity\Tweet;
|
|||
use App\Repository\TweetRepository;
|
||||
use App\Service\Retweeter;
|
||||
use App\Service\TweetFetcher;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
@ -19,25 +20,48 @@ class RetweetTweetsCommand extends Command
|
|||
|
||||
private $retweeter;
|
||||
|
||||
public function __construct(TweetFetcher $tweetFetcher, Retweeter $retweeter)
|
||||
{
|
||||
/**
|
||||
* @var \App\Repository\TweetRepository
|
||||
*/
|
||||
private $tweetRepository;
|
||||
|
||||
/**
|
||||
* @var \Doctrine\ORM\EntityManagerInterface
|
||||
*/
|
||||
private $entityManager;
|
||||
|
||||
public function __construct(
|
||||
TweetFetcher $tweetFetcher,
|
||||
TweetRepository $tweetRepository,
|
||||
Retweeter $retweeter,
|
||||
EntityManagerInterface $entityManager
|
||||
) {
|
||||
parent::__construct();
|
||||
|
||||
$this->tweetFetcher = $tweetFetcher;
|
||||
$this->retweeter = $retweeter;
|
||||
$this->tweetRepository = $tweetRepository;
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setDescription('Add a short description for your command')
|
||||
->addOption('number', null, InputOption::VALUE_OPTIONAL, 'Specify how many tweets to retweet.', 1)
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->tweetFetcher->getTweets()->each(function (Tweet $tweet) {
|
||||
$this->tweetRepository->getUntweetedTweets($input->getOption('number'))->each(function (Tweet $tweet) {
|
||||
$this->retweeter->retweet($tweet);
|
||||
|
||||
$tweet->setRetweeted(time());
|
||||
|
||||
$this->entityManager->persist($tweet);
|
||||
});
|
||||
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue