Beispiel #1
0
 public function push()
 {
     if ($this->getErrors()) {
         return $this;
     }
     if (!$this->__certificate) {
         $this->setErrors(array($this->_("Please provide a certificate.")));
         return $this;
     }
     $this->createConnection();
     $device = new Push_Model_Iphone_Device();
     $app_id = $this->getMessage()->getAppId();
     if ($this->getMessage()->getSendToAll() == 0) {
         $category_message = new Topic_Model_Category_Message();
         $allowed_categories = $category_message->findCategoryByMessageId($this->getMessage()->getId());
     } else {
         $allowed_categories = null;
     }
     $devices = $device->findByAppId($app_id, $allowed_categories);
     $errors = array();
     $error = false;
     foreach ($devices as $device) {
         try {
             $this->sendMessage($device);
         } catch (Exception $e) {
             $errors[$device->getId()] = "Device {$device->getId()} -> {$e->getMessage()}";
         }
     }
     fclose($this->_stream_client);
     try {
         $this->_checkFeedback();
     } catch (Exception $e) {
         $errors[] = $e->getMessage();
     }
     $this->setErrors($errors);
     return $this;
 }