QueuePruner   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 45
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setDoctrine() 0 4 1
A run() 0 15 1
A all() 0 7 1
1
<?php
2
3
namespace Glooby\TaskBundle\Queue;
4
5
use Doctrine\Common\Persistence\ManagerRegistry;
6
use Doctrine\DBAL\Connection;
7
use Glooby\TaskBundle\Annotation\Schedule;
8
use Glooby\TaskBundle\Task\TaskInterface;
9
10
/**
11
 * This task is used to test that the whole scheduling chain works.
12
 *
13
 * @Schedule("@daily")
14
 *
15
 * @author Emil Kilhage
16
 */
17
class QueuePruner implements TaskInterface
18
{
19
    /**
20
     * @var ManagerRegistry
21
     */
22
    protected $doctrine;
23
24
    /**
25
     * @param ManagerRegistry $doctrine
26
     */
27
    public function setDoctrine($doctrine)
28
    {
29
        $this->doctrine = $doctrine;
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function run(array $params = [])
36
    {
37
        /** @var Connection $connection */
38
        $connection = $this->doctrine->getConnection();
39
40
        $deleted = $connection->exec('DELETE FROM task_queue
41
            WHERE resolution = "success"
42
              AND created <= DATE_SUB(NOW(), INTERVAL 1 MONTH)');
43
44
        $deleted += $connection->exec('DELETE FROM task_queue
45
            WHERE resolution != "success"
46
              AND created <= DATE_SUB(NOW(), INTERVAL 3 MONTH)');
47
48
        return sprintf('%d deleted', $deleted);
49
    }
50
51
    /**
52
     *
53
     */
54
    public function all()
55
    {
56
        /** @var Connection $connection */
57
        $connection = $this->doctrine->getConnection();
58
        $deleted = $connection->exec('DELETE FROM task_queue');
59
        return sprintf('%d deleted', $deleted);
60
    }
61
}
62