Completed
Pull Request — development (#2329)
by Joshua
09:15
created

action_reducemailqueue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6
Metric Value
dl 0
loc 12
ccs 0
cts 8
cp 0
rs 9.4286
cc 2
eloc 5
nc 2
nop 0
crap 6
1
<?php
2
3
/**
4
 * This handles the execution of scheduled tasks, mail queue scheduling included.
5
 *
6
 * @name      ElkArte Forum
7
 * @copyright ElkArte Forum contributors
8
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause
9
 *
10
 * @version 1.1 dev
11
 *
12
 */
13
14 1
if (!defined('ELK'))
15 1
	die('No access...');
16
17
/**
18
 * This controller class action handlers are automatically called.
19
 * It handles execution of scheduled tasks, mail queue scheduling included.
20
 */
21
class ScheduledTasks_Controller extends Action_Controller
22
{
23
	/**
24
	 * Default method for the class, just forwards to autotask
25
	 *
26
	 * @return bool
27
	 */
28
	public function action_index()
29
	{
30
		return $this->action_autotask();
31
	}
32
33
	/**
34
	 * This method works out what to run
35
	 *
36
	 * What it does:
37
	 *  - It checks if it's time for the next tasks
38
	 *  - Runs next tasks
39
	 *  - Update the database for the next round
40
	 */
41 1
	public function action_autotask()
42
	{
43
		// Include the ScheduledTasks subs worker.
44 1
		require_once(SUBSDIR . '/ScheduledTasks.subs.php');
45
46
		// The mail queue is also called from here.
47 1
		if ($this->_req->getQuery('scheduled') === 'mailq')
48 1
			$this->action_reducemailqueue();
49
		else
50
		{
51 1
			call_integration_include_hook('integrate_autotask_include');
52
53
			// Run tasks based on this time stamp
54 1
			$ts = $this->_req->getQuery('ts', 'intval', 0);
55 1
			processNextTasks($ts);
56
57
			// Get the timestamp stored for the next task, if any.
58 1
			$nextTime = nextTime();
59
60
			// If there was none, update with defaults
61 1
			if ($nextTime === false)
62 1
				updateSettings(array('next_task_time' => time() + 86400));
63
			else
64 1
				updateSettings(array('next_task_time' => $nextTime));
65
		}
66
67
		// Return, if we're not explicitly called.
68
		// @todo remove?
69 1
		if (!isset($this->_req->query->scheduled))
70 1
			return true;
71
72
		// Finally, send some bland image
73
		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
74
		header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
75
		header('Content-Type: image/gif');
76
		die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B");
0 ignored issues
show
Coding Style Compatibility introduced by
The method action_autotask() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
77
	}
78
79
	/**
80
	 * Reduce mail queue.
81
	 */
82
	public function action_reducemailqueue()
83
	{
84
		global $modSettings;
85
86
		// Lets not waste our time or resources.
87
		if (empty($modSettings['mail_queue_use_cron']))
88
		{
89
			// This does the hard work, it does.
90
			require_once(SUBSDIR . '/Mail.subs.php');
91
			reduceMailQueue();
92
		}
93
	}
94
}