Skip to content
This repository has been archived by the owner on Jan 10, 2020. It is now read-only.

Commit

Permalink
Updating styles
Browse files Browse the repository at this point in the history
  • Loading branch information
bassrock committed Apr 24, 2016
1 parent ac308cf commit 91742e9
Show file tree
Hide file tree
Showing 10 changed files with 231 additions and 190 deletions.
16 changes: 8 additions & 8 deletions Command/SendFailedNotificationsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
use Symfony\Component\Routing\Exception\InvalidParameterException;


class SendFailedNotificationsCommand extends ContainerAwareCommand{
protected function configure() {
class SendFailedNotificationsCommand extends ContainerAwareCommand
{
protected function configure()
{
$this->setName('dab:push:send:failed');
$this->setDescription('Send all unsent push notifications.');
}

protected function execute(InputInterface $input, OutputInterface $output) {
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var $messageManager \DABSquared\PushNotificationsBundle\Model\MessageManager */
$messageManager = $this->getContainer()->get('dab_push_notifications.manager.message');

Expand All @@ -35,7 +38,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$messages = $messageManager->findByStatus(MessageStatus::MESSAGE_STATUS_NO_CERT);

/** @var $message \DABSquared\PushNotificationsBundle\Model\Message */
foreach($messages as $message) {
foreach ($messages as $message) {
$message->setStatus(MessageStatus::MESSAGE_STATUS_SENDING);
$messageManager->saveMessage($message);
}
Expand All @@ -46,15 +49,12 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$messages = $messageManager->findByStatus(MessageStatus::MESSAGE_STATUS_STREAM_ERROR);

/** @var $message \DABSquared\PushNotificationsBundle\Model\Message */
foreach($messages as $message) {
foreach ($messages as $message) {
$message->setStatus(MessageStatus::MESSAGE_STATUS_SENDING);
$messageManager->saveMessage($message);
}

$notificationManager->sendMessages($messages);


die();
}
}

Expand Down
35 changes: 16 additions & 19 deletions Command/SendNotificationsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
use Symfony\Component\Routing\Exception\InvalidParameterException;


class SendNotificationsCommand extends ContainerAwareCommand{
protected function configure() {
class SendNotificationsCommand extends ContainerAwareCommand
{
protected function configure()
{
$this->setName('dab:push:send')
->setDescription('Send all unsent push notifications.')
->setDefinition(array(
new InputArgument('messageId',
InputArgument::OPTIONAL,
'The message to send'),));
->setDefinition(array(new InputArgument('messageId', InputArgument::OPTIONAL, 'The message to send')));
}

protected function execute(InputInterface $input, OutputInterface $output) {
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var $messageManager \DABSquared\PushNotificationsBundle\Model\MessageManagerInterface */
$messageManager = $this->getContainer()->get('dab_push_notifications.manager.message');

Expand All @@ -39,30 +39,30 @@ protected function execute(InputInterface $input, OutputInterface $output) {

$messages = array();

if(!is_null($messageId)) {
if (!is_null($messageId)) {
$messages = $messageManager->findById($messageId);
/** @var $message \DABSquared\PushNotificationsBundle\Model\MessageInterface */
foreach($messages as $message) {
if($message->getStatus() == MessageStatus::MESSAGE_STATUS_SENT) {
foreach ($messages as $message) {
if ($message->getStatus() == MessageStatus::MESSAGE_STATUS_SENT) {
throw new InvalidParameterException("This message has already been sent");
}
}
} else {
$messages = $messageManager->findByStatus(MessageStatus::MESSAGE_STATUS_NOT_SENT);
$messages = $messageManager->findByStatus(MessageStatus::MESSAGE_STATUS_NOT_SENT);
}



/** @var $message \DABSquared\PushNotificationsBundle\Model\MessageInterface */
foreach($messages as $message) {
foreach ($messages as $message) {
$message->setStatus(MessageStatus::MESSAGE_STATUS_SENDING);
$messageManager->saveMessage($message);
}

$notificationManager->sendMessages($messages);

if(!is_null($messageId)) {
die();
if (!is_null($messageId)) {
return;
}


Expand All @@ -72,7 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$messages = $messageManager->findByStatus(MessageStatus::MESSAGE_STATUS_NO_CERT);

/** @var $message \DABSquared\PushNotificationsBundle\Model\MessageInterface */
foreach($messages as $message) {
foreach ($messages as $message) {
$message->setStatus(MessageStatus::MESSAGE_STATUS_SENDING);
$messageManager->saveMessage($message);
}
Expand All @@ -83,15 +83,12 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$messages = $messageManager->findByStatus(MessageStatus::MESSAGE_STATUS_STREAM_ERROR);

/** @var $message \DABSquared\PushNotificationsBundle\Model\MessageInterface */
foreach($messages as $message) {
foreach ($messages as $message) {
$message->setStatus(MessageStatus::MESSAGE_STATUS_SENDING);
$messageManager->saveMessage($message);
}

$notificationManager->sendMessages($messages);


die();
}
}

Expand Down
25 changes: 14 additions & 11 deletions Command/iOSFeedbackCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,28 @@

use DABSquared\PushNotificationsBundle\Device\DeviceStatus;
use DABSquared\PushNotificationsBundle\Device\Types;
use DABSquared\PushNotificationsBundle\Message\MessageStatus;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Routing\Exception\InvalidParameterException;


class iOSFeedbackCommand extends ContainerAwareCommand{
protected function configure() {
class iOSFeedbackCommand extends ContainerAwareCommand
{

protected function configure()
{
$this->setName('dab:push:ios:feedback');
$this->setDescription('Contacts iOS feedback service to correctly set device statuses.');
$arguments = array();
$arguments[] = new InputArgument('appId',InputArgument::OPTIONAL,'The internal app id to get feedback for.');
$arguments[] = new InputArgument('sandbox',InputArgument::OPTIONAL,'Whether or not to get sandbox feedback or not.');
$arguments[] = new InputArgument('appId', InputArgument::OPTIONAL, 'The internal app id to get feedback for.');
$arguments[] = new InputArgument('sandbox', InputArgument::OPTIONAL, 'Whether or not to get sandbox feedback or not.');
$this->setDefinition($arguments);
}

protected function execute(InputInterface $input, OutputInterface $output) {
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var $iosFeedback \DABSquared\PushNotificationsBundle\Service\iOSFeedback */
$iosFeedback = $this->getContainer()->get('dab_push_notifications.ios.feedback');

Expand All @@ -39,19 +42,19 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$appId = $input->getArgument("appId");
$sandbox = $input->getArgument("sandbox");

if(!is_null($sandbox)) {
if(!filter_var($sandbox, FILTER_VALIDATE_BOOLEAN)) {
if (!is_null($sandbox)) {
if (!filter_var($sandbox, FILTER_VALIDATE_BOOLEAN)) {
throw new InvalidParameterException("Sandbox needs to be a 1 (True) or a 0 (False) or null for both.");
}
}

$feedbacks = $iosFeedback->getDeviceFeedback($appId,$sandbox);
$feedbacks = $iosFeedback->getDeviceFeedback($appId, $sandbox);

/** @var $feedback \DABSquared\PushNotificationsBundle\Device\iOS\Feedback */
foreach($feedbacks as $feedback) {
foreach ($feedbacks as $feedback) {
$output->writeln("UUID: ".$feedback->uuid." Token Length: ". $feedback->tokenLength." Timestamp: ".$feedback->timestamp);
$device = $deviceManager->findDeviceByTypeIdentifierAndAppId(Types::OS_IOS, $feedback->uuid, $feedback->internalAppId);
if(!is_null($device)) {
if (!is_null($device)) {
$device->setStatus(DeviceStatus::DEVICE_STATUS_UNACTIVE);
$deviceManager->saveDevice($device);
}
Expand Down
60 changes: 36 additions & 24 deletions Controller/DeviceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class DeviceController extends Controller
* @RequestParam(name="app_id", description="The internal app id that is registered in the Symfony 2 config.", strict=true)
* @RequestParam(name="device_identifier", description="The vendor device identifier of the iOS device.", strict=true)
*/
public function registeriOSDeviceAction(ParamFetcher $paramFetcher) {
public function registeriOSDeviceAction(ParamFetcher $paramFetcher)
{
$deviceToken = $paramFetcher->get('device_token');
$deviceName = $paramFetcher->get('device_name');
$deviceModel = $paramFetcher->get('device_model');
Expand All @@ -83,12 +84,14 @@ public function registeriOSDeviceAction(ParamFetcher $paramFetcher) {
/** @var $device \DABSquared\PushNotificationsBundle\Model\Device */
$device = $deviceManager->findDeviceByTypeIdentifierAndAppId(Types::OS_IOS, $deviceIdentifier, $appId);

if(is_null($device)) {
$device = $deviceManager->createDevice($device);
if (is_null($device)) {
$device = $deviceManager->createDevice();
}

if($device instanceof UserDeviceInterface) {
$user = $this->get('security.context')->getToken()->getUser();
if ($device instanceof UserDeviceInterface) {
$user = $this->get('security.token_storage')->getToken()->getUser();

/** @var $device \DABSquared\PushNotificationsBundle\Model\UserDeviceInterface */
$device->setUser($user);
}
$device->setAppId($appId);
Expand Down Expand Up @@ -130,7 +133,8 @@ public function registeriOSDeviceAction(ParamFetcher $paramFetcher) {
* @RequestParam(name="app_version", description="The version of the app that is registering.", strict=true)
* @RequestParam(name="app_id", description="The internal app id that is registered in the Symfony 2 config.", strict=true)
*/
public function registerGCMRegistrationIDAction(ParamFetcher $paramFetcher) {
public function registerGCMRegistrationIDAction(ParamFetcher $paramFetcher)
{
$deviceToken = $paramFetcher->get('device_token');
$deviceName = $paramFetcher->get('device_name');
$deviceModel = $paramFetcher->get('device_model');
Expand All @@ -146,12 +150,13 @@ public function registerGCMRegistrationIDAction(ParamFetcher $paramFetcher) {
/** @var $device \DABSquared\PushNotificationsBundle\Model\Device */
$device = $deviceManager->findDeviceByTypeIdentifierAndAppIdAndDeviceToken(Types::OS_ANDROID_GCM, $deviceIdentifier, $appId, $deviceToken);

if(is_null($device)) {
$device = $deviceManager->createDevice($device);
if (is_null($device)) {
$device = $deviceManager->createDevice();
}

if($device instanceof UserDeviceInterface) {
$user = $this->get('security.context')->getToken()->getUser();
if ($device instanceof UserDeviceInterface) {
$user = $this->get('security.token_storage')->getToken()->getUser();
/** @var $device \DABSquared\PushNotificationsBundle\Model\UserDeviceInterface */
$device->setUser($user);
}

Expand Down Expand Up @@ -187,7 +192,8 @@ public function registerGCMRegistrationIDAction(ParamFetcher $paramFetcher) {
* @RequestParam(name="device_identifier", description="The vendor device identifier of the iOS device.", strict=true)
* @RequestParam(name="app_id", description="The internal app id that is registered in the Symfony 2 config.", strict=true)
*/
public function unregisteriOSDeviceAction(ParamFetcher $paramFetcher) {
public function unregisteriOSDeviceAction(ParamFetcher $paramFetcher)
{
$appId = $paramFetcher->get('app_id');
$deviceIdentifier = $paramFetcher->get('device_identifier');

Expand All @@ -197,7 +203,7 @@ public function unregisteriOSDeviceAction(ParamFetcher $paramFetcher) {
/** @var $device \DABSquared\PushNotificationsBundle\Model\Device */
$device = $deviceManager->findDeviceByTypeIdentifierAndAppId(Types::OS_IOS, $deviceIdentifier, $appId);

if(!is_null($device)) {
if (!is_null($device)) {
$device->setStatus(DeviceStatus::DEVICE_STATUS_UNACTIVE);
$device->setBadgeNumber(0);
$deviceManager->saveDevice($device);
Expand All @@ -218,7 +224,8 @@ public function unregisteriOSDeviceAction(ParamFetcher $paramFetcher) {
* @RequestParam(name="device_identifier", description="The vendor device identifier of the Android device.", strict=true)
* @RequestParam(name="app_id", description="The internal app id that is registered in the Symfony 2 config.", strict=true)
*/
public function unregisterGCMDeviceAction(ParamFetcher $paramFetcher) {
public function unregisterGCMDeviceAction(ParamFetcher $paramFetcher)
{
$appId = $paramFetcher->get('app_id');
$deviceIdentifier = $paramFetcher->get('device_identifier');

Expand All @@ -228,7 +235,7 @@ public function unregisterGCMDeviceAction(ParamFetcher $paramFetcher) {
/** @var $device \DABSquared\PushNotificationsBundle\Model\Device */
$device = $deviceManager->findDeviceByTypeIdentifierAndAppId(Types::OS_ANDROID_GCM, $deviceIdentifier, $appId);

if(!is_null($device)) {
if (!is_null($device)) {
$device->setStatus(DeviceStatus::DEVICE_STATUS_UNACTIVE);
$device->setBadgeNumber(0);
$deviceManager->saveDevice($device);
Expand All @@ -249,7 +256,8 @@ public function unregisterGCMDeviceAction(ParamFetcher $paramFetcher) {
* @RequestParam(name="device_identifier", description="The device identifier you defined.", strict=true)
* @RequestParam(name="app_id", description="The internal app id that is registered in the Symfony 2 config.", strict=true)
*/
public function appOpenAction(ParamFetcher $paramFetcher) {
public function appOpenAction(ParamFetcher $paramFetcher)
{
$appId = $paramFetcher->get('app_id');
$deviceIdentifier =$paramFetcher->get('device_identifier');

Expand All @@ -262,7 +270,7 @@ public function appOpenAction(ParamFetcher $paramFetcher) {
/** @var $device \DABSquared\PushNotificationsBundle\Model\Device */
$device = $deviceManager->findDeviceByTypeIdentifierAndAppId(Types::OS_IOS, $deviceIdentifier, $appId);

if(!is_null($device)) {
if (!is_null($device)) {
$device->setBadgeNumber(0);
$deviceManager->saveDevice($device);
$appEvent = $appEventManager->createAppEvent();
Expand All @@ -286,7 +294,8 @@ public function appOpenAction(ParamFetcher $paramFetcher) {
* @RequestParam(name="device_identifier", description="The device identifier you defined.", strict=true)
* @RequestParam(name="app_id", description="The internal app id that is registered in the Symfony 2 config.", strict=true)
*/
public function appiOSOpenAction(ParamFetcher $paramFetcher) {
public function appiOSOpenAction(ParamFetcher $paramFetcher)
{
$appId = $paramFetcher->get('app_id');
$deviceIdentifier =$paramFetcher->get('device_identifier');

Expand All @@ -301,7 +310,7 @@ public function appiOSOpenAction(ParamFetcher $paramFetcher) {



if(!is_null($device)) {
if (!is_null($device)) {
$device->setBadgeNumber(0);
$deviceManager->saveDevice($device);
$appEvent = $appEventManager->createAppEvent();
Expand All @@ -325,7 +334,8 @@ public function appiOSOpenAction(ParamFetcher $paramFetcher) {
* @RequestParam(name="device_identifier", description="The device identifier you defined.", strict=true)
* @RequestParam(name="app_id", description="The internal app id that is registered in the Symfony 2 config.", strict=true)
*/
public function appiOSTerminatedAction(ParamFetcher $paramFetcher) {
public function appiOSTerminatedAction(ParamFetcher $paramFetcher)
{
$appId = $paramFetcher->get('app_id');
$deviceIdentifier =$paramFetcher->get('device_identifier');

Expand All @@ -338,7 +348,7 @@ public function appiOSTerminatedAction(ParamFetcher $paramFetcher) {
/** @var $device \DABSquared\PushNotificationsBundle\Model\Device */
$device = $deviceManager->findDeviceByTypeIdentifierAndAppId(Types::OS_IOS, $deviceIdentifier, $appId);

if(!is_null($device)) {
if (!is_null($device)) {
$appEvent = $appEventManager->createAppEvent();
$appEvent->setType(AppEventInterface::APP_TERMINATED);
$appEvent->setDevice($device);
Expand All @@ -360,7 +370,8 @@ public function appiOSTerminatedAction(ParamFetcher $paramFetcher) {
* @RequestParam(name="device_identifier", description="The device identifier you defined.", strict=true)
* @RequestParam(name="app_id", description="The internal app id that is registered in the Symfony 2 config.", strict=true)
*/
public function appiOSBackgroundedAction(ParamFetcher $paramFetcher) {
public function appiOSBackgroundedAction(ParamFetcher $paramFetcher)
{
$appId = $paramFetcher->get('app_id');
$deviceIdentifier =$paramFetcher->get('device_identifier');

Expand All @@ -373,7 +384,7 @@ public function appiOSBackgroundedAction(ParamFetcher $paramFetcher) {
/** @var $device \DABSquared\PushNotificationsBundle\Model\Device */
$device = $deviceManager->findDeviceByTypeIdentifierAndAppId(Types::OS_IOS, $deviceIdentifier, $appId);

if(!is_null($device)) {
if (!is_null($device)) {
$appEvent = $appEventManager->createAppEvent();
$appEvent->setType(AppEventInterface::APP_BACKGROUNDED);
$appEvent->setDevice($device);
Expand All @@ -396,7 +407,8 @@ public function appiOSBackgroundedAction(ParamFetcher $paramFetcher) {
* @RequestParam(name="app_id", description="The internal app id that is registered in the Symfony 2 config.", strict=true)
* @RequestParam(name="device_token", description="The registration id returned from GCM", strict=true)
*/
public function appGCMOpenAction(ParamFetcher $paramFetcher) {
public function appGCMOpenAction(ParamFetcher $paramFetcher)
{
$appId = $paramFetcher->get('app_id');
$deviceIdentifier =$paramFetcher->get('device_identifier');
$deviceToken = $paramFetcher->get('device_token');
Expand All @@ -407,7 +419,7 @@ public function appGCMOpenAction(ParamFetcher $paramFetcher) {
/** @var $device \DABSquared\PushNotificationsBundle\Model\Device */
$device = $deviceManager->findDeviceByTypeIdentifierAndAppIdAndDeviceToken(Types::OS_ANDROID_GCM, $deviceIdentifier, $appId, $deviceToken);

if(!is_null($device)) {
if (!is_null($device)) {
$device->setBadgeNumber(0);
$deviceManager->saveDevice($device);
}
Expand Down
Loading

0 comments on commit 91742e9

Please sign in to comment.