@@ -13,94 +13,94 @@ |
||
13 | 13 | class LocationCsvBulkLoader extends CsvBulkLoader |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - public $columnMap = [ |
|
20 | - 'Name' => 'Title', |
|
21 | - 'EmailAddress' => 'Email', |
|
22 | - 'Categories' => '->getCategoryByName', |
|
23 | - 'Import_ID' => 'Import_ID', |
|
24 | - 'Country' => '->getCountryByName', |
|
25 | - ]; |
|
16 | + /** |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + public $columnMap = [ |
|
20 | + 'Name' => 'Title', |
|
21 | + 'EmailAddress' => 'Email', |
|
22 | + 'Categories' => '->getCategoryByName', |
|
23 | + 'Import_ID' => 'Import_ID', |
|
24 | + 'Country' => '->getCountryByName', |
|
25 | + ]; |
|
26 | 26 | |
27 | - /** |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - public $duplicateChecks = [ |
|
31 | - 'Import_ID' => 'Import_ID', |
|
32 | - ]; |
|
27 | + /** |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + public $duplicateChecks = [ |
|
31 | + 'Import_ID' => 'Import_ID', |
|
32 | + ]; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @param $val |
|
36 | - * @return string|string[]|null |
|
37 | - */ |
|
38 | - public function getEscape($val) |
|
39 | - { |
|
40 | - return preg_replace("/\r|\n/", "", $val); |
|
41 | - } |
|
34 | + /** |
|
35 | + * @param $val |
|
36 | + * @return string|string[]|null |
|
37 | + */ |
|
38 | + public function getEscape($val) |
|
39 | + { |
|
40 | + return preg_replace("/\r|\n/", "", $val); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param $obj |
|
45 | - * @param $val |
|
46 | - * @param $record |
|
47 | - * @throws \SilverStripe\ORM\ValidationException |
|
48 | - */ |
|
49 | - public static function getCategoryByName(&$obj, $val, $record) |
|
50 | - { |
|
51 | - $val = Convert::raw2sql($val); |
|
43 | + /** |
|
44 | + * @param $obj |
|
45 | + * @param $val |
|
46 | + * @param $record |
|
47 | + * @throws \SilverStripe\ORM\ValidationException |
|
48 | + */ |
|
49 | + public static function getCategoryByName(&$obj, $val, $record) |
|
50 | + { |
|
51 | + $val = Convert::raw2sql($val); |
|
52 | 52 | |
53 | - if ($val == '') { |
|
54 | - return; |
|
55 | - } |
|
53 | + if ($val == '') { |
|
54 | + return; |
|
55 | + } |
|
56 | 56 | |
57 | - $parts = explode(', ', $val); |
|
57 | + $parts = explode(', ', $val); |
|
58 | 58 | |
59 | - foreach ($parts as $part) { |
|
60 | - $category = LocationCategory::get()->filter(['Name' => $part])->first(); |
|
61 | - if (!$category) { |
|
62 | - $category = LocationCategory::create(); |
|
63 | - $category->Name = $part; |
|
64 | - $category->write(); |
|
65 | - } |
|
66 | - $obj->Categories()->add($category); |
|
67 | - } |
|
68 | - } |
|
59 | + foreach ($parts as $part) { |
|
60 | + $category = LocationCategory::get()->filter(['Name' => $part])->first(); |
|
61 | + if (!$category) { |
|
62 | + $category = LocationCategory::create(); |
|
63 | + $category->Name = $part; |
|
64 | + $category->write(); |
|
65 | + } |
|
66 | + $obj->Categories()->add($category); |
|
67 | + } |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * @param $obj |
|
72 | - * @param $val |
|
73 | - * @param $record |
|
74 | - */ |
|
75 | - public function getCountryByName(&$obj, $val, $record) |
|
76 | - { |
|
77 | - $val = $this->getEscape($val); |
|
78 | - $countries = IntlLocales::singleton()->getCountries(); |
|
70 | + /** |
|
71 | + * @param $obj |
|
72 | + * @param $val |
|
73 | + * @param $record |
|
74 | + */ |
|
75 | + public function getCountryByName(&$obj, $val, $record) |
|
76 | + { |
|
77 | + $val = $this->getEscape($val); |
|
78 | + $countries = IntlLocales::singleton()->getCountries(); |
|
79 | 79 | |
80 | - if (strlen((string)$val) == 2) { |
|
81 | - $val = strtolower($val); |
|
82 | - if (array_key_exists($val, $countries)) { |
|
83 | - $obj->Country = $val; |
|
84 | - } |
|
85 | - } |
|
80 | + if (strlen((string)$val) == 2) { |
|
81 | + $val = strtolower($val); |
|
82 | + if (array_key_exists($val, $countries)) { |
|
83 | + $obj->Country = $val; |
|
84 | + } |
|
85 | + } |
|
86 | 86 | |
87 | - if (in_array($val, $countries)) { |
|
88 | - $obj->Country = array_search($val, $countries); |
|
89 | - } |
|
90 | - } |
|
87 | + if (in_array($val, $countries)) { |
|
88 | + $obj->Country = array_search($val, $countries); |
|
89 | + } |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @param array $record |
|
94 | - * @param array $columnMap |
|
95 | - * @param \SilverStripe\Dev\BulkLoader_Result $results |
|
96 | - * @param bool $preview |
|
97 | - * @return int|void |
|
98 | - */ |
|
99 | - protected function processRecord($record, $columnMap, &$results, $preview = false) |
|
100 | - { |
|
101 | - $objID = parent::processRecord($record, $columnMap, $results, $preview = false); |
|
92 | + /** |
|
93 | + * @param array $record |
|
94 | + * @param array $columnMap |
|
95 | + * @param \SilverStripe\Dev\BulkLoader_Result $results |
|
96 | + * @param bool $preview |
|
97 | + * @return int|void |
|
98 | + */ |
|
99 | + protected function processRecord($record, $columnMap, &$results, $preview = false) |
|
100 | + { |
|
101 | + $objID = parent::processRecord($record, $columnMap, $results, $preview = false); |
|
102 | 102 | |
103 | - $location = Location::get()->byID($objID); |
|
104 | - $location->publishSingle(); |
|
105 | - } |
|
103 | + $location = Location::get()->byID($objID); |
|
104 | + $location->publishSingle(); |
|
105 | + } |
|
106 | 106 | } |