summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/Http/Controllers/GedcomFileController.php16
-rw-r--r--app/Tree.php47
-rw-r--r--tests/TestCase.php3
3 files changed, 32 insertions, 34 deletions
diff --git a/app/Http/Controllers/GedcomFileController.php b/app/Http/Controllers/GedcomFileController.php
index eefeb4f706..f76064f3ba 100644
--- a/app/Http/Controllers/GedcomFileController.php
+++ b/app/Http/Controllers/GedcomFileController.php
@@ -82,7 +82,7 @@ class GedcomFileController extends AbstractBaseController
->where('gedcom_id', '=', $tree->id())
->where('imported', '=', '0')
->orderby('gedcom_chunk_id')
- ->select('gedcom_chunk_id, chunk_data')
+ ->select(['gedcom_chunk_id', 'chunk_data'])
->first();
// If we are loading the first (header) record, make sure the encoding is UTF-8.
@@ -169,27 +169,25 @@ class GedcomFileController extends AbstractBaseController
// Re-fetch the data, now that we have performed character set conversion.
$data = DB::table('gedcom_chunk')
->where('gedcom_chunk_id', '=', $data->gedcom_chunk_id)
- ->select('gedcom_chunk_id, chunk_data')
+ ->select(['gedcom_chunk_id', 'chunk_data'])
->first();
}
- $data->chunk_data = str_replace("\r", "\n", $data->chunk_data);
-
if (!$data) {
break;
}
+ $data->chunk_data = str_replace("\r", "\n", $data->chunk_data);
+
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 = :chunk_id"
- )->execute([
- 'chunk_id' => $data->gedcom_chunk_id,
- ]);
+ DB::table('gedcom_chunk')
+ ->where('gedcom_chunk_id', '=', $data->gedcom_chunk_id)
+ ->update(['imported' => 1]);
} catch (PDOException $ex) {
return $this->viewResponse('admin/import-fail', [
'error' => $ex->getMessage(),
diff --git a/app/Tree.php b/app/Tree.php
index 34b384824c..37f4589558 100644
--- a/app/Tree.php
+++ b/app/Tree.php
@@ -547,23 +547,25 @@ class Tree
*/
public function deleteGenealogyData(bool $keep_media)
{
- Database::prepare("DELETE FROM `##gedcom_chunk` WHERE gedcom_id = ?")->execute([$this->id]);
- Database::prepare("DELETE FROM `##individuals` WHERE i_file = ?")->execute([$this->id]);
- Database::prepare("DELETE FROM `##families` WHERE f_file = ?")->execute([$this->id]);
- Database::prepare("DELETE FROM `##sources` WHERE s_file = ?")->execute([$this->id]);
- Database::prepare("DELETE FROM `##other` WHERE o_file = ?")->execute([$this->id]);
- Database::prepare("DELETE FROM `##places` WHERE p_file = ?")->execute([$this->id]);
- Database::prepare("DELETE FROM `##placelinks` WHERE pl_file = ?")->execute([$this->id]);
- Database::prepare("DELETE FROM `##name` WHERE n_file = ?")->execute([$this->id]);
- Database::prepare("DELETE FROM `##dates` WHERE d_file = ?")->execute([$this->id]);
- Database::prepare("DELETE FROM `##change` WHERE gedcom_id = ?")->execute([$this->id]);
+ DB::table('gedcom_chunk')->where('gedcom_id', '=', $this->id)->delete();
+ DB::table('individuals')->where('i_file', '=', $this->id)->delete();
+ DB::table('families')->where('f_file', '=', $this->id)->delete();
+ DB::table('sources')->where('s_file', '=', $this->id)->delete();
+ DB::table('other')->where('o_file', '=', $this->id)->delete();
+ DB::table('places')->where('p_file', '=', $this->id)->delete();
+ DB::table('placelinks')->where('pl_file', '=', $this->id)->delete();
+ DB::table('name')->where('n_file', '=', $this->id)->delete();
+ DB::table('dates')->where('d_file', '=', $this->id)->delete();
+ DB::table('change')->where('gedcom_id', '=', $this->id)->delete();
if ($keep_media) {
- Database::prepare("DELETE FROM `##link` WHERE l_file =? AND l_type<>'OBJE'")->execute([$this->id]);
+ DB::table('link')->where('l_file', '=', $this->id)
+ ->where('l_type', '<>', 'OBJE')
+ ->delete();
} else {
- Database::prepare("DELETE FROM `##link` WHERE l_file =?")->execute([$this->id]);
- Database::prepare("DELETE FROM `##media` WHERE m_file =?")->execute([$this->id]);
- Database::prepare("DELETE FROM `##media_file` WHERE m_file =?")->execute([$this->id]);
+ DB::table('link')->where('l_file', '=', $this->id)->delete();
+ DB::table('media_file')->where('m_file', '=', $this->id)->delete();
+ DB::table('media')->where('m_file', '=', $this->id)->delete();
}
}
@@ -673,20 +675,17 @@ class Tree
}
}
if ($pos) {
- Database::prepare(
- "INSERT INTO `##gedcom_chunk` (gedcom_id, chunk_data) VALUES (?, ?)"
- )->execute([
- $this->id,
- substr($file_data, 0, $pos),
+ DB::table('gedcom_chunk')->insert([
+ 'gedcom_id' => $this->id,
+ 'chunk_data' => substr($file_data, 0, $pos),
]);
+
$file_data = substr($file_data, $pos);
}
}
- Database::prepare(
- "INSERT INTO `##gedcom_chunk` (gedcom_id, chunk_data) VALUES (?, ?)"
- )->execute([
- $this->id,
- $file_data,
+ DB::table('gedcom_chunk')->insert([
+ 'gedcom_id' => $this->id,
+ 'chunk_data' => $file_data,
]);
fclose($fp);
diff --git a/tests/TestCase.php b/tests/TestCase.php
index 9fca11260a..06ef504869 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -122,10 +122,11 @@ class TestCase extends \PHPUnit\Framework\TestCase
$tree = Tree::create(basename($gedcom_file), basename($gedcom_file));
$tree->importGedcomFile(__DIR__ . '/data/' . $gedcom_file, $gedcom_file);
+ View::share('tree', $tree);
$gedcom_file_controller = new GedcomFileController();
do {
- $gedcom_file_controller->import(new TimeoutService(microtime()), $tree);
+ $gedcom_file_controller->import(new TimeoutService(microtime(true)), $tree);
$imported = $tree->getPreference('imported');
} while (!$imported);