Skip to content

Commit 12bc2ea

Browse files
committed
Fixed out of sync and duplication error
Fixed the scenarios where the chunking can cause an out of sync insert with the left over and also duplication creation.
1 parent ad3c89f commit 12bc2ea

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)