Skip to content

Commit a5d1c00

Browse files
authored
BUGFIX empty category name in csv creates empty category objects (#232)
* BUGFIX empty category name in csv creates empty category objects * BUGFIX empty category name in csv creates empty category objects * UPDATE workflows ci config * UPDATE remove various “extra” declarations from composer * UPDATE allowed-plugins
1 parent 80bcd3f commit a5d1c00

File tree

3 files changed

+97
-31
lines changed

3 files changed

+97
-31
lines changed

.github/workflows/ci.yml

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions
2+
3+
on:
4+
push:
5+
branches: [ '**' ]
6+
pull_request:
7+
branches: [ '**' ]
8+
9+
name: "CI"
10+
11+
jobs:
12+
tests:
13+
name: "Tests"
14+
15+
runs-on: "ubuntu-latest"
16+
17+
env:
18+
php_extensions: ctype, dom, fileinfo, hash, intl, mbstring, session, simplexml, tokenizer, xml, pdo, mysqli, gd, zip
19+
20+
services:
21+
mysql:
22+
image: "mysql:5.7"
23+
env:
24+
MYSQL_ALLOW_EMPTY_PASSWORD: true
25+
MYSQL_ROOT_PASSWORD:
26+
MYSQL_DATABASE: test_db
27+
ports:
28+
- 3306/tcp
29+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
30+
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
php-version:
35+
- "7.3"
36+
- "7.4"
37+
38+
steps:
39+
- name: "Checkout"
40+
uses: "actions/checkout@v2"
41+
42+
- name: "Install PHP with extensions"
43+
uses: "shivammathur/setup-php@v2"
44+
with:
45+
php-version: "${{ matrix.php-version }}"
46+
extensions: "${{ env.php_extensions }}"
47+
coverage: "xdebug"
48+
49+
- name: "Start mysql service"
50+
run: "sudo /etc/init.d/mysql start"
51+
52+
- name: "Cache dependencies installed with composer"
53+
uses: "actions/cache@v1"
54+
with:
55+
path: "~/.composer/cache"
56+
key: "php${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('**/composer.json') }}"
57+
restore-keys: "php${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-"
58+
59+
- name: "Install dependencies with composer"
60+
run: "composer install --no-ansi --no-interaction --no-progress"
61+
62+
- name: "Run tests with phpunit/phpunit"
63+
env:
64+
SS_DATABASE_PORT: ${{ job.services.mysql.ports['3306'] }}
65+
run: "vendor/bin/phpunit --coverage-clover=coverage.xml"
66+
67+
- name: "Upload coverage results to CodeCov"
68+
uses: codecov/codecov-action@v1
69+
with:
70+
files: ./coverage.xml # optional
71+
flags: unittests # optional
72+
73+
- name: "Run tests with squizlabs/php_codesniffer"
74+
run: "vendor/bin/phpcs -s --report=summary --standard=phpcs.xml.dist --extensions=php,inc --ignore=autoload.php --ignore=vendor/ src/ tests/"

composer.json

+12-25
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,19 @@
2828
"colymba/gridfield-bulk-editing-tools": "^3.0"
2929
},
3030
"require-dev": {
31-
"phpunit/phpunit": "^5.7",
32-
"squizlabs/php_codesniffer": "^3.0",
33-
"phpmd/phpmd": "^2.6",
34-
"sebastian/phpcpd": "^3.0",
35-
"phploc/phploc": "^4.0",
36-
"pdepend/pdepend": "^2.5",
37-
"theseer/phpdox": "^0.11.0"
31+
"phpunit/phpunit": "^5.7",
32+
"squizlabs/php_codesniffer": "^3.0",
33+
"phpmd/phpmd": "^2.6"
3834
},
39-
"config": {
40-
"process-timeout": 600
35+
"config": {
36+
"allow-plugins": {
37+
"composer/installers": true,
38+
"silverstripe/recipe-plugin": true,
39+
"silverstripe/vendor-plugin": true
4140
},
42-
"autoload": {
41+
"process-timeout": 600
42+
},
43+
"autoload": {
4344
"psr-4": {
4445
"Dynamic\\Locator\\": "src/",
4546
"Dynamic\\Locator\\Tests\\": "tests/"
@@ -55,20 +56,6 @@
5556
],
5657
"branch-alias": {
5758
"dev-master": "4.x-dev"
58-
},
59-
"project-files-installed": [
60-
"app/.htaccess",
61-
"app/_config.php",
62-
"app/_config/mysite.yml",
63-
"app/src/Page.php",
64-
"app/src/PageController.php"
65-
],
66-
"public-files-installed": [
67-
".htaccess",
68-
"index.php",
69-
"install-frameworkmissing.html",
70-
"install.php",
71-
"web.config"
72-
]
59+
}
7360
}
7461
}

src/bulkloader/LocationCsvBulkLoader.php

+11-6
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@ class LocationCsvBulkLoader extends CsvBulkLoader
1616
/**
1717
* @var array
1818
*/
19-
public $columnMap = array(
19+
public $columnMap = [
2020
'Name' => 'Title',
2121
'EmailAddress' => 'Email',
2222
'Categories' => '->getCategoryByName',
2323
'Import_ID' => 'Import_ID',
2424
'Country' => '->getCountryByName',
25-
);
25+
];
2626

2727
/**
2828
* @var array
2929
*/
30-
public $duplicateChecks = array(
31-
'Import_ID' => 'Import_ID'
32-
);
30+
public $duplicateChecks = [
31+
'Import_ID' => 'Import_ID',
32+
];
3333

3434
/**
3535
* @param $val
@@ -49,10 +49,15 @@ public function getEscape($val)
4949
public static function getCategoryByName(&$obj, $val, $record)
5050
{
5151
$val = Convert::raw2sql($val);
52+
53+
if ($val == '') {
54+
return;
55+
}
56+
5257
$parts = explode(', ', $val);
5358

5459
foreach ($parts as $part) {
55-
$category = LocationCategory::get()->filter(array('Name' => $part))->first();
60+
$category = LocationCategory::get()->filter(['Name' => $part])->first();
5661
if (!$category) {
5762
$category = LocationCategory::create();
5863
$category->Name = $part;

0 commit comments

Comments
 (0)