From 4fa8fcab734e705b271df5f194d3b05c727653e5 Mon Sep 17 00:00:00 2001 From: Florent Torregrosa Date: Sat, 2 May 2015 23:30:58 +0200 Subject: [PATCH] Issue #2470553: Add live test of the tika jar file and allow to empty the tika config variable. --- .../TikaExtractor.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Plugin/SearchApiAttachmentsTextExtractor/TikaExtractor.php b/src/Plugin/SearchApiAttachmentsTextExtractor/TikaExtractor.php index 0765688..83c9367 100644 --- a/src/Plugin/SearchApiAttachmentsTextExtractor/TikaExtractor.php +++ b/src/Plugin/SearchApiAttachmentsTextExtractor/TikaExtractor.php @@ -62,7 +62,20 @@ class TikaExtractor extends TextExtractorPluginBase { '#description' => $this->t('Enter the full path to tika executable jar file. For example: "/var/apache-tika/tika-app-1.7.jar".'), '#default_value' => $this->configuration['tika_path'], ); - //@todo test connection live + + // Live test of the connection to Tika. + if (isset($this->configuration['tika_path']) && !empty($this->configuration['tika_path'])) { + $cmd = escapeshellcmd('java') . ' -jar ' . escapeshellarg($this->configuration['tika_path']) . ' -V'; + exec($cmd, $output, $return_code); + // $return_code = 1 if it fails. 0 instead. + if ($return_code) { + drupal_set_message(t('Tika could not be reached and executed.'), 'error'); + } + else { + drupal_set_message(t('Tika can be reached and be executed')); + } + } + return $form; } @@ -71,7 +84,7 @@ class TikaExtractor extends TextExtractorPluginBase { */ public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { $values = $form_state->getValues(); - if (isset($values['text_extractor_config']['tika_path']) && !file_exists($values['text_extractor_config']['tika_path'])) { + if (isset($values['text_extractor_config']['tika_path']) && !empty($values['text_extractor_config']['tika_path']) && !file_exists($values['text_extractor_config']['tika_path'])) { $form_state->setError($form['text_extractor_config']['tika_path'], $this->t('Invalid path or filename for tika application jar.')); } } -- 1.7.10.4