Completed
Pull Request — master (#49)
by Nic
09:03
created

DiscountTierTypeTask   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 3 1
A setParentTypes() 0 6 2
1
<?php
2
3
namespace Dynamic\Foxy\Discounts\Task;
4
5
use Dynamic\Foxy\Discounts\Model\DiscountTier;
6
use SilverStripe\Control\HTTPRequest;
7
use SilverStripe\Dev\BuildTask;
8
use SilverStripe\ORM\ValidationException;
9
10
/**
11
 * Class DiscountTierTypeTask
12
 * @package Dynamic\Foxy\Discounts\Task
13
 */
14
class DiscountTierTypeTask extends BuildTask
15
{
16
    /**
17
     * @var string
18
     */
19
    protected $title = "Foxy Discounts - Discount Tier Type Task";
20
21
    /**
22
     * @var string
23
     */
24
    protected $description = "Set the new ParentType field for existing Discount Tier records.";
25
26
    /**
27
     * @var string
28
     */
29
    private static $segment = 'foxy-discounts-discount-tier-type-task';
1 ignored issue
show
introduced by
The private property $segment is not used, and could be removed.
Loading history...
30
31
    /**
32
     * @param HTTPRequest $request
33
     * @throws ValidationException
34
     */
35
    public function run($request)
36
    {
37
        $this->setParentTypes();
38
    }
39
40
    /**
41
     * @throws ValidationException
42
     */
43
    protected function setParentTypes()
44
    {
45
        /** @var DiscountTier $tier */
46
        foreach (DiscountTier::get() as $tier) {
47
            $tier->ParentType = $tier->Discount()->Type;
48
            $tier->write();
49
        }
50
    }
51
}
52