| Conditions | 5 |
| Paths | 8 |
| Total Lines | 24 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 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 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.