app = $app; if($intern !== false){ return; } $this->app->ActionHandlerInit($this); $this->app->DefaultActionHandler('settings'); $this->app->ActionHandler('settings', 'SuperSearchSettings'); $this->app->ActionHandler('ajax', 'SuperSearchAjax'); $this->app->ActionHandlerListen($app); } /** * @return void */ public function Install() { $this->app->erp->CheckTable('supersearch_index_item'); $this->app->erp->CheckColumn('id', 'INT(10) UNSIGNED', 'supersearch_index_item', 'NOT NULL AUTO_INCREMENT'); $this->app->erp->CheckColumn('index_name', 'VARCHAR(16)', 'supersearch_index_item', 'NOT NULL'); $this->app->erp->CheckColumn('index_id', 'VARCHAR(38)', 'supersearch_index_item', 'NOT NULL'); $this->app->erp->CheckColumn('project_id', 'INT(10) UNSIGNED', 'supersearch_index_item', 'NOT NULL DEFAULT 0'); $this->app->erp->CheckColumn('title', 'VARCHAR(128)', 'supersearch_index_item', 'NOT NULL'); $this->app->erp->CheckColumn('subtitle', 'VARCHAR(128)', 'supersearch_index_item', 'NULL DEFAULT NULL'); $this->app->erp->CheckColumn('additional_infos', 'VARCHAR(255)', 'supersearch_index_item', 'NULL DEFAULT NULL'); $this->app->erp->CheckColumn('link', 'VARCHAR(128)', 'supersearch_index_item', 'NOT NULL'); $this->app->erp->CheckColumn('search_words', 'TEXT', 'supersearch_index_item', "NOT NULL DEFAULT ''"); $this->app->erp->CheckColumn('outdated', 'TINYINT(1) UNSIGNED', 'supersearch_index_item', "NOT NULL DEFAULT '0'"); $this->app->erp->CheckColumn('created_at', 'TIMESTAMP', 'supersearch_index_item', 'NOT NULL DEFAULT CURRENT_TIMESTAMP'); $this->app->erp->CheckColumn('updated_at', 'TIMESTAMP', 'supersearch_index_item', 'NULL DEFAULT NULL'); $this->app->erp->CheckIndex('supersearch_index_item', 'project_id'); $this->app->erp->CheckFulltextIndex('supersearch_index_item', 'search_words'); $this->app->erp->CheckAlterTable('ALTER TABLE `supersearch_index_item` ADD UNIQUE KEY `index_identifier` (`index_name`, `index_id`)'); $this->app->erp->CheckTable('supersearch_index_group'); $this->app->erp->CheckColumn('id', 'INT(10) UNSIGNED', 'supersearch_index_group', 'NOT NULL AUTO_INCREMENT'); $this->app->erp->CheckColumn('name', 'VARCHAR(16)', 'supersearch_index_group', 'NOT NULL'); $this->app->erp->CheckColumn('title', 'VARCHAR(32)', 'supersearch_index_group', 'NOT NULL'); $this->app->erp->CheckColumn('module', 'VARCHAR(38)', 'supersearch_index_group', 'NULL DEFAULT NULL'); $this->app->erp->CheckColumn('active', 'TINYINT(1) UNSIGNED', 'supersearch_index_group', "NOT NULL DEFAULT '1'"); $this->app->erp->CheckColumn('last_full_update', 'TIMESTAMP', 'supersearch_index_group', 'NULL DEFAULT NULL'); $this->app->erp->CheckColumn('last_diff_update', 'TIMESTAMP', 'supersearch_index_group', 'NULL DEFAULT NULL'); $this->app->erp->CheckAlterTable('ALTER TABLE `supersearch_index_group` ADD UNIQUE KEY `name` (`name`)'); $this->app->erp->CheckProzessstarter('SuperSearch Index-Full', 'uhrzeit', '', '2017-01-01 02:30:00', 'cronjob', 'supersearch_index_full', 1); $this->app->erp->CheckProzessstarter('SuperSearch Index-Diff', 'periodisch', '3600', '', 'cronjob', 'supersearch_index_diff', 1); $this->app->erp->RegisterHook('article_delete', 'supersearch', 'SuperSearchOnArticleDelete'); $this->app->erp->RegisterHook('address_delete', 'supersearch', 'SuperSearchOnAddressDelete'); } /** * @param int $articleId */ public function SuperSearchOnArticleDelete($articleId) { /** @var SuperSearchIndexer $indexer */ $indexer = $this->app->Container->get('SuperSearchIndexer'); $identifier = new IndexIdentifier('articles', (int)$articleId); $indexer->deleteIndexItem($identifier); } /** * @param int $addressId */ public function SuperSearchOnAddressDelete($addressId) { /** @var SuperSearchIndexer $indexer */ $indexer = $this->app->Container->get('SuperSearchIndexer'); $identifier = new IndexIdentifier('addresses', (int)$addressId); $indexer->deleteIndexItem($identifier); } /** * @return void */ public function SuperSearchMenu() { $this->app->erp->MenuEintrag('index.php?module=supersearch&action=settings', 'Übersicht'); } /** * @return void */ public function SuperSearchSettings() { $cmd = $this->app->Secure->GetPOST('cmd'); switch ($cmd) { case 'run-full-index-task': // Full-Index-Task ausführen $response = $this->HandleSuperSearchSettingsFullIndexTask(); $response->send(); $this->app->ExitXentral(); break; case 'activate-provider': $response = $this->HandleSuperSearchSettingsActivateProvider(); $response->send(); $this->app->ExitXentral(); break; case 'deactivate-provider': $response = $this->HandleSuperSearchSettingsDeactivateProvider(); $response->send(); $this->app->ExitXentral(); break; } // Prüfen ob beide Cronjobs aktiv sind $this->app->erp->checkActiveCronjob('supersearch_index_full'); $this->app->erp->checkActiveCronjob('supersearch_index_diff'); /** @var SuperSearchService $searchService */ $searchService = $this->app->Container->get('SuperSearchService'); if ($searchService->isIndexEmpty()) { $searchIndexEmptyMessage = 'Der Such-Index ist leer. Die Einstellungen stehen erst zur Verfügung wenn der Such-Index einmalig gefüllt wurde.'; $this->app->Tpl->Add('MESSAGE', sprintf('
Index | '; $table .= 'Index-Größe (aktuell) | '; $table .= 'Index-Größe (potentiell) | '; $table .= 'Letzes Index-Update | '; $table .= 'Provider-Status | '; $table .= 'Aktionen | '; $table .= '|
---|---|---|---|---|---|---|
'; $table .= ' | ' . ($info['index_size_current'] !== null ? $info['index_size_current'] : 'Unbekannt') . ' | '; $table .= '' . ($info['index_size_potential'] !== null ? $info['index_size_potential'] : 'Unbekannt') . ' | '; $table .= '' . ($lastUpdate !== null ? $lastUpdate->format('d.m.Y H:i:s') : 'NULL') . ' | '; $table .= ''; if ($info['active'] === true) { $table .= 'Aktiv'; } if ($info['active'] === false) { $table .= 'Inaktiv'; } if ($info['active'] === null) { $table .= 'Unbekannt'; } $table .= ' | '; $buttonTemplate = ''; if ($info['active'] === true){ $table .= sprintf($buttonTemplate, $info['name'], 'button-provider-deactivate', 'Such-Index deaktivieren'); } if ($info['active'] === false) { $table .= sprintf($buttonTemplate, $info['name'], 'button-provider-activate', 'Such-Index aktivieren'); } if ($info['active'] === null) { $table .= ' | '; } $table .= ' |
Such-Index ist nicht gefüllt. Bitte prüfen ob Prozessstarter aktiv sind.
'. ''. 'Zu den SuperSearch-Einstellungen'. '', 'data' => 'index-empty', ], JsonResponse::HTTP_INTERNAL_SERVER_ERROR ); } } return new JsonResponse(['success' => true, 'data' => $searchResult]); } /** * @return JsonResponse */ protected function HandleSuperSearchAjaxDetail() { $detailGroup = $this->app->Secure->GetPOST('detail_group'); $detailIdentifier = $this->app->Secure->GetPOST('detail_identifier'); $detailQuery = new DetailQuery($detailGroup, $detailIdentifier); $detailResult = new ResultDetail(); $this->app->erp->RunHook('supersearch_detail', 2, $detailQuery, $detailResult); return new JsonResponse(['success' => true, 'data' => $detailResult]); } /** * @param string|null $lastFullUpdate * @param string|null $lastDiffUpdate * * @return DateTimeImmutable|null */ protected function getGreatestDateTime($lastFullUpdate = null, $lastDiffUpdate = null) { if (!empty($lastFullUpdate)){ try { $lastFullUpdateTime = new \DateTimeImmutable($lastFullUpdate); } catch (Exception $exception) { } } if (!empty($lastDiffUpdate)) { try { $lastDiffUpdateTime = new \DateTimeImmutable($lastDiffUpdate); } catch (Exception $exception) { } } if (isset($lastFullUpdateTime) && !isset($lastDiffUpdateTime)) { return $lastFullUpdateTime; } if (!isset($lastFullUpdateTime) && isset($lastDiffUpdateTime)) { return $lastDiffUpdateTime; } if (isset($lastFullUpdateTime) && isset($lastDiffUpdateTime)) { if ($lastFullUpdateTime > $lastDiffUpdateTime) { return $lastFullUpdateTime; } else { return $lastDiffUpdateTime; } } return null; } }