Skip to content

Instantly share code, notes, and snippets.

@muskie9
Created September 21, 2018 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muskie9/afcb4a5075fe7d3f355afed80cbe40a8 to your computer and use it in GitHub Desktop.
Save muskie9/afcb4a5075fe7d3f355afed80cbe40a8 to your computer and use it in GitHub Desktop.
<?php
namespace Foo\Bar\Baz;
use SilverStripe\Dev\BuildTask;
use SilverStripe\ORM\DB;
/**
* Class CountryCodeUpdateTask
* @package Dynamic\Jasna\Tasks
*/
class CountryCodeUpdateTask extends BuildTask
{
/**
* @var string
*/
protected $title = 'Country Code Update Task';
/**
* @var string
*/
private static $segment = 'country-code-update-task';
/**
* Table and Column mapping for updating SS3 country codes to SS4 country codes (lower case)
* [
* 'MyFirstTable' => 'MyColumnName',
* ]
* @var array
*/
private $update_mapping = [
'MyTable' => 'MyCountryColumn',
];
/**
* @param \SilverStripe\Control\HTTPRequest $request
*/
public function run($request)
{
$this->updateCountryCodes();
}
/**
*
*/
protected function updateCountryCodes()
{
foreach ($this->update_mapping as $table => $column) {
$updateQuery = "UPDATE \"{$table}\" SET \"{$column}\" = LOWER(\"{$column}\")";
DB::query($updateQuery);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment