WIP on document conversion

This commit is contained in:
2024-05-30 21:58:54 -04:00
parent cfa56ec44f
commit df20936af2
34 changed files with 674 additions and 204 deletions

View File

@@ -1,5 +1,8 @@
<?php
use JetBrains\PhpStorm\NoReturn;
use BitBadger\Documents\SQLite\Custom;
use BitBadger\Documents\SQLite\Results;
use FeedReaderCentral\Data;
require __DIR__ . '/../cli-start.php';
@@ -20,8 +23,8 @@ switch ($argv[1]) {
/**
* Display the options for this utility and exit
*/
#[NoReturn]
function display_help(): void {
function display_help(): never
{
printfn('Options:');
printfn(' - rebuild');
printfn(' Rebuilds search index');
@@ -31,17 +34,20 @@ function display_help(): void {
/**
* Rebuild the search index, creating it if it does not already exist
*/
function rebuild_index(): void {
function rebuild_index(): void
{
$db = Data::getConnection();
try {
$hasIndex = $db->query("SELECT COUNT(*) FROM sqlite_master WHERE name = 'item_ai'");
if ($hasIndex->fetchArray(SQLITE3_NUM)[0] == 0) {
$hasIndex = Custom::scalar("SELECT COUNT(*) FROM sqlite_master WHERE name = 'item_ai'", [],
Results::toCount(...), $db);
if ($hasIndex == 0) {
printfn('Creating search index....');
Data::createSearchIndex($db);
}
printfn('Rebuilding search index...');
$db->exec("INSERT INTO item_search (item_search) VALUES ('rebuild')");
Custom::nonQuery("INSERT INTO item_search (item_search) VALUES ('rebuild')", [], $db);
// $db->exec("INSERT INTO item_search (item_search) VALUES ('rebuild')");
printfn(PHP_EOL . 'Search index rebuilt');
} finally {
$db->close();