From f93552ad864202a3459fcbdfdffb1c79115a7552 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Thu, 25 Apr 2024 22:38:34 +0100 Subject: [PATCH] Revert "Use the same indexing database throughout (#118)" This doesn't seem to create the DB properly and is failing the builds. This reverts commit ef13e91f06845434398a12139741f0ac88a4fcf8. --- phpdotnet/phd/Format.php | 10 ++++++++-- phpdotnet/phd/functions.php | 14 +++++++++----- render.php | 29 ++++++++++++++++++----------- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/phpdotnet/phd/Format.php b/phpdotnet/phd/Format.php index 1754f914..2317deba 100644 --- a/phpdotnet/phd/Format.php +++ b/phpdotnet/phd/Format.php @@ -63,8 +63,14 @@ abstract class Format extends ObjectStorage protected $CURRENT_ID = ""; public function __construct() { - if (Config::indexcache()) { - $this->sqlite = Config::indexcache(); + $sqlite = Config::indexcache(); + if (!$sqlite) { + if (file_exists(Config::output_dir() . "index.sqlite")) { + $sqlite = new \SQLite3(Config::output_dir() . 'index.sqlite'); + } + } + if ($sqlite) { + $this->sqlite = $sqlite; $this->sortIDs(); } } diff --git a/phpdotnet/phd/functions.php b/phpdotnet/phd/functions.php index dff19f29..013d2d2d 100644 --- a/phpdotnet/phd/functions.php +++ b/phpdotnet/phd/functions.php @@ -195,9 +195,12 @@ function errh($errno, $msg, $file, $line, $ctx = null) { * * @return boolean True if indexing is required. */ -function requireIndexing(Config $config): bool { - if (! $config->indexcache()) { - return true; +function requireIndexing(Config $config, ?\SQLite3 $db = null): bool { + if ($db === null) { + $indexfile = $config->output_dir() . 'index.sqlite'; + if (!file_exists($indexfile)) { + return true; + } } if ($config->no_index()) { @@ -208,8 +211,9 @@ function requireIndexing(Config $config): bool { return true; } - $db = $config->indexcache(); - + if ($db === null) { + $db = new \SQLite3($indexfile); + } $indexingCount = $db->query('SELECT COUNT(time) FROM indexing') ->fetchArray(SQLITE3_NUM); if ($indexingCount[0] == 0) { diff --git a/render.php b/render.php index 04ed86d8..4dfb2ae1 100644 --- a/render.php +++ b/render.php @@ -73,15 +73,15 @@ exit(0); } -function make_reader(Config $config) { +function make_reader() { //Partial Rendering $idlist = Config::render_ids() + Config::skip_ids(); if (!empty($idlist)) { v("Running partial build", VERBOSE_RENDER_STYLE); $parents = []; - if ($config->indexcache()) { - $sqlite = $config->indexcache(); + if (file_exists(Config::output_dir() . "index.sqlite")) { + $sqlite = new \SQLite3(Config::output_dir() . "index.sqlite"); // Fetch all ancestors of the ids we should render foreach(Config::render_ids() as $p => $v) { do { @@ -116,26 +116,33 @@ function make_reader(Config $config) { $readerOpts |= LIBXML_XINCLUDE; } -if (Config::memoryindex()) { - $db = new \SQLite3(":memory:"); -} else { +if (file_exists(Config::output_dir() . 'index.sqlite')) { $db = new \SQLite3(Config::output_dir() . 'index.sqlite'); +} else { + $db = null; } -Config::set_indexcache($db); - // Indexing -if (requireIndexing(new Config)) { +if (requireIndexing(new Config, $db)) { v("Indexing...", VERBOSE_INDEXING); + if (Config::memoryindex()) { + $db = new \SQLite3(":memory:"); + } else { + $db = $db ?? new \SQLite3(Config::output_dir() . 'index.sqlite'); + } // Create indexer $indexRepository = new IndexRepository($db); $format = new Index($indexRepository); $render->attach($format); - $reader = make_reader(new Config); + $reader = make_reader(); $reader->open(Config::xml_file(), NULL, $readerOpts); $render->execute($reader); + if (Config::memoryindex()) { + Config::set_indexcache($db); + } + $render->detach($format); v("Indexing done", VERBOSE_INDEXING); @@ -158,7 +165,7 @@ function make_reader(Config $config) { } // Render formats -$reader = make_reader(new Config); +$reader = make_reader(); $reader->open(Config::xml_file(), NULL, $readerOpts); foreach($render as $format) { $format->notify(Render::VERBOSE, true);