Example #1
0
 /**
  * ForgetSend
  * Forgets (or resets) the class variables between each split test campaign being sent.
  *
  * This one just sets the _percentage_send_maximum variable back to the default (null)
  * then calls the parent ForgetSend method to do the rest.
  *
  * @uses _percentage_send_maximum
  * @uses Splittest_Send_API::ForgetSend
  *
  * @return Mixed Returns the status from the parent ForgetSend method.
  */
 protected function ForgetSend()
 {
     $this->_percentage_send_maximum = null;
     return parent::ForgetSend();
 }
Example #2
0
 /**
  * DeleteSchedules
  * If scheduled items are going to be deleted, this processes the jobs it needs to.
  *
  * The data passed in contains lots of data:
  * jobids - the job id's that need to be processed
  * message - the current success/failure message
  * success - the current success counter (how many jobs have successfully been deleted previous to getting here)
  * failure - the current failure counter (how many jobs have not successfully been deleted previous to getting here)
  *
  * Any non-"splittest" job types are skipped
  * Any "in progress" splittest jobs are skipped and the failure counter is incremented
  * Any jobs that can be deleted are - as well as figuring out whether a job needs to give back any email credits.
  *
  * Any appropriate messages are added to the "message" item in the passed in array.
  *
  * @param EventData_IEM_SCHEDULE_DELETEJOBS $data The data array containing the jobs to process, the current message, success and failure counts.
  *
  * @uses Jobs_API::LoadJob()
  * @uses Stats_API::DeleteUserStats()
  * @uses Stats_API::MarkNewsletterFinished()
  * @uses Splittest_Send_API::DeleteJob()
  * @uses User_API::ReduceEmails()
  * @uses EventData_IEM_SCHEDULE_DELETEJOBS
  */
 public static function DeleteSchedules(EventData_IEM_SCHEDULE_DELETEJOBS $data)
 {
     $jobids =& $data->jobids;
     $message =& $data->Message;
     $success =& $data->success;
     $failure =& $data->failure;
     $user = GetUser();
     require_once SENDSTUDIO_API_DIRECTORY . '/jobs.php';
     require_once SENDSTUDIO_API_DIRECTORY . '/stats.php';
     require_once dirname(__FILE__) . '/api/splittest_send.php';
     $jobapi = new Jobs_API();
     $stats_api = new Stats_API();
     $send_api = new Splittest_Send_API();
     foreach ($jobids as $p => $jobid) {
         $jobinfo = $jobapi->LoadJob($jobid);
         if (empty($jobinfo)) {
             continue;
         }
         if ($jobinfo['jobtype'] !== 'splittest') {
             continue;
         }
         if ($jobinfo['jobstatus'] == 'i') {
             $failure++;
             unset($jobids[$p]);
             continue;
         }
         $statids = array();
         if (isset($jobinfo['jobdetails']['Stats'])) {
             $statids = array_values($jobinfo['jobdetails']['Stats']);
         }
         /**
          * If there are no stats, then the send hasn't started yet.
          * So just credit the user back with the number of emails they were trying to send.
          * Use 'ReduceEmails' to re-add the credits by using a double negative :)
          */
         if (empty($statids) && $jobinfo['jobstatus'] == 'w') {
             $stats_api->DeleteUserStats($jobinfo['ownerid'], $jobid);
             $user->ReduceEmails(-(int) $jobinfo['jobdetails']['SendSize']);
         }
         /**
          * If a send is started (ie it has stats),
          * but is not completed,
          * We need to mark it as complete.
          *
          * This also credits a user back if they have any limits in place.
          *
          * This needs to happen before we delete the 'job' from the database
          * as deleting the job cleans up the queues/unsent items.
          */
         if (!empty($statids) && $jobinfo['jobstatus'] != 'c') {
             $stats_api->MarkNewsletterFinished($statids, $jobinfo['jobdetails']['SendSize']);
             // Credits needs to be returned too whenever the job is canceled AFTER it has been scheduled, but before it was sent
         } elseif ($jobinfo['jobstatus'] != 'c') {
             $stats_api->RefundFixedCredit($jobid);
         }
         $result = $send_api->DeleteJob($jobid);
         if ($result) {
             $success++;
         } else {
             $failure++;
         }
         unset($jobids[$p]);
     }
     /**
      * Only failure messages get added to the message stack.
      * Successful deletes are handled in the calling code
      * in case:
      * - a non-addon deletes an item
      * - other addons delete their own items
      */
     if ($failure > 0) {
         if ($failure == 1) {
             FlashMessage(GetLang('Addon_splittest_Schedule_JobDeleteFail'), SS_FLASH_MSG_ERROR);
         } else {
             FlashMessage(sprintf(GetLang('Addon_splittest_Schedule_JobsDeleteFail'), self::PrintNumber($failure)), SS_FLASH_MSG_SUCCESS);
         }
     }
     $message .= GetFlashMessages();
 }