From 382511077a03a6c8dbe9547d363445b5a9b2178d Mon Sep 17 00:00:00 2001 From: Brian Huisman Date: Fri, 21 Jul 2023 13:04:51 -0400 Subject: [PATCH] Misc updates Prettify some SQL code. Add some error-reponse code for fatal failed SQL statements. --- orcinus/config.php | 15 ++++++++++++--- orcinus/crawler.php | 17 +++++++++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/orcinus/config.php b/orcinus/config.php index 9ba0186..41f5ef7 100644 --- a/orcinus/config.php +++ b/orcinus/config.php @@ -123,7 +123,10 @@ if (!in_array($_DDATA['tbprefix'].'config', $_DDATA['tables'], true)) { `jw_hostname` TINYTEXT NOT NULL, `jw_compression` TINYINT UNSIGNED NOT NULL, PRIMARY KEY (`version`) - ) ENGINE = MyISAM, CHARACTER SET = utf8mb4, COLLATE = utf8mb4_unicode_520_ci;' + ) ENGINE = MyISAM, + CHARACTER SET = utf8mb4, + COLLATE = utf8mb4_unicode_520_ci + ;' ); $err = $create->errorInfo(); if ($err[0] != '00000') @@ -232,7 +235,10 @@ if (!in_array($_DDATA['tbprefix'].'crawldata', $_DDATA['tables'], true)) { `last_modified` INT NOT NULL, `priority` DECIMAL(2,1) NOT NULL, UNIQUE `content_checksum` (`content_checksum`) - ) ENGINE = MyISAM, CHARACTER SET = utf8mb4, COLLATE = utf8mb4_unicode_520_ci;' + ) ENGINE = MyISAM, + CHARACTER SET = utf8mb4, + COLLATE = utf8mb4_unicode_520_ci + ;' ); $err = $create->errorInfo(); if ($err[0] != '00000') @@ -248,7 +254,10 @@ if (!in_array($_DDATA['tbprefix'].'query', $_DDATA['tables'], true)) { `stamp` INT UNSIGNED NOT NULL, `ip` INT UNSIGNED NOT NULL, `cache` MEDIUMBLOB NOT NULL - ) ENGINE = MyISAM, CHARACTER SET = utf8mb4, COLLATE = utf8mb4_unicode_520_ci;' + ) ENGINE = MyISAM, + CHARACTER SET = utf8mb4, + COLLATE = utf8mb4_unicode_520_ci + ;' ); $err = $create->errorInfo(); if ($err[0] != '00000') diff --git a/orcinus/crawler.php b/orcinus/crawler.php index c4eb8f6..8c34637 100644 --- a/orcinus/crawler.php +++ b/orcinus/crawler.php @@ -806,7 +806,7 @@ if (in_array($_DDATA['tbprefix'].'crawltemp', $_DDATA['tables'], true)) { // Run through every entry in the crawltemp table foreach ($select as $row) { - // In an entry matches an existing URL in the queue (just + // If an entry matches an existing URL in the queue (just // starting URLs right now) then delete that queue entry foreach ($_RDATA['sp_queue'] as $key => $queue) if ($row['url'] == $queue[0]) @@ -852,6 +852,13 @@ if (in_array($_DDATA['tbprefix'].'crawltemp', $_DDATA['tables'], true)) { $drop = $_DDATA['pdo']->query( 'DROP TABLE IF EXISTS `'.$_DDATA['tbprefix'].'crawltemp`;' ); + $err = $drop->errorInfo(); + if ($err[0] != '00000') { + // If we couldn't delete the interrupted crawldata table, this is + // a fatal error + OS_crawlLog('Could not delete previously interrupted crawl data; unable to crawl.', 2); + throw new Exception('Could not delete previously interrupted crawl data; unable to crawl.'); + } } } @@ -860,7 +867,13 @@ $create = $_DDATA['pdo']->query( 'CREATE TABLE IF NOT EXISTS`'.$_DDATA['tbprefix'].'crawltemp` LIKE `'.$_DDATA['tbprefix'].'crawldata`;' ); - +$err = $create->errorInfo(); +if ($err[0] != '00000') { + // If we could not create the crawldata table, or an interrupted + // crawldata table doesn't exist, then this is a fatal error + OS_crawlLog('Unable to create or reuse existing crawl data table; unable to crawl.', 2); + throw new Exception('Unable to create or reuse existing crawl data table; unable to crawl.'); +} // Prepare SQL statements $selectData = $_DDATA['pdo']->prepare(