i-lateral / silverstripe-slightly-better-bulkloader
It's the SilverStripe bulk loader, but ever so slightly better
Installs: 653
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 5
Forks: 0
Open Issues: 0
Type:silverstripe-vendormodule
Requires
- silverstripe/framework: ~4.0
Requires (Dev)
- league/csv: ^8
- phpunit/phpunit: ^5.7
- silverstripe/versioned: ^1
- squizlabs/php_codesniffer: ^3.0
README
It's the SilverStripe bulk loader, but ever so slightly better!
This module expands the default SS version and adds error logging per import row and attempts to solve issues where Excel sometimes adds blank columns to the end of a CSV (which then fails to import)
Install
Instalation via composer:
# composer require i-lateral/silverstripe-slightly-better-bulkloader
Usage
By default this module should automatically replace BulkLoader_Result
with a custom version
that track errors.
However to make the most of this, you need to also implement your own version of CSVBulkLoader
for example:
ModelAdmin
Adding the Custom CSV uploader via ModelAdmin
namespace App\Admin; use SilverStripe\Admin\ModelAdmin; use ilateral\SilverStripe\SlightlyBetterBulkLoader\CsvBulkLoader; class MyModelAdmin extends ModelAdmin { private static $managed_models = [ MyDataObject::class ]; private static $model_importers = [ MyDataObject::class => CsvBulkLoader::class ]; }
Manualy Called
An example of adding a custom CSV import after a form has been submitted.
use SilverStripe\Forms\Form; use ilateral\SilverStripe\SlightlyBetterBulkLoader\CsvBulkLoader; class MyImportForm extends Form { public function import($data, $form) { $loader = CsvBulkLoader::create(); $results = $loader->load($_FILES['_CsvFile']['tmp_name']); $form->sessionMessage( $results->getMessagesString("</br>"), $results->getMessageType(), ValidationResult::CAST_HTML ); return $this->redirectBack(); } }