protected function execJob($name, $data) { require_once 'include/SugarQueue/SugarJobQueue.php'; $job = new SchedulersJob(); $job->name = "Bug56573Test Alert Job - '{$name}'"; $job->target = "class::Bug56573TestJob"; $job->data = $data; $job->assigned_user_id = $GLOBALS['current_user']->id; // Add the Job the the job Queue $jq = new SugarJobQueue(); $jq->submitJob($job); // Run the job $job->runJob(); // Save id for cleaning $this->id = $job->id; return $job; }
function aorRunScheduledReports() { require_once 'include/SugarQueue/SugarJobQueue.php'; $date = new DateTime(); //Ensure we check all schedules at the same instant foreach (BeanFactory::getBean('AOR_Scheduled_Reports')->get_full_list() as $scheduledReport) { if ($scheduledReport->shouldRun($date)) { if (empty($scheduledReport->aor_report_id)) { continue; } $job = new SchedulersJob(); $job->name = "Scheduled report - {$scheduledReport->name} on {$date->format('c')}"; $job->data = $scheduledReport->id; $job->target = "class::AORScheduledReportJob"; $job->assigned_user_id = 1; $jq = new SugarJobQueue(); $jq->submitJob($job); } } }
/** * handle creating or updating a currency record * */ function handleAdd() { global $current_user; if ($current_user->is_admin) { if (isset($_POST['edit']) && $_POST['edit'] == 'true' && isset($_POST['name']) && !empty($_POST['name']) && isset($_POST['conversion_rate']) && !empty($_POST['conversion_rate']) && isset($_POST['symbol']) && !empty($_POST['symbol'])) { $currency = BeanFactory::getBean('Currencies'); $isUpdate = false; if (isset($_POST['record']) && !empty($_POST['record'])) { $isUpdate = true; $currency->retrieve($_POST['record']); } $currency->name = $_POST['name']; $currency->status = $_POST['status']; $currency->symbol = $_POST['symbol']; $currency->iso4217 = $_POST['iso4217']; $previousConversionRate = $currency->conversion_rate; $currency->conversion_rate = (string) unformat_number($_POST['conversion_rate']); $currency->save(); $this->focus = $currency; // Used to tell calling code that a change was made $this->recordSaved = true; //Check if the conversion rates changed and, if so, update the rates with a scheduler job if ($isUpdate && $previousConversionRate != $currency->conversion_rate) { global $timedate; // use bean factory here $job = BeanFactory::getBean('SchedulersJobs'); $job->name = "SugarJobUpdateCurrencyRates: " . $timedate->getNow()->asDb(); $job->target = "class::SugarJobUpdateCurrencyRates"; $job->data = $currency->id; $job->retry_count = 0; $job->assigned_user_id = $current_user->id; $jobQueue = new SugarJobQueue(); $jobQueue->submitJob($job); } } } }
/** * @param array $data The data for the Job * @param bool $returnJob When `true` the job will be returned, otherwise the job id will be returned * @param string|null $job_group The Group that this job belongs to * @return SchedulersJob|String */ public static function createJob(array $data, $returnJob = false, $job_group = null) { global $current_user; /* @var $job SchedulersJob */ $job = BeanFactory::getBean('SchedulersJobs'); $job->name = "Update Old Opportunities"; $job->target = "class::SugarJobUpdateOpportunities"; $job->data = json_encode($data); $job->retry_count = 0; $job->assigned_user_id = $current_user->id; if (!is_null($job_group)) { $job->job_group = $job_group; } require_once 'include/SugarQueue/SugarJobQueue.php'; $job_queue = new SugarJobQueue(); $job_queue->submitJob($job); if ($returnJob === true) { return $job; } return $job->id; }
/** * Create a job for the backend to process records on. * * @param string $forecast_by * @param array $data * @param string $user_id */ protected function createUpdateForecastWorksheetJob($forecast_by, array $data, $user_id) { /* @var $job SchedulersJob */ $job = BeanFactory::getBean('SchedulersJobs'); $job->name = "Update ForecastWorksheets"; $job->target = "class::SugarJobUpdateForecastWorksheets"; $job->data = json_encode(array('forecast_by' => $forecast_by, 'data' => $data)); $job->retry_count = 0; $job->assigned_user_id = $user_id; require_once 'include/SugarQueue/SugarJobQueue.php'; $jq = new SugarJobQueue(); $jq->submitJob($job); }
*/ $modListHeader = array(); require_once 'modules/Reports/schedule/ReportSchedule.php'; require_once 'modules/Reports/utils.php'; require_once 'include/modules.php'; require_once 'config.php'; /** @var Localization $locale */ global $sugar_config, $current_language, $app_list_strings, $app_strings, $locale, $timedate; $language = $sugar_config['default_language']; // here we'd better use English, because pdf coding problem. $app_list_strings = return_app_list_strings_language($language); $app_strings = return_application_language($language); $reportSchedule = new ReportSchedule(); $reportSchedule->handleFailedReports(); $reportsToEmail = $reportSchedule->get_reports_to_email(); //Process Enterprise Schedule reports via CSV //bug: 23934 - enable Advanced reports require_once 'modules/ReportMaker/process_scheduled.php'; global $report_modules, $modListHeader, $current_user; $queue = new SugarJobQueue(); foreach ($reportsToEmail as $scheduleInfo) { $job = BeanFactory::getBean('SchedulersJobs'); $job->name = 'Send Scheduled Report ' . $scheduleInfo['report_id']; $job->assigned_user_id = $scheduleInfo['user_id']; $job->target = 'class::SugarJobSendScheduledReport'; $job->data = $scheduleInfo['id']; $job->job_group = $scheduleInfo['report_id']; $queue->submitJob($job); } sugar_cleanup(false); // continue script execution so that if run from Scheduler, job status will be set back to "Active"
/** * Helper for processing subscriptions on a bean-related activity. * * @param SugarBean $bean * @param Activity $act * @param array $args * @param array $params */ public static function processSubscriptions(SugarBean $bean, Activity $act, array $args, $params = array()) { $userPartials = self::getSubscribedUsers($bean, 'array', $params); $data = array('act_id' => $act->id, 'args' => $args, 'user_partials' => $userPartials); if (count($userPartials) < 5) { self::addActivitySubscriptions($data); } else { $job = BeanFactory::getBean('SchedulersJobs'); $job->requeue = 1; $job->name = "ActivityStream add"; $job->data = serialize($data); $job->target = "class::SugarJobAddActivitySubscriptions"; $job->assigned_user_id = $GLOBALS['current_user']->id; $queue = new SugarJobQueue(); $queue->submitJob($job); } }
/** * Create a job queue FTS consumer for a specific module * * @param string $module * @param bool $runNow Run job immediately instead of placing in job queue * @return string Id of newly created job */ public function createJobQueueConsumerForModule($module, $runNow = false) { $jobBean = BeanFactory::getBean('SchedulersJobs'); $q = sprintf("SELECT name FROM %s\n WHERE name = 'FTSConsumer %s' AND deleted = 0 AND status != '%s'", $jobBean->table_name, $module, SchedulersJob::JOB_STATUS_DONE); $res = $jobBean->db->query($q); if ($row = $GLOBALS['db']->fetchByAssoc($res)) { $GLOBALS['log']->info("Job queue already exists for: FTSConsumer {$module}"); return; } $GLOBALS['log']->info("Creating FTS Job queue consumer for: {$module} "); $job = new SchedulersJob(); $job->data = $module; $job->name = "FTSConsumer {$module}"; $job->target = "class::SugarSearchEngineFullIndexer"; $job->assigned_user_id = 1; if ($runNow) { $job->runJob(); } else { $queue = new SugarJobQueue(); $queue->submitJob($job); } return $job->id; }
public function getJob($jobId) { return parent::getJob($jobId); }
private function scheduleOpportunityRevenueLineItemNoteCreate(array $labels, array $chunk, $job_group) { /* @var $job SchedulersJob */ $job = BeanFactory::getBean('SchedulersJobs'); $job->name = "Create Revenue Line Items Note On Opportunities"; $job->target = "class::SugarJobCreateRevenueLineItemNotes"; $job->data = json_encode(array('chunk' => $chunk, 'labels' => $labels)); $job->retry_count = 0; $job->assigned_user_id = $GLOBALS['current_user']->id; $job->job_group = $job_group; require_once 'include/SugarQueue/SugarJobQueue.php'; $jq = new SugarJobQueue(); $jq->submitJob($job); }
public function submitJob($job) { $this->jobs[] = $job; parent::submitJob($job); }
/** * Create a job for the Scheduler to create the RLI's for. * * @param array $data * @param string $job_group */ protected function createRevenueLineItemJob(array $data, $job_group) { /* @var $job SchedulersJob */ $job = BeanFactory::getBean('SchedulersJobs'); $job->name = "Create RevenueLineItems for Opportunities"; $job->target = "class::SugarJobCreateRevenueLineItems"; $job->data = json_encode(array('data' => $data)); $job->retry_count = 0; $job->assigned_user_id = $GLOBALS['current_user']->id; $job->job_group = $job_group; require_once 'include/SugarQueue/SugarJobQueue.php'; $jq = new SugarJobQueue(); $jq->submitJob($job); }
/** * do post update process to update the opportunity RLIs, ENT only */ public function doPostUpdateAction() { $sql = "SELECT opportunity_id AS opp_id,\n Sum(likely_case) AS likely,\n Sum(worst_case) AS worst,\n Sum(best_case) AS best\n FROM (SELECT rli.opportunity_id,\n (rli.likely_case/rli.base_rate) as likely_case,\n (rli.worst_case/rli.base_rate) as worst_case,\n (rli.best_case/rli.base_rate) as best_case\n FROM revenue_line_items AS rli\n WHERE rli.deleted = 0) AS T\n GROUP BY opp_id"; $results = $this->db->query($sql); $stages = $this->getClosedStages(); $queries = array(); // skip closed opps $sql_tpl = "UPDATE opportunities SET amount = '%s', best_case = '%s', worst_case = '%s' WHERE id = '%s' AND sales_status NOT IN ('%s')"; while ($row = $this->db->fetchRow($results)) { $queries[] = sprintf($sql_tpl, $row['likely'], $row['best'], $row['worst'], $row['opp_id'], implode("','", $stages)); } if (count($queries) < self::CHUNK_SIZE) { // do queries in this process foreach ($queries as $query) { $this->db->query($query); } } else { // schedule queries to SQLRunner job scheduler $chunks = array_chunk($queries, self::CHUNK_SIZE); global $timedate, $current_user; foreach ($chunks as $chunk) { $job = BeanFactory::getBean('SchedulersJobs'); $job->name = "SugarJobSQLRunner: " . $timedate->getNow()->asDb(); $job->target = "class::SugarJobSQLRunner"; $job->data = serialize($chunk); $job->retry_count = 0; $job->assigned_user_id = $current_user->id; $jobQueue = new SugarJobQueue(); $jobQueue->submitJob($job); } } return true; }
/** * Checks if any jobs qualify to run at this moment * @param SugarJobQueue $queue */ public function checkPendingJobs($queue) { $allSchedulers = $this->get_full_list('', "schedulers.status='Active' AND NOT EXISTS(SELECT id FROM {$this->job_queue_table} WHERE scheduler_id=schedulers.id AND status!='" . SchedulersJob::JOB_STATUS_DONE . "')"); $GLOBALS['log']->info('-----> Scheduler found [ ' . count($allSchedulers) . ' ] ACTIVE jobs'); if (!empty($allSchedulers)) { foreach ($allSchedulers as $focus) { if ($focus->fireQualified()) { $job = $focus->createJob(); $queue->submitJob($job, $this->getUser()); } } } else { $GLOBALS['log']->debug('----->No Schedulers found'); } }
/** * Create a job queue consumer for mass update * * @param Mixed $data job queue data * @param String $jobType job type - 'init' for parent job, 'work' for child job * @return String id of the created job */ public function createJobQueueConsumer($data, $jobType = "init") { $job = new SchedulersJob(); $job->name = 'MassUpdate_' . $jobType; $job->target = "class::SugarJobMassUpdate"; $data['_jobType_'] = $jobType; $job->data = json_encode($data); $job->assigned_user_id = $GLOBALS['current_user']->id; $queue = new SugarJobQueue(); $queue->submitJob($job); return $job->id; }
/** * Run cleanup and schedule * @param string $session * @param string $clientid */ public function job_queue_cycle($session, $clientid) { $GLOBALS['log']->info('Begin: SugarWebServiceImpl->job_queue_cycle'); $error = new SoapError(); if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', 'read', 'no_access', $error)) { $GLOBALS['log']->info('End: SugarWebServiceImpl->job_queue_cycle denied.'); return; } require_once 'include/SugarQueue/SugarJobQueue.php'; $queue = new SugarJobQueue(); $queue->cleanup(); $queue->runSchedulers(); $GLOBALS['log']->info('End: SugarWebServiceImpl->job_queue_cycle'); return array("results" => "ok"); }
/** * Create the job in the job_queue * * @param $data * @return String */ public static function createJob($data) { global $current_user; //Create an entry in the job queue to run UpdateOppsJob which handles updating all opportunities /* @var $job SchedulersJob */ $job = BeanFactory::getBean('SchedulersJobs'); $job->name = "Resave All RevenueLineItems"; $job->target = "class::SugarJobUpdateRevenueLineItems"; $job->data = json_encode($data); $job->retry_count = 0; $job->assigned_user_id = $current_user->id; require_once 'include/SugarQueue/SugarJobQueue.php'; $job_queue = new SugarJobQueue(); return $job_queue->submitJob($job); }