Skip to content

Commit b8ef1b3

Browse files
committed
Merge pull request #5 from slakbal/patch-2
Fixed out of sync and duplication error
2 parents ad3c89f + 12bc2ea commit b8ef1b3

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/Flynsarmy/CsvSeeder/CsvSeeder.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,15 @@ private function seedFromCSV($filename, $deliminator = ",")
125125
{
126126
$this->run_insert($data);
127127
$row_count = 0;
128+
//clear the data array explicitly when it was inserted so that nothing is left, otherwise a leftover scenario can cause duplicate inserts
129+
$data = array();
128130
}
129131
}
130132
}
131133

132134
// Insert any leftover rows
133-
if ( $row_count )
135+
//check if the data array explicitly if there are any values left to be inserted, if insert them
136+
if ( count($data) > 0 )
134137
$this->run_insert($data);
135138

136139
fclose($handle);

0 commit comments

Comments
 (0)