Source of file RemoveDisabledCommand.php
Size: 2,398 Bytes - Last Modified: 2014-10-15T13:48:08+03:00
/Users/mcfedr/dev/awspushbundle/src/Mcfedr/AwsPushBundle/Command/RemoveDisabledCommand.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 | <?php namespace Mcfedr\AwsPushBundle\Command; use Aws\Sns\SnsClient; use Psr\Log\LoggerInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class RemoveDisabledCommand extends Command { /** * @var SnsClient */ private $sns; /** * @var array */ private $arns; /** * @var LoggerInterface */ private $logger; /** * @param SnsClient $sns * @param array $arns * @param \Psr\Log\LoggerInterface $logger */ public function __construct(SnsClient $sns, $arns, LoggerInterface $logger = null) { parent::__construct(); $this->sns = $sns; $this->arns = $arns; $this->logger = $logger; } protected function configure() { $this ->setName('mcfedr:aws:remove') ->setDescription('Remove disabled devices'); } protected function execute(InputInterface $input, OutputInterface $output) { foreach ($this->arns as $platform => $arn) { $this->logger && $this->logger->info("Removing from $platform"); $this->removeFromPlatform($platform); } } /** * Enable all devices registered on platform * * @param string $platform */ private function removeFromPlatform($platform) { foreach ($this->sns->getListEndpointsByPlatformApplicationIterator( [ 'PlatformApplicationArn' => $this->arns[$platform] ] ) as $endpoint) { if ($endpoint['Attributes']['Enabled'] == "false") { try { $this->sns->deleteEndpoint( [ 'EndpointArn' => $endpoint['EndpointArn'] ] ); $this->logger && $this->logger->info("Removed {$endpoint['EndpointArn']}"); } catch (\Exception $e) { $this->logger && $this->logger->error( "Failed to remove endpoint {$endpoint['EndpointArn']}", [ 'exception' => $e, 'endpoint' => $endpoint ] ); } } } } } |