-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add hook to include custom variables by default when searching under …
…Overview entries refs #1045
- Loading branch information
Oscar Zambotti
authored and
Oscar Zambotti
committed
Aug 20, 2024
1 parent
334aaf8
commit 5c2b7d3
Showing
3 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Icinga\Module\Icingadb\Hook; | ||
|
||
use Icinga\Application\Hook; | ||
use Icinga\Application\Logger; | ||
use ipl\Orm\Model; | ||
use Throwable; | ||
|
||
abstract class CustomVarsRetrieverHook | ||
{ | ||
abstract public function retrieveCustomVars(Model $model): array; | ||
|
||
final public static function getCustomVarColumns(Model $model): array | ||
{ | ||
$columns = []; | ||
|
||
$hooks = Hook::all('Icingadb/CustomVarsRetriever'); | ||
foreach ($hooks as $hook) { | ||
try { | ||
$customVars = $hook->retrieveCustomVars($model); | ||
if (!empty($customVars)) { | ||
$columns = [...$columns, ...$customVars]; | ||
} | ||
} catch (Throwable $e) { | ||
Logger::error( | ||
'Error retrieving Custom Vars for %s: %s', | ||
$object, | ||
$e->getMessage() | ||
); | ||
} | ||
} | ||
|
||
return $columns; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters