chg: [eventReport] Improved html_to_markdown module handling

pull/6493/head
mokaddem 2020-10-26 13:45:54 +01:00
parent 3f25957d2a
commit 2143cdf83d
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
3 changed files with 9 additions and 6 deletions

View File

@ -186,7 +186,7 @@ class EventReportsController extends AppController
if (!empty($filters['index_for_event'])) {
$this->set('extendedEvent', !empty($filters['extended_event']));
$fetcherModule = $this->EventReport->isFetchURLModuleEnabled();
$this->set('importModuleEnabled', !empty($fetcherModule));
$this->set('importModuleEnabled', is_array($fetcherModule));
$this->render('ajax/indexForEvent');
}
}
@ -298,10 +298,10 @@ class EventReportsController extends AppController
'content' => $markdown
];
$errors = $this->EventReport->addReport($this->Auth->user(), $report, $event_id);
$redirectTarget = array('controller' => 'events', 'action' => 'view', $event_id);
} else {
$errors[] = __('Could not fetch report from URL. Fetcher module not enabled or could not download the page');
}
$redirectTarget = array('controller' => 'events', 'action' => 'view', $event_id);
if (!empty($errors)) {
return $this->__getFailResponseBasedOnContext($errors, array(), 'addFromURL', $this->EventReport->id, $redirectTarget);
} else {
@ -310,7 +310,7 @@ class EventReportsController extends AppController
return $this->__getSuccessResponseBasedOnContext($successMessage, $report, 'addFromURL', false, $redirectTarget);
}
}
$this->set('importModuleEnabled', empty($fetcherModule));
$this->set('importModuleEnabled', is_array($fetcherModule));
$this->set('event_id', $event_id);
$this->layout = 'ajax';
$this->render('ajax/importReportFromUrl');

View File

@ -825,7 +825,10 @@ class EventReport extends AppModel
public function downloadMarkdownFromURL($event_id, $url)
{
$this->Module = ClassRegistry::init('Module');
$module = $this->Module->getEnabledModule('html_to_markdown', 'expansion');
$module = $this->isFetchURLModuleEnabled();
if (!is_array($module)) {
return false;
}
$modulePayload = [
'module' => $module['name'],
'event_id' => $event_id,
@ -833,7 +836,7 @@ class EventReport extends AppModel
];
$module = $this->isFetchURLModuleEnabled();
if (!empty($module)) {
$result = $this->Module->queryModuleServer('/query', json_encode($modulePayload), false, $moduleFamily = 'Import');
$result = $this->Module->queryModuleServer('/query', $modulePayload, false);
if (empty($result['results'][0]['values'][0])) {
return '';
}

View File

@ -156,7 +156,7 @@ class Module extends AppModel
return 'The requested module is not enabled.';
}
if (is_array($modules)) {
foreach ($modules['modules'] as $module) {
foreach ($modules as $module) {
if ($module['name'] == $name) {
if ($type && in_array(strtolower($type), $module['meta']['module-type'])) {
return $module;