Change to PDODocument library

This commit is contained in:
2024-06-04 19:56:06 -04:00
parent 1ca7dbdedd
commit 7231a95fca
18 changed files with 197 additions and 233 deletions

View File

@@ -1,9 +1,9 @@
<?php declare(strict_types=1);
use BitBadger\Documents\DocumentException;
use BitBadger\Documents\SQLite\Configuration;
use BitBadger\Documents\SQLite\Custom;
use BitBadger\Documents\SQLite\Results;
use BitBadger\PDODocument\Configuration;
use BitBadger\PDODocument\Custom;
use BitBadger\PDODocument\DocumentException;
use BitBadger\PDODocument\Mapper\CountMapper;
use FeedReaderCentral\Data;
require __DIR__ . '/../cli-start.php';
@@ -39,25 +39,23 @@ function display_help(): never
function rebuild_index(): void
{
try {
$db = Configuration::dbConn();
$pdo = Configuration::dbConn();
} catch (DocumentException $ex) {
printfn("ERR: Cannot obtain a connection to the database\n $ex");
return;
}
try {
$hasIndex = Custom::scalar("SELECT COUNT(*) FROM sqlite_master WHERE name = 'item_ai'", [],
Results::toCount(...), $db);
$hasIndex = Custom::scalar("SELECT COUNT(*) FROM sqlite_master WHERE name = 'item_ai'", [], new CountMapper(),
$pdo);
if ($hasIndex == 0) {
printfn('Creating search index....');
Data::createSearchIndex($db);
Data::createSearchIndex($pdo);
}
printfn('Rebuilding search index...');
Custom::nonQuery("INSERT INTO item_search (item_search) VALUES ('rebuild')", [], $db);
Custom::nonQuery("INSERT INTO item_search (item_search) VALUES ('rebuild')", [], $pdo);
printfn(PHP_EOL . 'Search index rebuilt');
} catch (DocumentException $ex) {
printfn("$ex");
} finally {
$db->close();
}
}