diff --git a/README.md b/README.md index 81695a4..e4d4099 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,6 @@ Szkielet komponentu Joomla 6 do gromadzenia pytań testowych. ## Instalacja -W Joomla wybierz **System → Install → Install from Folder** i wskaż ten katalog. Manifestem instalacyjnym jest `com_testquestions.xml` (wersja 1.42.6). +W Joomla wybierz **System → Install → Install from Folder** i wskaż ten katalog. Manifestem instalacyjnym jest `com_testquestions.xml` (wersja 1.42.7). Po instalacji komponent jest dostępny w panelu administratora jako **Pytania testowe**. diff --git a/administrator/components/com_testquestions/sql/updates/mysql/1.42.7.sql b/administrator/components/com_testquestions/sql/updates/mysql/1.42.7.sql new file mode 100644 index 0000000..ebf5489 --- /dev/null +++ b/administrator/components/com_testquestions/sql/updates/mysql/1.42.7.sql @@ -0,0 +1 @@ +-- No database changes required for version 1.42.7. diff --git a/administrator/components/com_testquestions/src/Controller/ResultController.php b/administrator/components/com_testquestions/src/Controller/ResultController.php index ed457f7..6ff6064 100644 --- a/administrator/components/com_testquestions/src/Controller/ResultController.php +++ b/administrator/components/com_testquestions/src/Controller/ResultController.php @@ -47,9 +47,12 @@ class ResultController extends BaseController try { $this->getModel('Result')->evaluateWithAi($id, $questionId); } catch (\Throwable $error) { - $message = $error->getMessage() === 'AI_NOT_CONFIGURED' - ? Text::_('COM_TESTQUESTIONS_AI_NOT_CONFIGURED') - : Text::sprintf('COM_TESTQUESTIONS_AI_ERROR', $error->getMessage()); + $errorMessage = $error->getMessage(); + $message = str_starts_with($errorMessage, 'AI_KEY_EMPTY|') + ? 'Diagnostyka konfiguracji AI (1.42.7): ' . substr($errorMessage, strlen('AI_KEY_EMPTY|')) + : ($errorMessage === 'AI_NOT_CONFIGURED' + ? Text::_('COM_TESTQUESTIONS_AI_NOT_CONFIGURED') + : Text::sprintf('COM_TESTQUESTIONS_AI_ERROR', $errorMessage)); $type = 'error'; } diff --git a/administrator/components/com_testquestions/src/Model/ResultModel.php b/administrator/components/com_testquestions/src/Model/ResultModel.php index 69efeea..84874d7 100644 --- a/administrator/components/com_testquestions/src/Model/ResultModel.php +++ b/administrator/components/com_testquestions/src/Model/ResultModel.php @@ -93,6 +93,7 @@ class ResultModel extends BaseDatabaseModel $params = ComponentHelper::getParams('com_testquestions'); $provider = trim((string) $params->get('ai_provider', 'openai')); $apiKey = trim((string) $params->get('ai_api_key', '')); + $componentKeyLength = mb_strlen($apiKey); // Odczytaj zapisane parametry bezpośrednio z bazy. Dzięki temu nie użyjemy // nieaktualnej wartości z pamięci ComponentHelper, a maska pola hasła @@ -120,6 +121,17 @@ class ResultModel extends BaseDatabaseModel } } + if (trim($apiKey) === '') { + $databaseKey = is_array($storedParams) ? trim((string) ($storedParams['ai_api_key'] ?? '')) : ''; + $databaseKeyLength = preg_match('/^\*+$/', $databaseKey) ? 0 : mb_strlen($databaseKey); + throw new \RuntimeException( + 'AI_KEY_EMPTY|provider=' . ($provider !== '' ? $provider : '(pusty)') + . '|component_chars=' . $componentKeyLength + . '|database_chars=' . $databaseKeyLength + . '|database_params=' . (is_array($storedParams) ? 'json' : 'unreadable') + ); + } + $feedback = (new AiService())->evaluate( $provider, $apiKey, diff --git a/com_testquestions.xml b/com_testquestions.xml index 1a56bee..989ad96 100644 --- a/com_testquestions.xml +++ b/com_testquestions.xml @@ -4,7 +4,7 @@ 2026-10-14 Komponent GNU General Public License version 2 or later - 1.42.6 + 1.42.7 COM_TESTQUESTIONS_DESCRIPTION com_testquestions Komponent\Component\Testquestions