From 74915779b03cbdb2f798e45ea15ccb1f4f71567c Mon Sep 17 00:00:00 2001 From: Nic Date: Mon, 24 Sep 2018 13:08:02 -0500 Subject: [PATCH] BUGFIX tasks not compatible with SS4 (#135) fixes #134 --- tasks/SlidePublishTask.php | 14 ++++++++++-- tasks/SlideThumbnailNavMigrationTask.php | 27 ++++++++++++++++++------ 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/tasks/SlidePublishTask.php b/tasks/SlidePublishTask.php index 8551697..03fe7d0 100644 --- a/tasks/SlidePublishTask.php +++ b/tasks/SlidePublishTask.php @@ -35,6 +35,16 @@ public function run($request) $this->publishSlides(); } + /** + * @return \Generator + */ + protected function getSlides() + { + foreach (SlideImage::get() as $slide) { + yield $slide; + } + } + /** * mark all ProductDetail records as ShowInMenus = 0. */ @@ -42,14 +52,14 @@ public function publishSlides() { $slides = SlideImage::get(); $ct = 0; - foreach ($slides as $slide) { + foreach ($this->getSlides() as $slide) { if ($slide->ShowSlide == 1) { if (!$slide->Name) { $slide->Name = "No Name"; } $title = $slide->Name; $slide->writeToStage('Stage'); - $slide->publish('Stage', 'Live'); + $slide->publishRecursive(); static::write_message($slide->Name . " updated"); ++$ct; } diff --git a/tasks/SlideThumbnailNavMigrationTask.php b/tasks/SlideThumbnailNavMigrationTask.php index 385fddd..879af30 100644 --- a/tasks/SlideThumbnailNavMigrationTask.php +++ b/tasks/SlideThumbnailNavMigrationTask.php @@ -2,9 +2,12 @@ namespace Dynamic\flexslider\tasks; +use Dynamic\FlexSlider\ORM\FlexSlider; use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Core\ClassInfo; use SilverStripe\Dev\BuildTask; +use SilverStripe\ORM\DataObject; +use SilverStripe\Versioned\Versioned; /** * Class SlideThumbnailNavMigrationTask @@ -35,6 +38,17 @@ public function run($request) $this->defaultSliderSettings(); } + /** + * @param $class + * @return \Generator + */ + protected function getObjectSet($class) + { + foreach ($class::get() as $object) { + yield $object; + } + } + /** * */ @@ -42,12 +56,13 @@ public function defaultSliderSettings() { $ct = 0; - $objects = ClassInfo::subclassesFor('DataObject'); + $objects = ClassInfo::subclassesFor(DataObject::class); + if ($objects) { - unset($objects['DataObject']); + unset($objects[DataObject::class]); foreach ($objects as $object) { - if (singleton($object)->hasExtension('FlexSlider')) { - foreach ($object::get() as $result) { + if ($object::singleton()->hasExtension(FlexSlider::class)) { + foreach ($this->getObjectSet($object) as $result) { $result->Loop = 1; $result->Animate = 1; $result->SliderControlNav = 1; @@ -55,10 +70,10 @@ public function defaultSliderSettings() $result->CarouselControlNav = 0; $result->CarouselDirectionNav = 1; $result->CarouselThumbnailCt = 6; - if ($result instanceof SiteTree || singleton($object)->hasExtension('VersionedDataobject')) { + if ($result instanceof SiteTree || $object::singleton()->hasExtension(Versioned::class)) { $result->writeToStage('Stage'); if ($result->isPublished()) { - $result->publish('Stage', 'Live'); + $result->publishRecursive(); } } else { $result->write();