RecalculateAllOrdersTask   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 21
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 15 4
1
<?php
2
3
namespace SilverShop\Tasks;
4
5
use SilverShop\Model\Order;
6
use SilverStripe\Control\Director;
7
use SilverStripe\Dev\BuildTask;
8
9
/**
10
 * Recalculate All Orders
11
 * Re-runs all calculation functions on all orders so that database is populated with pre-calculated values.
12
 *
13
 * @subpackage tasks
14
 */
15
class RecalculateAllOrdersTask extends BuildTask
16
{
17
    protected $title = 'Recalculate All Orders';
18
19
    protected $description = 'Runs all price calculation functions on all orders.';
20
21
    public function run($request)
22
    {
23
        $br = Director::is_cli() ? "\n" : '<br/>';
24
25
        //TODO: include order total calculation, once that gets written
26
        //TODO: figure out how to make this run faster
27
        //TODO: better memory managment...the destroy calls are not enough it appears.
28
29
        if ($orders = Order::get()) {
30
            echo $br . 'Writing all order items ';
31
            foreach ($orders as $order) {
32
                $order->calculate();
33
                $order->write();
34
            }
35
            echo $br . 'done.' . $br;
36
        }
37
    }
38
}
39