$fetched = file_put_contents($dumpFile, $dump); if (!$fetched) { echo "Error storing dump file {$match[2]} in (" . nZEDb_RES . ').' . PHP_EOL; continue; } // Make sure it's readable by all. chmod($dumpFile, 0777); $local = strtolower($argv[2]) == 'local' ? true : false; $verbose = $argv[3] == true ? true : false; if ($verbose) { echo $predb->log->info("Clearing import table"); } // Truncate to clear any old data $predb->executeTruncate(); // Import file into predb_imports $predb->executeLoadData(['fields' => '\\t\\t', 'lines' => '\\r\\n', 'local' => $local, 'path' => $dumpFile]); // Remove any titles where length <=8 if ($verbose === true) { echo $predb->log->info("Deleting any records where title <=8 from Temporary Table"); } $predb->executeDeleteShort(); // Add any groups that do not currently exist $predb->executeAddGroups(); // Fill the group_id $predb->executeUpdateGroupID(); echo $predb->log->info("Inserting records from temporary table into predb table"); $predb->executeInsert(); // Delete the dump. unlink($dumpFile); $progress = $predb->progress(settings_array($match[2] + 1, $progress), ['read' => false]); echo "Successfully imported PreDB dump {$match[2]}, " . --$total . ' dumps remaining.' . PHP_EOL;
if (!(isset($argv[1]) && in_array(strtolower($argv[1]), $db) && isset($argv[2]) && is_file($argv[2]))) { $message = <<<HELP This script can import a predb dump file. You may use the full path, or a relative path. For importing, the script insert new rows and update existing matched rows. For databases not on the local system, use remote, else use local. php {$argv[0]} [remote | local] /path/with/filename HELP; exit($message); } else { $path = !preg_match('#^/#', $argv[2]) ? getcwd() . '/' . $argv[2] : $argv[2]; } $argv[1] = strtolower($argv[1]); Misc::clearScreen(); $table = isset($argv[3]) ? $argv[3] : 'predb'; $predb = new PreDb(); $local = $argv[1] === 'local'; echo $predb->log->info("Clearing import table"); // Truncate to clear any old data $predb->executeTruncate(); // Import file into predb_imports $predb->executeLoadData(['enclosedby' => "'", 'fields' => '\\t\\t', 'lines' => '\\r\\n', 'local' => $local, 'optional' => true, 'path' => $path]); // Remove any titles where length <=8 echo $predb->log->info("Deleting any records where title <=8 from Temporary Table"); $predb->executeDeleteShort(); // Add any groups that do not currently exist $predb->executeAddGroups(); // Fill the group_id $predb->executeUpdateGroupID(); echo $predb->log->info("Inserting records from temporary table into predb table"); $predb->executeInsert();