Created
September 21, 2018 15:34
-
-
Save muskie9/afcb4a5075fe7d3f355afed80cbe40a8 to your computer and use it in GitHub Desktop.
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
<?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