Skip to content

Commit

Permalink
#76 - Refactor batchInsert() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeckerson committed Mar 28, 2020
1 parent dbc07ae commit 0739d36
Show file tree
Hide file tree
Showing 5 changed files with 2,546 additions and 7 deletions.
16 changes: 11 additions & 5 deletions src/Mvc/Model/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -710,23 +710,29 @@ public function batchInsert(string $tableName, $fields)
{
$migrationData = self::$migrationPath . $this->version . '/' . $tableName . '.dat';
if (!file_exists($migrationData)) {
return; // nothing to do
return;
}

self::$connection->begin();
self::$connection->delete($tableName);

$batchHandler = fopen($migrationData, 'r');
while (($line = fgetcsv($batchHandler)) !== false) {
$values = array_map(
function ($value) {
return null === $value ? null : stripslashes($value);
if (null === $value) {
return null;
}

if ($value === 'NULL') {
return null;
}

return stripslashes($value);
},
$line
);

$nullify = new Nullify();
self::$connection->insert($tableName, $nullify($values), $fields);
self::$connection->insert($tableName, $values, $fields);
unset($line);
}

Expand Down
Loading

0 comments on commit 0739d36

Please sign in to comment.