18 require_once SQ_CORE_PACKAGE_PATH.
'/system/cron/cron_job/cron_job.inc';
19 require_once SQ_FUDGE_PATH.
'/db_extras/db_extras.inc';
44 parent::__construct($assetid);
62 require_once SQ_CORE_PACKAGE_PATH.
'/system/system_asset_fns.inc';
64 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
65 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
67 if ($linkid = parent::create($link)) {
68 if (!system_asset_fns_create_cleanup($this)) {
74 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
76 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
79 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
96 return $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($this->
type(),
'name');
127 trigger_localised_error(
'CRON0024', E_USER_WARNING, $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($this->type(),
'name'));
163 $jobs = $this->getBulkmailJobs();
164 if (empty($jobs))
return SQ_CRON_JOB_COMPLETED;
168 $am = $GLOBALS[
'SQ_SYSTEM']->am;
169 $cm = $am->getSystemAsset(
'cron_manager');
170 $bm = $am->getSystemAsset(
'bulkmail_manager');
171 $last_run = $cm->attr(
'last_run');
174 'hourly' => (60 * 60),
175 'daily' => (60 * 60 * 24),
176 'weekly' => (60 * 60 * 24 * 7),
177 'monthly' => (60 * 60 * 24 * 30),
178 'yearly' => (60 * 60 * 24 * 365),
181 foreach ($jobs as $job_id => $schedule) {
182 $frequency = array_get_index(array_keys($schedule), 0);
183 $date_time = $schedule[$frequency];
184 $date_time_ts = strtotime($date_time);
187 if ($date_time_ts > $now)
continue;
191 $queued_jobs = $bm->getQueuedJobs($job_id);
192 if (!empty($queued_jobs))
continue;
194 $bulkmail_job = $am->getAsset($job_id);
195 $last_job_run = $bulkmail_job->attr(
'last_scheduled_run');
197 if (!$last_job_run && $date_time_ts < $now) {
200 $bulkmail_job->processStatusChange(SQ_STATUS_LIVE);
201 $am->acquireLock($bulkmail_job->id,
'all');
202 $bulkmail_job->setAttrValue(
'last_scheduled_run', $now);
203 $bulkmail_job->saveAttributes();
204 $am->releaseLock($bulkmail_job->id,
'all');
212 $next_run_for_bulkmail = $last_job_run + $multiplier[$frequency];
214 if ($next_run_for_bulkmail < $now && $next_run_for_bulkmail > $last_run) {
217 $bulkmail_job->processStatusChange(SQ_STATUS_LIVE);
218 $am->acquireLock($bulkmail_job->id,
'all');
219 $bulkmail_job->setAttrValue(
'last_scheduled_run', $now);
220 $bulkmail_job->saveAttributes();
221 $am->releaseLock($bulkmail_job->id,
'all');
226 return SQ_CRON_JOB_COMPLETED;
231 function getBulkmailJobs()
235 $all_bulkmail_jobs = $GLOBALS[
'SQ_SYSTEM']->am->getTypeAssetids(
'bulkmail_job');
236 foreach ($all_bulkmail_jobs as $job_id) {
237 $bulkmail_job = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($job_id);
239 if (!$bulkmail_job->attr(
'scheduling_status'))
continue;
240 $schedule = $bulkmail_job->attr(
'scheduled_time');
242 if (empty($schedule))
continue;
243 $res[$job_id] = $schedule;
245 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($bulkmail_job, TRUE);
246 unset($bulkmail_job);