Completed
Pull Request — development (#3050)
by John
23:37
created

Remove_Old_Drafts   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 46
ccs 0
cts 27
cp 0
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 38 4
1
<?php
2
3
/**
4
 * Check for old drafts and remove them
5
 *
6
 * @name      ElkArte Forum
7
 * @copyright ElkArte Forum contributors
8
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause
9
 *
10
 * This file contains code covered by:
11
 * copyright:	2011 Simple Machines (http://www.simplemachines.org)
12
 * license:  	BSD, See included LICENSE.TXT for terms and conditions.
13
 *
14
 * @version 2.0 dev
15
 *
16
 */
17
18
namespace ElkArte\sources\subs\ScheduledTask;
19
20
/**
21
 * Class Remove_Old_Drafts - Check for old drafts and remove them
22
 *
23
 * @package ScheduledTasks
24
 */
25
class Remove_Old_Drafts implements Scheduled_Task_Interface
26
{
27
	/**
28
	 * Scheduled task for removing those old and abandoned drafts
29
	 *
30
	 * @return bool
31
	 */
32
	public function run()
33
	{
34
		global $modSettings;
35
36
		$db = database();
37
38
		if (empty($modSettings['drafts_keep_days']))
39
			return true;
40
41
		// init
42
		$drafts = array();
43
44
		// We need this for language items
45
		theme()->getTemplates()->loadEssentialThemeData();
46
47
		// Find all of the old drafts
48
		$request = $db->query('', '
49
			SELECT 
50
				id_draft
51
			FROM {db_prefix}user_drafts
52
			WHERE poster_time <= {int:poster_time_old}',
53
			array(
54
				'poster_time_old' => time() - (86400 * $modSettings['drafts_keep_days']),
55
			)
56
		);
57
		while ($row = $db->fetch_row($request))
58
			$drafts[] = (int) $row[0];
59
		$db->free_result($request);
60
61
		// If we have old one, remove them
62
		if (count($drafts) > 0)
63
		{
64
			require_once(SUBSDIR . '/Drafts.subs.php');
65
			deleteDrafts($drafts, -1, false);
66
		}
67
68
		return true;
69
	}
70
}