MigrateOrderMinMaxTask   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 2
dl 0
loc 35
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 23 9
1
<?php
2
/**
3
 * PreviewTicketTask.php
4
 *
5
 * @author Bram de Leeuw
6
 * Date: 27/03/17
7
 */
8
9
namespace Broarm\EventTickets;
10
11
use BuildTask;
12
use Director;
13
use Guzzle\Common\Event;
14
15
/**
16
 * Class MigrateOrderMinMaxTask
17
 * Migrate the min and max field data from the Event to the ticket
18
 *
19
 * @package Broarm\EventTickets
20
 */
21
class MigrateOrderMinMaxTask extends BuildTask
22
{
23
    protected $title = 'Migrate the order min and max';
24
25
    protected $description = 'Migrate the order min and max field data from the Event to the ticket';
26
27
    protected $enabled = true;
28
29
    /**
30
     * @param \SS_HTTPRequest $request
31
     */
32
    public function run($request)
33
    {
34
        if (!Director::is_cli()) echo '<pre>';
35
        echo "Start migrating the order min and max\n\n";
36
37
        /** @var \CalendarEvent|TicketExtension $event */
38
        foreach (\CalendarEvent::get() as $event) {
39
            if (($tickets = $event->Tickets()) && $tickets->exists()) {
40
                $max = $event->OrderMax;
41
                $min = $event->OrderMin;
42
                /** @var Ticket $ticket */
43
                foreach ($tickets as $ticket) {
44
                    if (empty($ticket->OrderMax)) $ticket->OrderMax = $max;
45
                    if (empty($ticket->OrderMin)) $ticket->OrderMin = $min;
46
                    $ticket->write();
47
                    echo "[$event->Title] Set order min on ticket {$ticket->Title} to [$min] and max to [$max] \n";
48
                }
49
            }
50
        }
51
52
        echo "\n\nDone migration";
53
        if (!Director::is_cli()) echo '</pre>';
54
    }
55
}
56