Skip to content

Commit

Permalink
Location - versioning
Browse files Browse the repository at this point in the history
closes #140
  • Loading branch information
jsirish committed Feb 10, 2017
1 parent 2694c42 commit a244592
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 11 deletions.
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
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"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"
},
"suggest": {
Expand Down
42 changes: 42 additions & 0 deletions tasks/LocationPublishTask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

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)
{
$this->publishLocations();
}
/**
* mark all ProductDetail records as ShowInMenus = 0.
*/
public function publishLocations()
{
$locations = Location::get();
$ct = 0;
foreach ($locations as $location) {
if ($location->ShowInLocator == 1 && !$location->isPublished()) {
$title = $location->Title;
$location->writeToStage('Stage');
$location->publish('Stage', 'Live');
echo $title.'<br><br>';
++$ct;
}
}
echo '<p>'.$ct.' locations updated.</p>';
}
}
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

0 comments on commit a244592

Please sign in to comment.