public function process() { $sent = 0; $filter = array('WorkflowStatus' => array('Active', 'Paused'), 'Definition.RemindDays:GreaterThan' => 0); $active = WorkflowInstance::get()->filter($filter); foreach ($active as $instance) { $edited = strtotime($instance->LastEdited); $days = $instance->Definition()->RemindDays; if ($edited + $days * 3600 * 24 > time()) { continue; } $email = new Email(); $bcc = ''; $members = $instance->getAssignedMembers(); $target = $instance->getTarget(); if (!$members || !count($members)) { continue; } $email->setSubject("Workflow Reminder: {$instance->Title}"); $email->setBcc(implode(', ', $members->column('Email'))); $email->setTemplate('WorkflowReminderEmail'); $email->populateTemplate(array('Instance' => $instance, 'Link' => $target instanceof SiteTree ? "admin/show/{$target->ID}" : '')); $email->send(); $sent++; // add a comment to the workflow if possible $action = $instance->CurrentAction(); $currentComment = $action->Comment; $action->Comment = sprintf(_t('AdvancedWorkflow.JOB_REMINDER_COMMENT', '%s: Reminder email sent\\n\\n'), date('Y-m-d H:i:s')) . $currentComment; try { $action->write(); } catch (Exception $ex) { SS_Log::log($ex, SS_Log::WARN); } $instance->LastEdited = time(); try { $instance->write(); } catch (Exception $ex) { SS_Log::log($ex, SS_Log::WARN); } } $this->currentStep = 2; $this->isComplete = true; $nextDate = date('Y-m-d H:i:s', time() + $this->repeatInterval); $this->queuedJobService->queueJob(new WorkflowReminderJob($this->repeatInterval), $nextDate); }
/** * Save the post * * @param DataObject $post * @param type $data */ public function savePost(DataObject $post, $data) { if ($post->checkPerm('Write') && isset($data['Content'])) { $post->Content = $data['Content']; if ($this->securityContext->getMember()->Balance >= MicroBlogMember::BALANCE_THRESHOLD) { $post->analyseContent(); $post->write(); } else { $this->queuedJobService->queueJob(new ProcessPostJob($post)); } $html = $post->renderWith('PostContent'); return $post; } }
/** * @param array $data * @param Form $form * @return SS_HTTPResponse */ public function createjob($data, Form $form) { if (Permission::check('ADMIN')) { $jobType = isset($data['JobType']) ? $data['JobType'] : ''; $params = isset($data['JobParams']) ? $data['JobParams'] : array(); $time = isset($data['JobStart']) ? $data['JobStart'] : null; $js = $form->Fields()->dataFieldByName('JobStart'); $time = $js->Value(); if ($jobType && class_exists($jobType)) { $jobClass = new ReflectionClass($jobType); $job = $jobClass->newInstanceArgs($params); $this->jobQueue->queueJob($job, $time); } } return $this->responseNegotiator->respond($this->getRequest()); }