Completed
Pull Request — development (#3050)
by John
23:37
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 0%

Importance

Changes 0
Metric Value
dl 0
loc 42
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 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 2.0 dev
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
	public function run()
29
	{
30
		global $modSettings;
31
32
		if (empty($modSettings['enableFollowup']))
33
			return false;
34
35
		$db = database();
36
37
		// The old FU request :P
38
		$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
			LIMIT {int:limit}',
45
			array(
46
				'limit' => 100,
47
			)
48
		);
49
		$remove = array();
50
		while ($row = $db->fetch_assoc($request))
51
			$remove[] = $row['derived_from'];
52
		$db->free_result($request);
53
54
		if (empty($remove))
55
			return true;
56
57
		require_once(SUBSDIR . '/FollowUps.subs.php');
58
		removeFollowUpsByMessage($remove);
59
60
		return true;
61
	}
62
}