Completed
Push — master ( 5cca73...7a2a08 )
by John
10s
created

BaseElementExtension::doUnpublish()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.0534
c 0
b 0
f 0
cc 4
eloc 12
nc 3
nop 0
1
<?php
2
3
use \Heyday\VersionedDataObjects\VersionedDataObject;
4
5
/**
6
 * @package elemental
7
 */
8
class BaseElementExtension extends VersionedDataObject
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
{
10
    /**
11
     * {@inheritDoc}
12
     */
13
    public function canView($member = null)
14
    {
15
        return (Permission::check('CMS_ACCESS_CMSMain', 'any', $member)) ? true : null;
16
    }
17
18
    /**
19
     * {@inheritDoc}
20
     */
21
    public function canEdit($member = null)
22
    {
23
        return (Permission::check('CMS_ACCESS_CMSMain', 'any', $member)) ? true : null;
24
    }
25
26
    /**
27
     * {@inheritDoc}
28
     */
29
    public function canDelete($member = null)
30
    {
31
        return (Permission::check('CMS_ACCESS_CMSMain', 'any', $member)) ? true : null;
32
    }
33
34
    /**
35
     * {@inheritDoc}
36
     */
37
    public function canCreate($member = null)
38
    {
39
        return (Permission::check('CMS_ACCESS_CMSMain', 'any', $member)) ? true : null;
40
    }
41
42
    /**
43
     * Handles unpublishing as VersionedDataObjects doesn't
44
     * Modelled on SiteTree::doUnpublish
45
     *
46
     */
47
    public function doUnpublish() {
48
        if(!$this->owner->ID) return false;
49
50
        $this->owner->extend('onBeforeUnpublish');
51
52
        $origStage = Versioned::get_reading_mode();
53
        Versioned::set_reading_mode('Stage.Live');
54
55
        // This way our ID won't be unset
56
        $clone = clone $this->owner;
57
        $clone->delete();
58
59
        Versioned::set_reading_mode($origStage);
60
61
        $virtualLinkedElements = $this->owner->getPublishedVirtualLinkedElements();
62
        if ($virtualLinkedElements) foreach($virtualLinkedElements as $vle) $vle->doUnpublish();
63
64
        $this->owner->extend('onAfterUnpublish');
65
66
        return true;
67
    }
68
69
}
70