Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Location - versioning #141

Merged
merged 4 commits into from
Feb 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions code/objects/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ class Location extends DataObject implements PermissionProvider
'Phone',
'Email',
'Category.ID',
'ShowInLocator',
'Featured',
);

Expand All @@ -106,11 +105,17 @@ class Location extends DataObject implements PermissionProvider
'Postcode',
'Country',
'Category.Name',
'ShowInLocator.NiceAsBoolean',
'Featured.NiceAsBoolean',
'Coords',
);

/**
* @var array
*/
private static $extensions = [
'VersionedDataObject',
];

/**
* Coords status for $summary_fields
*
Expand Down Expand Up @@ -164,8 +169,6 @@ public function getCMSFields()
->setAttribute('placeholder', 'http://'),
DropdownField::create('CategoryID', 'Category', LocationCategory::get()->map('ID', 'Title'))
->setEmptyString('-- select --'),
CheckboxField::create('ShowInLocator', 'Show in results')
->setDescription('Location will be included in results list'),
CheckboxField::create('Featured')
->setDescription('Location will show at/near the top of the results list')
)
Expand All @@ -175,13 +178,14 @@ public function getCMSFields()
// allow to be extended via DataExtension
$this->extend('updateCMSFields', $fields);

$fields->removeByName([
'ShowInLocator',
'Import_ID',
]);

// override Suburb field name
$fields->dataFieldByName('Suburb')->setTitle('City');

$fields->removeByName(array(
'Import_ID',
));

return $fields;
}

Expand Down
4 changes: 1 addition & 3 deletions code/pages/Locator.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ class Locator_Controller extends Page_Controller
/**
* @var array
*/
private static $base_filter = [
'ShowInLocator' => true,
];
private static $base_filter = [];

/**
* @var array
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
"silverstripe/framework": "^3.4",
"silverstripe/cms": "^3.4",
"silverstripe-australia/addressable": "^1.1",
"heyday/silverstripe-versioneddataobjects": "^1.4",
"unclecheese/betterbuttons": "^1.3",
"muskie9/data-to-arraylist": "^1.0",
"silverstripe-australia/gridfieldextensions": "^1.2"
},
"suggest": {
"unclecheese/betterbuttons": "Adds new form actions and buttons to GridField detail form for usability enhancements.",
"unclecheese/bootstrap-forms": "Allows the creation of forms compatible with the Twitter Bootstrap CSS framework in SilverStripe."
},
"extra": {
Expand Down
78 changes: 78 additions & 0 deletions tasks/LocationPublishTask.php
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>";
}
}
}
2 changes: 2 additions & 0 deletions tests/LocationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public function testFieldLabels()
'Coords' => 'Coords',
'Import_ID' => 'Import_ID',
'LatLngOverride' => 'Lat Lng Override',
'Version' => 'Version',
'Versions' => 'Versions'
);
$this->assertEquals($expected, $labels);
}
Expand Down