public function testWriteLog()
 {
     $rawData = '[{"sg_event_id":"8rQZ-LulQcObW_2WyUTLpg","zurmoToken":"' . md5(ZURMO_TOKEN) . '","sg_message_id":"14826db909d.7e66.8eff7e.filter-297.4955.5401C16C1B.0","event":"processed","itemClass":"CampaignItem","email":"*****@*****.**","itemId":31,"smtp-id":"<*****@*****.**>","timestamp":1409401197,"personId":42}]';
     // Not Coding Standard
     SendGridLogUtil::writeLog('test', $rawData);
     $logPath = SendGridLogUtil::getLogFilePath('test');
     $this->assertTrue(file_exists($logPath));
     $testContent = file_get_contents($logPath);
     $this->assertEquals($rawData, $testContent);
     @unlink($logPath);
     //Failure test
     $rawData = '[{"sg_event_id":"8rQZ-LulQcObW_2WyUTLpg","sg_message_id":"14826db909d.7e66.8eff7e.filter-297.4955.5401C16C1B.0","event":"processed","itemClass":"CampaignItem","email":"*****@*****.**","itemId":31,"smtp-id":"<*****@*****.**>","timestamp":1409401197,"personId":42}]';
     // Not Coding Standard
     SendGridLogUtil::writeLog('test', $rawData);
     $logPath = SendGridLogUtil::getLogFilePath('test');
     $this->assertFalse(file_exists($logPath));
 }
 /**
  * (non-PHPdoc)
  * @see BaseJob::run()
  */
 public function run()
 {
     $sendGridEmailAccounts = SendGridEmailAccount::getAll();
     foreach ($sendGridEmailAccounts as $sendGridEmailAccount) {
         $eventWebhookFilePath = SendGridLogUtil::getLogFilePath($sendGridEmailAccount->apiUsername);
         if ($eventWebhookFilePath != null && file_exists($eventWebhookFilePath)) {
             $this->processEventData($eventWebhookFilePath);
             @file_put_contents($eventWebhookFilePath, '');
         }
     }
     //Global
     if (Yii::app()->sendGridEmailHelper->apiUsername != '') {
         $globalWebHookFilePath = SendGridLogUtil::getLogFilePath(Yii::app()->sendGridEmailHelper->apiUsername);
         if ($globalWebHookFilePath != null && file_exists($globalWebHookFilePath)) {
             $this->processEventData($globalWebHookFilePath);
             @file_put_contents($globalWebHookFilePath, '');
         }
     }
     return true;
 }
 /**
  * Writes log.
  * @param string $username Username for the sendgrid api
  * @see Global configuration screen for sendgrid. The username there is what is being
  * input here.
  */
 public function actionWriteLog($username)
 {
     SendGridLogUtil::writeLog($username, file_get_contents("php://input"));
 }
 /**
  * Write log for send
  * @param string $apiUsername
  */
 public static function writeLog($apiUsername, $rawData)
 {
     $logFile = SendGridLogUtil::getLogFilePath($apiUsername);
     $fp = fopen($logFile, 'a+');
     // Not Coding Standard
     if ($fp) {
         if (empty($rawData)) {
             $rawData = CJSON::encode(array('data' => 'empty data'));
         }
         fwrite($fp, print_r($rawData, true));
         fclose($fp);
     }
 }