Passed
Pull Request — master (#405)
by Nic
10:54
created

ClearPasswordLogTask   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 8
c 1
b 0
f 0
dl 0
loc 37
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A resetLog() 0 4 2
A run() 0 3 1
A getLogs() 0 4 2
1
<?php
2
3
namespace Dynamic\FoxyStripe\Tasks;
4
5
use SilverStripe\Dev\BuildTask;
6
use SilverStripe\ORM\DB;
7
8
/**
9
 * Class ClearPasswordLogTask
10
 * @package Dynamic\FoxyStripe\Tasks
11
 */
12
class ClearPasswordLogTask extends BuildTask
13
{
14
    /**
15
     * @var string
16
     */
17
    protected $title = 'Foxy - Clear Password Log Task';
18
19
    /**
20
     * @var string
21
     */
22
    private static $segment = 'foxy-clear-password-log-task';
0 ignored issues
show
introduced by
The private property $segment is not used, and could be removed.
Loading history...
23
24
    /**
25
     * @param \SilverStripe\Control\HTTPRequest $request
26
     */
27
    public function run($request)
28
    {
29
        $this->resetLog();
30
    }
31
32
    /**
33
     *
34
     */
35
    protected function resetLog()
36
    {
37
        foreach ($this->getLogs() as $log) {
38
            DB::prepared_query("DELETE FROM `MemberPassword` WHERE `ID` = ?", [$log['ID']]);
39
        }
40
    }
41
42
    /**
43
     * @return \Generator
44
     */
45
    protected function getLogs()
46
    {
47
        foreach (DB::query("Select * FROM `MemberPassword`") as $passwordLog) {
48
            yield $passwordLog;
49
        }
50
    }
51
}
52