/** * _FinishJob * This does a few cleanup jobs. * - Marks the job as complete in stats * - Clears out any unsent recipients from the "queue". * - Calls the parent FinishJob method to do it's work. * * @uses _stats_api * @uses Stats_API::MarkNewsletterFinished * @uses ClearQueue * @uses FinishJob * * @return Void Doesn't return anything. */ function _FinishJob() { /** * Pass all of the stats through to the stats api. * * Since the stats contains an array of: * newsletterid => statid * * we just need to pass through the statid's. */ $this->_stats_api->MarkNewsletterFinished(array_values($this->jobdetails['Stats']), $this->jobdetails['SendSize']); $this->ClearQueue($this->jobdetails['SendQueue'], 'splittest'); $this->FinishJob($this->_jobid, $this->jobdetails['splitid']); }
/** * Show_Send_Step_5 * Step 5 handles the final step of doing a send. * It marks the stats as finished, * it cleans up anything left over in the send queue * Then it calls PrintSendFailureReport to show a report of how many emails were sent and how long it took. * * @uses Stats_API::MarkNewsletterFinished * @uses PrintSendFailureReport * @uses GetApi * @uses Splittest_Send_API::FinishJob * @uses Jobs_API::ClearQueue */ public function Show_Send_Step_5() { $send_details = IEM::sessionGet('SplitTestSendDetails'); $this->template_system->Assign('AdminUrl', $this->admin_url, false); $jobid = $send_details['Job']; require_once SENDSTUDIO_API_DIRECTORY . '/stats.php'; $statsapi = new Stats_API(); /** * Pass all of the stats through to the stats api. * * Since the stats contains an array of: * newsletterid => statid * * we just need to pass through the statid's. */ $statsapi->MarkNewsletterFinished(array_values($send_details['Stats']), $send_details['SendSize']); $timetaken = $send_details['SendEndTime'] - $send_details['SendStartTime']; $timedifference = $this->TimeDifference($timetaken); $this->template_system->Assign('SendReport_Intro', sprintf(GetLang('Addon_splittest_Send_Step5_Intro'), $timedifference)); $sendreport = ''; if ($send_details['EmailResults']['success'] > 0) { if ($send_details['EmailResults']['success'] == 1) { FlashMessage(GetLang('Addon_splittest_Send_Step5_SendReport_Success_One'), SS_FLASH_MSG_SUCCESS); } else { FlashMessage(sprintf(GetLang('Addon_splittest_Send_Step5_SendReport_Success_Many'), $this->PrintNumber($send_details['EmailResults']['success'])), SS_FLASH_MSG_SUCCESS); } $sendreport = GetFlashMessages(); } $this->PrintSendFailureReport($jobid, $sendreport); require_once SENDSTUDIO_API_DIRECTORY . '/jobs.php'; $jobs_api = new Jobs_API(); $send_api = $this->GetApi('Splittest_Send'); $send_api->FinishJob($jobid, $send_details['splitid']); $jobs_api->ClearQueue($send_details['SendQueue'], 'splittest'); }
/** * 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(); }