/** * This method implements the run function of RunnableSchedulerJob and handles processing a SchedulersJob * * @param Mixed $data parameter passed in from the job_queue.data column when a SchedulerJob is run * @return bool true on success, false on error */ public function run($data) { $systemInfo = $this->getSystemInfo(); if ($systemInfo->getActiveUsersXDaysCount(3) == 0) { if (!$this->sendHeartbeat($systemInfo->getInfo())) { $this->job->failJob("Unable to send heartbeat"); return false; } } $this->job->succeedJob(); return true; }
/** * @param $data * @return bool */ public function run($data) { $this->job->runnable_ran = true; $this->job->runnable_data = $data; $keys = json_decode(html_entity_decode($data), true); foreach ($keys as $key) { /* @var $opp RevenueLineItem */ $opp = BeanFactory::getBean('RevenueLineItems'); $opp->retrieve($key); $opp->save(false); } $this->job->succeedJob(); return true; }
/** * @param string $data The job data set for this particular Scheduled Job instance * @return boolean true if the run succeeded; false otherwise */ public function run($data) { /* @var $admin Administration */ $admin = BeanFactory::getBean('Administration'); $settings = $admin->getConfigForModule('Forecasts'); if ($settings['is_setup'] == false) { $GLOBALS['log']->fatal("Forecast Module is not setup. " . __CLASS__ . " should not be running"); return false; } $args = json_decode(html_entity_decode($data), true); $this->job->runnable_ran = true; // use the processWorksheetDataChunk to run the code. ForecastWorksheet::processWorksheetDataChunk($args['forecast_by'], $args['data']); $this->job->succeedJob(); return true; }
/** * @param string $data The job data set for this particular Scheduled Job instance * @return boolean true if the run succeeded; false otherwise */ public function run($data) { $settings = Opportunity::getSettings(); if (isset($settings['opps_view_by']) && $settings['opps_view_by'] !== 'RevenueLineItems') { $GLOBALS['log']->fatal("Opportunity are not being used with Revenue Line Items. " . __CLASS__ . " should not be running"); return false; } $args = json_decode(html_entity_decode($data), true); $this->job->runnable_ran = true; // use the processWorksheetDataChunk to run the code. SugarAutoLoader::load('modules/Opportunities/include/OpportunityWithRevenueLineItem.php'); OpportunityWithRevenueLineItem::processOpportunityIds($args['data']); $this->job->succeedJob(); $this->notifyAssignedUser(); return true; }
/** * @param $data * @return bool */ public function run($data) { $this->job->runnable_ran = true; $this->job->runnable_data = $data; $data = json_decode($data, true); Activity::disable(); $ftsInstance = SugarSearchEngineFactory::getInstance(); $ftsInstance->setForceAsyncIndex(true); foreach ($data as $row) { /* @var $opp Opportunity */ $opp = BeanFactory::getBean('Opportunities', $row['id']); $opp->save(false); } $ftsInstance->setForceAsyncIndex(SugarConfig::getInstance()->get('search_engine.force_async_index', false)); Activity::enable(); $this->job->succeedJob(); $this->notifyAssignedUser(); return true; }
/** * @param string $data The job data set for this particular Scheduled Job instance * @return boolean true if the run succeeded; false otherwise */ public function run($data) { $settings = Opportunity::getSettings(); if (isset($settings['opps_view_by']) && $settings['opps_view_by'] !== 'Opportunities') { $GLOBALS['log']->fatal("Opportunity are being used with Revenue Line Items. " . __CLASS__ . " should not be running"); return false; } $args = json_decode(html_entity_decode($data), true); $this->job->runnable_ran = true; $labels = $args['labels']; $data = $args['chunk']; $currencies = array(); Activity::disable(); // disable the fts index as well /* @var $ftsSearch SugarSearchEngineElastic */ $ftsSearch = SugarSearchEngineFactory::getInstance(); $ftsSearch->setForceAsyncIndex(true); foreach ($data as $opp_id => $rli_data) { /* @var $opp Opportunity */ $opp = BeanFactory::getBean('Opportunities', $opp_id); /* @var $note Note */ $note = BeanFactory::getBean('Notes'); $note->parent_id = $opp_id; $note->parent_type = 'Opportunities'; $note->assigned_user_id = $opp->assigned_user_id; $note->created_by = $opp->created_by; $note->name = 'Previous Associated Revenue Line Items'; $desc = ''; foreach ($rli_data as $rli) { $desc .= $rli['name'] . "\n"; foreach ($rli as $field => $value) { if (isset($labels[$field])) { if ($field === 'currency_id') { if (!isset($currencies[$value])) { $currencies[$value] = SugarCurrency::getCurrencyByID($value); } $desc .= " - " . $labels[$field] . ": " . $currencies[$value]->name . "\n"; } elseif ($field !== 'name' && $field !== 'opportunity_id') { $desc .= " - " . $labels[$field] . ": " . $value . "\n"; } } } $desc .= "\n\n"; } $note->description = trim($desc); $note->save(); } // set it back to the default value from the config. $ftsSearch->setForceAsyncIndex(SugarConfig::getInstance()->get('search_engine.force_async_index', false)); Activity::enable(); $this->job->succeedJob(); $this->notifyAssignedUser(); return true; }
public function testsucceedJob() { $schedulersJob = new SchedulersJob(); $result = $schedulersJob->succeedJob(); $this->assertEquals(true, $result); //test for record ID to verify that record is saved $this->assertTrue(isset($schedulersJob->id)); $this->assertEquals(36, strlen($schedulersJob->id)); $this->assertEquals(SchedulersJob::JOB_STATUS_DONE, $schedulersJob->status); $this->assertEquals(SchedulersJob::JOB_SUCCESS, $schedulersJob->resolution); $schedulersJob->mark_deleted($schedulersJob->id); }
/** * @param $data * @return bool */ public function run($data) { $this->job->runnable_ran = true; $maxLifetime = $this->getMaxLifetime(); if (!$maxLifetime) { $this->job->failJob('File max lifetime is not configured'); return false; } $dir = $this->getDirectory(); if (!file_exists($dir)) { $this->job->succeedJob(); return true; } $files = $this->getFilesToRemove($dir, $maxLifetime); $result = $this->removeFiles($files); if ($result) { $this->job->succeedJob(); } else { $this->job->failJob(); } return $result; }
/** * @param $data * @return bool */ public function run($data) { global $current_user; global $current_language; global $locale; $this->job->runnable_ran = true; $this->job->runnable_data = $data; $report_schedule_id = $data; require_once 'modules/Reports/schedule/ReportSchedule.php'; $reportSchedule = new ReportSchedule(); $scheduleInfo = $reportSchedule->getInfo($report_schedule_id); $GLOBALS["log"]->debug("-----> in Reports foreach() loop"); $savedReport = BeanFactory::getBean('Reports', $scheduleInfo['report_id']); $GLOBALS["log"]->debug("-----> Generating Reporter"); require_once 'modules/Reports/Report.php'; $reporter = new Report(from_html($savedReport->content)); $reporter->is_saved_report = true; $reporter->saved_report = $savedReport; $reporter->saved_report_id = $savedReport->id; $mod_strings = return_module_language($current_language, 'Reports'); // prevent invalid report from being processed if (!$reporter->is_definition_valid()) { $invalidFields = $reporter->get_invalid_fields(); $args = array($scheduleInfo['report_id'], implode(', ', $invalidFields)); $message = string_format($mod_strings['ERR_REPORT_INVALID'], $args); $GLOBALS["log"]->fatal("-----> {$message}"); $reportOwner = BeanFactory::retrieveBean('Users', $savedReport->assigned_user_id); if ($reportOwner) { require_once 'modules/Reports/utils.php'; $reportsUtils = new ReportsUtilities(); try { $reportsUtils->sendNotificationOfInvalidReport($reportOwner, $message); } catch (MailerException $me) { //@todo consider logging the error at the very least } } $this->job->failJob('Report field definition is invalid'); return false; } else { $GLOBALS["log"]->debug("-----> Reporter settings attributes"); $reporter->layout_manager->setAttribute("no_sort", 1); $GLOBALS["log"]->debug("-----> Reporter Handling PDF output"); require_once 'modules/Reports/templates/templates_tcpdf.php'; $reportFilename = template_handle_pdf($reporter, false); // get the recipient's data... // first get all email addresses known for this recipient $recipientEmailAddresses = array($current_user->email1, $current_user->email2); $recipientEmailAddresses = array_filter($recipientEmailAddresses); // then retrieve first non-empty email address $recipientEmailAddress = array_shift($recipientEmailAddresses); // get the recipient name that accompanies the email address $recipientName = $locale->formatName($current_user); $result = false; try { $GLOBALS["log"]->debug("-----> Generating Mailer"); $mailer = MailerFactory::getSystemDefaultMailer(); // set the subject of the email $subject = empty($savedReport->name) ? "Report" : $savedReport->name; $mailer->setSubject($subject); // add the recipient $mailer->addRecipientsTo(new EmailIdentity($recipientEmailAddress, $recipientName)); // attach the report, using the subject as the name of the attachment $charsToRemove = array("\r", "\n"); // remove these characters from the attachment name $attachmentName = str_replace($charsToRemove, "", $subject); // replace spaces with the underscores $attachmentName = str_replace(" ", "_", "{$attachmentName}.pdf"); $attachment = new Attachment($reportFilename, $attachmentName, Encoding::Base64, "application/pdf"); $mailer->addAttachment($attachment); // set the body of the email $body = $mod_strings["LBL_HELLO"]; if ($recipientName != "") { $body .= " {$recipientName}"; } $body .= ",\n\n" . $mod_strings["LBL_SCHEDULED_REPORT_MSG_INTRO"] . $savedReport->date_entered . $mod_strings["LBL_SCHEDULED_REPORT_MSG_BODY1"] . $savedReport->name . $mod_strings["LBL_SCHEDULED_REPORT_MSG_BODY2"]; $textOnly = EmailFormatter::isTextOnly($body); if ($textOnly) { $mailer->setTextBody($body); } else { $textBody = strip_tags(br2nl($body)); // need to create the plain-text part $mailer->setTextBody($textBody); $mailer->setHtmlBody($body); } $GLOBALS["log"]->debug("-----> Sending PDF via Email to [ {$recipientEmailAddress} ]"); $mailer->send(); $result = true; $GLOBALS["log"]->debug("-----> Send successful"); $reportSchedule->update_next_run_time($report_schedule_id, $scheduleInfo["next_run"], $scheduleInfo["time_interval"]); } catch (MailerException $me) { switch ($me->getCode()) { case MailerException::InvalidEmailAddress: $GLOBALS["log"]->info("No email address for {$recipientName}"); break; default: $GLOBALS["log"]->fatal("Mail error: " . $me->getMessage()); break; } } $GLOBALS["log"]->debug("-----> Removing temporary PDF file"); unlink($reportFilename); if ($result) { $this->job->succeedJob(); } return $result; } }