Skip to content

Commit

Permalink
BUGFIX empty category name in csv creates empty category objects (#232)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
muskie9 authored Oct 11, 2022
1 parent 80bcd3f commit a5d1c00
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 31 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions

on:
push:
branches: [ '**' ]
pull_request:
branches: [ '**' ]

name: "CI"

jobs:
tests:
name: "Tests"

runs-on: "ubuntu-latest"

env:
php_extensions: ctype, dom, fileinfo, hash, intl, mbstring, session, simplexml, tokenizer, xml, pdo, mysqli, gd, zip

services:
mysql:
image: "mysql:5.7"
env:
MYSQL_ALLOW_EMPTY_PASSWORD: true
MYSQL_ROOT_PASSWORD:
MYSQL_DATABASE: test_db
ports:
- 3306/tcp
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

strategy:
fail-fast: false
matrix:
php-version:
- "7.3"
- "7.4"

steps:
- name: "Checkout"
uses: "actions/checkout@v2"

- name: "Install PHP with extensions"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
extensions: "${{ env.php_extensions }}"
coverage: "xdebug"

- name: "Start mysql service"
run: "sudo /etc/init.d/mysql start"

- name: "Cache dependencies installed with composer"
uses: "actions/cache@v1"
with:
path: "~/.composer/cache"
key: "php${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('**/composer.json') }}"
restore-keys: "php${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-"

- name: "Install dependencies with composer"
run: "composer install --no-ansi --no-interaction --no-progress"

- name: "Run tests with phpunit/phpunit"
env:
SS_DATABASE_PORT: ${{ job.services.mysql.ports['3306'] }}
run: "vendor/bin/phpunit --coverage-clover=coverage.xml"

- name: "Upload coverage results to CodeCov"
uses: codecov/codecov-action@v1
with:
files: ./coverage.xml # optional
flags: unittests # optional

- name: "Run tests with squizlabs/php_codesniffer"
run: "vendor/bin/phpcs -s --report=summary --standard=phpcs.xml.dist --extensions=php,inc --ignore=autoload.php --ignore=vendor/ src/ tests/"
37 changes: 12 additions & 25 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,19 @@
"colymba/gridfield-bulk-editing-tools": "^3.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"squizlabs/php_codesniffer": "^3.0",
"phpmd/phpmd": "^2.6",
"sebastian/phpcpd": "^3.0",
"phploc/phploc": "^4.0",
"pdepend/pdepend": "^2.5",
"theseer/phpdox": "^0.11.0"
"phpunit/phpunit": "^5.7",
"squizlabs/php_codesniffer": "^3.0",
"phpmd/phpmd": "^2.6"
},
"config": {
"process-timeout": 600
"config": {
"allow-plugins": {
"composer/installers": true,
"silverstripe/recipe-plugin": true,
"silverstripe/vendor-plugin": true
},
"autoload": {
"process-timeout": 600
},
"autoload": {
"psr-4": {
"Dynamic\\Locator\\": "src/",
"Dynamic\\Locator\\Tests\\": "tests/"
Expand All @@ -55,20 +56,6 @@
],
"branch-alias": {
"dev-master": "4.x-dev"
},
"project-files-installed": [
"app/.htaccess",
"app/_config.php",
"app/_config/mysite.yml",
"app/src/Page.php",
"app/src/PageController.php"
],
"public-files-installed": [
".htaccess",
"index.php",
"install-frameworkmissing.html",
"install.php",
"web.config"
]
}
}
}
17 changes: 11 additions & 6 deletions src/bulkloader/LocationCsvBulkLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ class LocationCsvBulkLoader extends CsvBulkLoader
/**
* @var array
*/
public $columnMap = array(
public $columnMap = [
'Name' => 'Title',
'EmailAddress' => 'Email',
'Categories' => '->getCategoryByName',
'Import_ID' => 'Import_ID',
'Country' => '->getCountryByName',
);
];

/**
* @var array
*/
public $duplicateChecks = array(
'Import_ID' => 'Import_ID'
);
public $duplicateChecks = [
'Import_ID' => 'Import_ID',
];

/**
* @param $val
Expand All @@ -49,10 +49,15 @@ public function getEscape($val)
public static function getCategoryByName(&$obj, $val, $record)
{
$val = Convert::raw2sql($val);

if ($val == '') {
return;
}

$parts = explode(', ', $val);

foreach ($parts as $part) {
$category = LocationCategory::get()->filter(array('Name' => $part))->first();
$category = LocationCategory::get()->filter(['Name' => $part])->first();
if (!$category) {
$category = LocationCategory::create();
$category->Name = $part;
Expand Down

0 comments on commit a5d1c00

Please sign in to comment.