forked from dynamic/silverstripe-locator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request dynamic#141 from jsirish/feature/locationVersioning
Location - versioning
- Loading branch information
Showing
5 changed files
with
95 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
/** | ||
* Class LocationPublishTask | ||
*/ | ||
class LocationPublishTask extends BuildTask | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $title = 'Publish all Locations'; | ||
/** | ||
* @var string | ||
*/ | ||
protected $description = 'Migration task - pre versioning on Location'; | ||
/** | ||
* @var bool | ||
*/ | ||
protected $enabled = true; | ||
|
||
/** | ||
* @param $request | ||
*/ | ||
public function run($request) | ||
{ | ||
$class = ($request->getVar('locationclass')) ? $request->getVar('locationclass') : 'Location'; | ||
$this->publishLocations($class); | ||
} | ||
|
||
/** | ||
* @param string $class | ||
* @return Generator | ||
*/ | ||
protected function iterateLocations($class) | ||
{ | ||
foreach ($class::get()->filter('ShowInLocator', true) as $location) { | ||
yield $location; | ||
} | ||
} | ||
|
||
/** | ||
* mark all ProductDetail records as ShowInMenus = 0. | ||
* | ||
* @param string $class | ||
*/ | ||
public function publishLocations($class) | ||
{ | ||
if (!isset($class) || !class_exists($class) || !$class instanceof Location) $class = 'Location'; | ||
$ct = 0; | ||
$publish = function ($location) use (&$ct) { | ||
if (!$location->isPublished()) { | ||
$title = $location->Title; | ||
$location->writeToStage('Stage'); | ||
$location->publish('Stage', 'Live'); | ||
static::write_message($title); | ||
++$ct; | ||
} | ||
}; | ||
|
||
foreach ($this->iterateLocations($class) as $location) { | ||
$publish($location); | ||
} | ||
|
||
static::write_message("{$ct} locations updated."); | ||
} | ||
|
||
/** | ||
* @param $message | ||
*/ | ||
protected static function write_message($message) | ||
{ | ||
if (Director::is_cli()) { | ||
echo "{$message}\n"; | ||
} else { | ||
echo "{$message}<br><br>"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters