$first_time = false; // Re-fetch the data, now that we have performed character set conversion. $data = Database::prepare("SELECT gedcom_chunk_id, REPLACE(chunk_data, '\r', '\n') AS chunk_data" . " FROM `##gedcom_chunk`" . " WHERE gedcom_chunk_id=?")->execute(array($data->gedcom_chunk_id))->fetchOneRow(); } if (!$data) { break; } try { // Import all the records in this chunk of data foreach (preg_split('/\\n+(?=0)/', $data->chunk_data) as $rec) { FunctionsImport::importRecord($rec, $tree, false); } // Mark the chunk as imported Database::prepare("UPDATE `##gedcom_chunk` SET imported=TRUE WHERE gedcom_chunk_id=?")->execute(array($data->gedcom_chunk_id)); } catch (PDOException $ex) { Database::rollBack(); if ($ex->getCode() === '40001') { // "SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction" // The documentation says that if you get this error, wait and try again..... $controller->addInlineJavascript('jQuery("#import' . $gedcom_id . '").load("import.php?gedcom_id=' . $gedcom_id . '&u=' . uniqid() . '");'); } else { // A fatal error. Nothing we can do? echo '<span class="error">', $ex->getMessage(), '</span>'; $controller->addInlineJavascript('jQuery("#actions' . $gedcom_id . '").removeClass("hidden");'); } return; } } Database::commit(); // Reload..... // Use uniqid() to prevent jQuery caching the previous response.