Completed
Pull Request — development (#2979)
by Stephen
08:55
created

Remove_Old_Followups   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 77.78%

Importance

Changes 0
Metric Value
dl 0
loc 42
ccs 14
cts 18
cp 0.7778
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 34 4
1
<?php
2
3
/**
4
 * Check for followups from removed topics and remove them from the table
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 Release Candidate 1
11
 *
12
 */
13
14
namespace ElkArte\sources\subs\ScheduledTask;
15
16
/**
17
 * Check for followups from removed topics and remove them from the table
18
 *
19
 * @package ScheduledTasks
20
 */
21
class Remove_Old_Followups implements Scheduled_Task_Interface
22
{
23
	/**
24
	 * Remove followups that point to removed topics
25
	 *
26
	 * @return bool
27
	 */
28 1
	public function run()
29
	{
30 1
		global $modSettings;
31
32 1
		if (empty($modSettings['enableFollowup']))
33 1
			return false;
34
35 1
		$db = database();
36
37
		// The old FU request :P
38 1
		$request = $db->query('', '
39
			SELECT 
40
				fu.derived_from
41
			FROM {db_prefix}follow_ups AS fu
42
				LEFT JOIN {db_prefix}messages AS m ON (fu.derived_from = m.id_msg)
43
			WHERE m.id_msg IS NULL
44 1
			LIMIT {int:limit}',
45
			array(
46 1
				'limit' => 100,
47
			)
48 1
		);
49 1
		$remove = array();
50 1
		while ($row = $db->fetch_assoc($request))
51
			$remove[] = $row['derived_from'];
52 1
		$db->free_result($request);
53
54 1
		if (empty($remove))
55 1
			return true;
56
57
		require_once(SUBSDIR . '/FollowUps.subs.php');
58
		removeFollowUpsByMessage($remove);
59
60
		return true;
61
	}
62
}