Completed
Pull Request — master (#109)
by Jason
06:12
created

SlideThumbnailNavMigrationTask   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 2
dl 0
loc 57
ccs 0
cts 26
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 4 1
C defaultSliderSettings() 0 32 8
1
<?php
2
3
namespace Dynamic\FlexSlider;
4
5
use SilverStripe\CMS\Model\SiteTree;
6
use SilverStripe\Core\ClassInfo;
7
use SilverStripe\Dev\BuildTask;
8
9
class SlideThumbnailNavMigrationTask extends BuildTask
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $title = 'FlexSlider Default Values';
15
    /**
16
     * @var string
17
     */
18
    protected $description = 'Set default values for slider after the thumbnail nav update';
19
    /**
20
     * @var bool
21
     */
22
    protected $enabled = true;
23
    /**
24
     * @param $request
25
     */
26
    public function run($request)
27
    {
28
        $this->defaultSliderSettings();
29
    }
30
    /**
31
     *
32
     */
33
    public function defaultSliderSettings()
34
    {
35
        $ct = 0;
36
37
        $objects = ClassInfo::subclassesFor('DataObject');
38
        if ($objects) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $objects of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
39
            unset($objects['DataObject']);
40
            foreach ($objects as $object) {
41
                if (singleton($object)->hasExtension('FlexSlider')) {
42
                    foreach ($object::get() as $result) {
43
                        $result->Loop = 1;
44
                        $result->Animate = 1;
45
                        $result->SliderControlNav = 1;
46
                        $result->SliderDirectionNav = 1;
47
                        $result->CarouselControlNav = 0;
48
                        $result->CarouselDirectionNav = 1;
49
                        $result->CarouselThumbnailCt = 6;
50
                        if ($result InstanceOf SiteTree || singleton($object)->hasExtension('VersionedDataobject')) {
51
                            $result->writeToStage('Stage');
52
                            if ($result->isPublished()) {
53
                                $result->publish('Stage', 'Live');
54
                            }
55
                        } else {
56
                            $result->write();
57
                        }
58
                        $ct++;
59
                    }
60
                }
61
            }
62
        }
63
        echo '<p>'.$ct.' Sliders updated.</p>';
64
    }
65
}