Skip to content

Commit c388635

Browse files
committed
Update readme, log missing/unreadable import file
1 parent 75ab4a7 commit c388635

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

readme.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ Require this package in your composer.json and run composer update (or run `comp
1515

1616
### Usage
1717

18+
Your CSV's header row should match the DB columns you wish to import. IE to import *id* and *name* columns, your CSV should look like:
19+
20+
id,name
21+
1,Foo
22+
2,Bar
23+
1824
Seed classes must extend `Flynsarmy\CsvSeeder\CsvSeeder`, they must define the destination database table and CSV file path, and finally they must call `parent::run()` like so:
1925

2026
use Flynsarmy\CsvSeeder\CsvSeeder;
@@ -23,8 +29,8 @@ Seed classes must extend `Flynsarmy\CsvSeeder\CsvSeeder`, they must define the d
2329

2430
public function __construct()
2531
{
26-
$this->table = 'gtfs_stops';
27-
$this->filename = app_path().'/database/seeds/csvs/stops.txt';
32+
$this->table = 'your_table';
33+
$this->filename = base_path().'/database/seeds/csvs/your_csv.csv';
2834
}
2935

3036
public function run()
@@ -39,6 +45,8 @@ Seed classes must extend `Flynsarmy\CsvSeeder\CsvSeeder`, they must define the d
3945
}
4046
}
4147

48+
Drop your CSV into */database/seeds/csvs/your_csv.csv* or whatever path you specify in your constructor above.
49+
4250
### Configuration
4351

4452
In addition to setting the database table and CSV filename, two other configuration options are available. They can be set in your class constructor:
@@ -47,6 +55,15 @@ In addition to setting the database table and CSV filename, two other configurat
4755
- `csv_delimiter` (string ,) The CSV field delimiter.
4856
- `hashable` (string password) Hash the hashable field, useful if you are importing users and need their passwords hashed. Uses `Hash::make()`
4957

58+
For example if you have a CSV with pipe delimited values, your constructor seed constructor will look like so:
59+
60+
public function __construct()
61+
{
62+
$this->table = 'your_table';
63+
$this->csv_delimiter = '|';
64+
$this->filename = base_path().'/database/seeds/csvs/your_csv.csv';
65+
}
66+
5067
### License
5168

5269
CsvSeeder is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

src/Flynsarmy/CsvSeeder/CsvSeeder.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ private function strip_utf8_bom( $text )
8686
private function seedFromCSV($filename, $deliminator = ",")
8787
{
8888
if ( !file_exists($filename) || !is_readable($filename) )
89+
{
90+
Log::error("CSV insert failed: CSV " . $filename . " does not exist or is not readable.");
8991
return FALSE;
92+
}
9093

9194
$header = NULL;
9295
$row_count = 0;

0 commit comments

Comments
 (0)