Completed
Push — master ( 59c799...149ad0 )
by Will
02:15
created

code/extensions/ElementPublishChildren.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * @package elemental
5
 */
6
class ElementPublishChildren extends DataExtension
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...
7
{
8
9
    public function onBeforeVersionedPublish()
10
    {
11
        $staged = array();
12
13
        foreach ($this->owner->Elements() as $widget) {
14
            $staged[] = $widget->ID;
15
16
            $widget->publish('Stage', 'Live');
17
        }
18
19
        if($this->owner->ID) {
20
21
            // remove any elements that are on live but not in draft.
22
            $widgets = Versioned::get_by_stage('BaseElement', 'Live', sprintf(
23
                "ListID = '%s'", $this->owner->ID
24
            ));
25
26
            foreach ($widgets as $widget) {
27
                if (!in_array($widget->ID, $staged)) {
28
                    $widget->deleteFromStage('Live');
29
                }
30
            }
31
        }
32
    }
33
}
34