/** * Enable all devices registered on platform * * @param string $platform */ private function removeFromPlatform($platform) { foreach ($this->sns->getPaginator('ListEndpointsByPlatformApplication', ['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]); } } } }
private function addEndpoint(Model\AbstractEndpoint $endpoint) { try { $result = $this->sns->createPlatformEndpoint(['PlatformApplicationArn' => $this->getPlatformArn($endpoint), 'Token' => $endpoint->getToken(), 'CustomUserData' => $endpoint->getUser()->getId()]); } catch (\Aws\Sns\Exception\InvalidParameterException $e) { if (preg_match('/Endpoint (.*) already exists/', $e->getResponse()->getMessage(), $matches)) { $this->sns->deleteEndpoint(array('EndpointArn' => $matches[1])); $result = $this->sns->createPlatformEndpoint(['PlatformApplicationArn' => $this->getPlatformArn($endpoint), 'Token' => $endpoint->getToken(), 'CustomUserData' => $endpoint->getUser()->getId()]); } else { return; } } $endpoint->setArn($result['EndpointArn']); $this->em->persist($endpoint); $this->em->flush($endpoint); }
/** * Unregister a device, using its endpoint ARN * * @param string $endpoint */ public function unregisterDevice($endpoint) { $this->sns->deleteEndpoint(['EndpointArn' => $endpoint]); }