BranchSupport: new helper class

This commit is contained in:
Thomas Gelf 2022-08-25 14:42:17 +02:00
parent b2afca2496
commit 956708475e
2 changed files with 40 additions and 23 deletions

View File

@ -0,0 +1,38 @@
<?php
namespace Icinga\Module\Director\Db\Branch;
use Icinga\Module\Director\Data\Db\DbObjectTypeRegistry;
use Icinga\Module\Director\Objects\SyncRule;
class BranchSupport
{
const BRANCHED_TABLES = [
'icinga_apiuser',
'icinga_command',
'icinga_dependency',
'icinga_endpoint',
'icinga_host',
'icinga_hostgroup',
'icinga_notification',
'icinga_scheduled_downtime',
'icinga_service',
'icinga_servicegroup',
'icinga_timeperiod',
'icinga_user',
'icinga_usergroup',
'icinga_zone',
];
public static function existsForTableName($table)
{
return in_array($table, self::BRANCHED_TABLES, true);
}
public static function existsForSyncRule(SyncRule $rule)
{
return static::existsForTableName(
DbObjectTypeRegistry::tableNameByType($rule->get('object_type'))
);
}
}

View File

@ -6,6 +6,7 @@ use Icinga\Module\Director\Data\Db\DbObjectStore;
use Icinga\Module\Director\Data\Db\DbObjectTypeRegistry;
use Icinga\Module\Director\Db\Branch\Branch;
use Icinga\Module\Director\Db\Branch\BranchStore;
use Icinga\Module\Director\Db\Branch\BranchSupport;
use Icinga\Module\Director\Objects\IcingaObject;
use Icinga\Module\Director\Web\Widget\NotInBranchedHint;
@ -17,23 +18,6 @@ trait BranchHelper
/** @var BranchStore */
protected $branchStore;
protected static $banchedTables = [
'icinga_apiuser',
'icinga_command',
'icinga_dependency',
'icinga_endpoint',
'icinga_host',
'icinga_hostgroup',
'icinga_notification',
'icinga_scheduled_downtime',
'icinga_service',
'icinga_servicegroup',
'icinga_timeperiod',
'icinga_user',
'icinga_usergroup',
'icinga_zone',
];
/**
* @return false|\Ramsey\Uuid\UuidInterface
*/
@ -69,14 +53,9 @@ trait BranchHelper
return $this->getBranchUuid() !== null;
}
protected function tableHasBranchSupport($table)
{
return in_array($table, self::$banchedTables, true);
}
protected function enableStaticObjectLoader($table)
{
if ($this->tableHasBranchSupport($table)) {
if (BranchSupport::existsForTableName($table)) {
IcingaObject::setDbObjectStore(new DbObjectStore($this->db(), $this->getBranch()));
}
}