From ac9544adc3bfc33913deb6ff333c8e0165072c8e Mon Sep 17 00:00:00 2001 From: Lincoln Russell Date: Mon, 30 Dec 2024 15:30:49 -0500 Subject: [PATCH 1/9] fix: Deprecation warning in Formatter --- src/Formatter.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Formatter.php b/src/Formatter.php index 39ba5b67..5adeeae0 100644 --- a/src/Formatter.php +++ b/src/Formatter.php @@ -78,6 +78,10 @@ public function toTextFormatter(?string $format, ?string $text): string */ public static function closeTags(?string $text): ?string { + if (empty($text)) { + return $text; + } + //
$text = str_replace('
', '
', $text); // From f963a3bd4ce34621c28cfc57a0c563299f8ad007 Mon Sep 17 00:00:00 2001 From: Lincoln Russell Date: Mon, 30 Dec 2024 15:31:23 -0500 Subject: [PATCH 2/9] fix: Only show deprecation notices in debug mode --- bootstrap.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bootstrap.php b/bootstrap.php index d21e235d..8cadd5ae 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -26,6 +26,13 @@ // Require & load config. \Porter\Config::getInstance()->set(loadConfig()); +// See deprecation notices in debug mode only. +if (\Porter\Config::getInstance()->debugEnabled()) { + error_reporting(E_ALL); +} else { + error_reporting(E_ALL & ~E_DEPRECATED); +} + // Load source & target support. \Porter\Support::getInstance()->setSources(loadSources()); \Porter\Support::getInstance()->setTargets(loadTargets()); From 8781e89701964b828a4ff8d3a88398b5cec8c56c Mon Sep 17 00:00:00 2001 From: Lincoln Russell Date: Mon, 30 Dec 2024 15:59:48 -0500 Subject: [PATCH 3/9] fix: Throw exceptions in Config rather than triggering errors --- src/Config.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Config.php b/src/Config.php index e770115e..22fa82a8 100644 --- a/src/Config.php +++ b/src/Config.php @@ -2,6 +2,8 @@ namespace Porter; +use http\Exception; + class Config { private static $instance = null; @@ -83,25 +85,26 @@ public function getConnectionAlias(string $alias): array * * @param string $alias * @param array $info + * @throws \Exception */ protected function validateConnectionInfo(string $alias, array $info): void { // Alias not in config. if (empty($info)) { - trigger_error('Config error: Alias "' . $alias . '" not found', E_USER_ERROR); + //trigger_error('Config error: Alias "' . $alias . '" not found', E_USER_ERROR); + throw new \Exception('Alias "' . $alias . '" not found in config'); } // Type is required. if (empty($info['type'])) { - trigger_error('Config error: No connection `type` for alias "' . $alias . '"', E_USER_ERROR); + throw new \Exception('No connection `type` for alias "' . $alias . '" in config'); } // Database required fields. if ($info['type'] === 'database') { - foreach (['adapter', 'host','name','user'] as $required_field) { - if (!array_key_exists($required_field, $info)) { - trigger_error('Config error: Database `' . $required_field . - '` missing for alias "' . $alias . '"', E_USER_ERROR); + foreach (['adapter', 'host','name','user'] as $property) { + if (!array_key_exists($property, $info)) { + throw new \Exception('Database `' . $property . '` missing for alias "' . $alias . '" in config'); } } } From b1fae0453f27ae2d6be98e35de296361948198c9 Mon Sep 17 00:00:00 2001 From: Lincoln Russell Date: Mon, 30 Dec 2024 16:11:38 -0500 Subject: [PATCH 4/9] fix: Cleanup empty check for vanillPhoto() --- src/Functions/filter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Functions/filter.php b/src/Functions/filter.php index d3e97f56..683cc759 100644 --- a/src/Functions/filter.php +++ b/src/Functions/filter.php @@ -608,8 +608,8 @@ function bb_Decodeit($matches) function vanillaPhoto($path) { // Skip processing for blank entries. - if ($path === '') { - return ''; + if (empty($path)) { + return $path; } // Vanilla can have URLs in the Photo field. From ac9ab22b43a6999d5e99e5d25e0f7746aff752ec Mon Sep 17 00:00:00 2001 From: Lincoln Russell Date: Mon, 30 Dec 2024 17:31:06 -0500 Subject: [PATCH 5/9] fix: Use a digestable error when massive batch inserts fail --- src/Storage/Database.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Storage/Database.php b/src/Storage/Database.php index 00c3dcaa..1865953f 100644 --- a/src/Storage/Database.php +++ b/src/Storage/Database.php @@ -186,7 +186,12 @@ private function sendBatch(array $batch) { $tableName = $this->getBatchTable(); $action = (in_array($tableName, $this->ignoreErrorsTables)) ? 'insertOrIgnore' : 'insert'; - $this->connection->connection()->table($tableName)->$action($batch); + try { + $this->connection->connection()->table($tableName)->$action($batch); + } catch (\Illuminate\Database\QueryException $e) { + echo "\n\nBatch insert error: " . substr($e->getMessage(), 0, 500); + echo "\n[...]\n" . substr($e->getMessage(), -300) . "\n"; + } } /** From 1119e8cc80d3aa901781ccfd915f49c91df493d7 Mon Sep 17 00:00:00 2001 From: Lincoln Russell Date: Mon, 30 Dec 2024 18:39:29 -0500 Subject: [PATCH 6/9] fix: Ensure Flarum target gets non-null SQL math values --- src/Target/Flarum.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Target/Flarum.php b/src/Target/Flarum.php index 0613e6dd..b2d5e6ce 100644 --- a/src/Target/Flarum.php +++ b/src/Target/Flarum.php @@ -474,12 +474,12 @@ protected function comments(ExportModel $ex): void ->first(); // Save value for other associations (e.g. attachments). - $this->discussionPostOffset = $result->LastCommentID; + $this->discussionPostOffset = $result->LastCommentID ?? 0; // Use DiscussionID but fast-forward it past highest CommentID to insure it's unique. $discussions = $ex->dbImport()->table('PORT_Discussion') ->select( - $ex->dbImport()->raw('(DiscussionID + ' . $result->LastCommentID . ') as CommentID'), + $ex->dbImport()->raw('(DiscussionID + ' . $this->discussionPostOffset . ') as CommentID'), 'DiscussionID', 'InsertUserID', 'DateInserted', @@ -772,11 +772,12 @@ public function reactions(ExportModel $ex) ->table('PORT_Comment') ->select($ex->dbImport()->raw('max(CommentID) as LastCommentID')) ->first(); + $lastCommentID = $result->LastCommentID ?? 0; /* @see Target\Flarum::comments() — replicate our math in the post split */ $discussionReactions = $ex->dbImport()->table('PORT_UserTag') ->select( - $ex->dbImport()->raw('(RecordID + ' . $result->LastCommentID . ') as RecordID'), + $ex->dbImport()->raw('(RecordID + ' . $lastCommentID . ') as RecordID'), 'UserID', 'TagID', $ex->dbImport()->raw('TIMESTAMP(DateInserted) as DateInserted'), From 6c82a652d1cef4676560508311f5ececcefec75c Mon Sep 17 00:00:00 2001 From: Lincoln Russell Date: Mon, 30 Dec 2024 19:15:59 -0500 Subject: [PATCH 7/9] fix: Set config array defaults --- src/Config.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Config.php b/src/Config.php index 22fa82a8..1cacadb4 100644 --- a/src/Config.php +++ b/src/Config.php @@ -8,7 +8,11 @@ class Config { private static $instance = null; - protected array $config = []; + protected array $config = [ + 'debug' => false, + 'test_alias' => 'test', + 'connections' => [], + ]; /** * Make it a singleton; there's only 1 config. From ae116b2025c154aeb8b169720c3daae7429ce9b3 Mon Sep 17 00:00:00 2001 From: Lincoln Russell Date: Mon, 30 Dec 2024 19:21:57 -0500 Subject: [PATCH 8/9] Fix: Remove trigger_error for not coping config --- src/Functions/core.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Functions/core.php b/src/Functions/core.php index f1dd1e4d..beaa31f3 100644 --- a/src/Functions/core.php +++ b/src/Functions/core.php @@ -24,7 +24,7 @@ function loadConfig(): array if (file_exists(ROOT_DIR . '/config.php')) { return require(ROOT_DIR . '/config.php'); } else { - trigger_error('Missing config.php — Make a copy of config-sample.php!'); + //trigger_error('Missing config.php — Make a copy of config-sample.php!'); return require(ROOT_DIR . '/config-sample.php'); } } From 75e3a8a3c7162f8d6dd92e834c9dcb491aa8eec7 Mon Sep 17 00:00:00 2001 From: Lincoln Russell Date: Mon, 30 Dec 2024 19:26:06 -0500 Subject: [PATCH 9/9] fix: Default config debug to false --- src/Config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Config.php b/src/Config.php index 1cacadb4..097adda1 100644 --- a/src/Config.php +++ b/src/Config.php @@ -47,7 +47,7 @@ public function getConnections(): array */ public function debugEnabled(): bool { - return $this->config['debug']; + return $this->config['debug'] ?? false; } /**