private function update_sync_cron_events() { $count = ExternalCalendarUsers::count(); $events = CronEvents::findAll(array('conditions' => "name IN ('import_google_calendar','export_google_calendar')")); foreach ($events as $event) { if ($count > 0) { if (!$event->getEnabled()) { $event->setEnabled(true); $event->save(); } } else { if ($event->getEnabled()) { $event->setEnabled(false); $event->save(); } } } }
/** * This function will return paginated result. Result is an array where first element is * array of returned object and second populated pagination object that can be used for * obtaining and rendering pagination data using various helpers. * * Items and pagination array vars are indexed with 0 for items and 1 for pagination * because you can't use associative indexing with list() construct * * @access public * @param array $arguments Query argumens (@see find()) Limit and offset are ignored! * @param integer $items_per_page Number of items per page * @param integer $current_page Current page number * @return array */ function paginate($arguments = null, $items_per_page = 10, $current_page = 1) { if (isset($this) && instance_of($this, 'CronEvents')) { return parent::paginate($arguments, $items_per_page, $current_page); } else { return CronEvents::instance()->paginate($arguments, $items_per_page, $current_page); } // if }
function cron_events() { if (!can_manage_configuration(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } // if $events = CronEvents::getUserEvents(); tpl_assign("events", $events); $cron_events = array_var($_POST, 'cron_events'); if (is_array($cron_events)) { try { DB::beginWork(); foreach ($cron_events as $id => $data) { $event = CronEvents::findById($id); $date = getDateValue($data['date']); if ($date instanceof DateTimeValue) { $this->parseTime($data['time'], $hour, $minute); $date->add("m", $minute); $date->add("h", $hour); $date = new DateTimeValue($date->getTimestamp() - logged_user()->getTimezone() * 3600); $event->setDate($date); } $delay = $data['delay']; if (is_numeric($delay)) { $event->setDelay($delay); } $enabled = array_var($data, 'enabled') == 'checked'; $event->setEnabled($enabled); $event->save(); } DB::commit(); flash_success(lang("success update cron events")); ajx_current("back"); } catch (Exception $ex) { DB::rollback(); flash_error($ex->getMessage()); } } }
static function queueEmail($to, $cc, $bcc, $from, $subject, $body = false, $type = 'text/html', $encoding = '8bit', $attachments = array()) { $cron = CronEvents::getByName('send_notifications_through_cron'); if ($cron instanceof CronEvent && $cron->getEnabled()) { $qm = new QueuedEmail(); // set To if (!is_array($to)) { $to = array($to); } $qm->setTo(implode(";", $to)); // set CC if ($cc != null) { if (!is_array($cc)) { $cc = array($cc); } $qm->setCc(implode(";", $cc)); } // set BCC if ($bcc != null) { if (!is_array($bcc)) { $bcc = array($bcc); } $qm->setBcc(implode(";", $bcc)); } // set from $qm->setFrom($from); // set subject $qm->setSubject($subject); // set body $qm->setBody($body); // set attachments if ($qm->columnExists('attachments')) { $qm->setColumnValue('attachments', json_encode($attachments)); } $qm->save(); } else { // not using cron try { $sent_ok = self::sendEmail($to, $from, $subject, $body, $type, $encoding, $attachments); if ($sent_ok) { // save notification history when notifications are not sent by cron self::saveNotificationHistory(array('to' => $to, 'cc' => $cc, 'bcc' => $bcc, 'from' => $from, 'subject' => $subject, 'body' => $body, 'attachments' => json_encode($attachments), 'timestamp' => DateTimeValueLib::now()->toMySQL())); } } catch (Exception $e) { // save log in server if (defined('EMAIL_ERRORS_LOGDIR') && file_exists(EMAIL_ERRORS_LOGDIR) && is_dir(EMAIL_ERRORS_LOGDIR)) { $err_msg = ROOT_URL . "\nError sending notification (subject={$subject}) using account {$from}\n\nError detail:\n" . $e->getMessage() . "\n" . $e->getTraceAsString(); file_put_contents(EMAIL_ERRORS_LOGDIR . basename(ROOT), $err_msg, FILE_APPEND); } } } }
/** * Return manager instance * * @access protected * @param void * @return CronEvents */ function manager() { if (!$this->manager instanceof CronEvents) { $this->manager = CronEvents::instance(); } return $this->manager; }
include "init.php"; include APPLICATION_PATH . "/cron_functions.php"; header("Content-type: text/plain"); $type = array_var($_GET, "type"); session_commit(); // we don't need sessions @set_time_limit(0); // don't limit execution of cron, if possible $fast_functions = array( "send_reminders" => 1, "send_password_expiration_reminders" => 1, "send_notifications_through_cron"=> 1 ); $events = CronEvents::getDueEvents(); foreach ($events as $event) { if ($event->getEnabled()) { $function = $event->getName(); if ( $type=="fast" && array_var($fast_functions, $function) || $type=="slow" && !array_var($fast_functions, $function) || !$type ) { $errordate = DateTimeValueLib::now()->add("m", 30); /* setting this date allows to rerun the event in 30 minutes if a fatal error occurs during its execution, which would prevent the event from being rescheduled */ $event->setDate($errordate); $event->save(); $function = $event->getName();
static function queueEmail($to, $from, $subject, $body = false, $type = 'text/html', $encoding = '8bit', $attachments = array()) { $cron = CronEvents::getByName('send_notifications_through_cron'); if ($cron instanceof CronEvent && $cron->getEnabled()) { $qm = new QueuedEmail(); if (!is_array($to)) { $to = array($to); } $qm->setTo(implode(";", $to)); $qm->setFrom($from); $qm->setSubject($subject); $qm->setBody($body); if ($qm->columnExists('attachments')) $qm->setColumnValue('attachments', json_encode($attachments)); $qm->save(); } else { self::sendEmail($to, $from, $subject, $body, $type, $encoding, $attachments); } }
/** * Return manager instance * * @access protected * @param void * @return CronEvents */ function manager() { if(!($this->manager instanceof CronEvents)) $this->manager = CronEvents::instance(); return $this->manager; } // manager