BranchSupport: introduce new constants

This commit is contained in:
Thomas Gelf 2022-08-29 08:55:46 +02:00
parent ae45844bac
commit 98cfcafdcd
3 changed files with 79 additions and 43 deletions

View File

@ -31,16 +31,20 @@ class BranchModificationInspection
public function describeBranch(UuidInterface $uuid)
{
$tables = [
$this->translate('API Users') => 'branched_icinga_apiuser',
$this->translate('Endpoints') => 'branched_icinga_endpoint',
$this->translate('Zones') => 'branched_icinga_zone',
$this->translate('Commands') => 'branched_icinga_command',
$this->translate('Hosts') => 'branched_icinga_host',
$this->translate('Hostgroups') => 'branched_icinga_hostgroup',
$this->translate('Services') => 'branched_icinga_service',
$this->translate('Servicegroups') => 'branched_icinga_servicegroup',
$this->translate('Users') => 'branched_icinga_user',
$this->translate('Timeperiods') => 'branched_icinga_timeperiod',
$this->translate('API Users') => BranchSupport::BRANCHED_TABLE_ICINGA_APIUSER,
$this->translate('Endpoints') => BranchSupport::BRANCHED_TABLE_ICINGA_COMMAND,
$this->translate('Zones') => BranchSupport::BRANCHED_TABLE_ICINGA_DEPENDENCY,
$this->translate('Commands') => BranchSupport::BRANCHED_TABLE_ICINGA_ENDPOINT,
$this->translate('Hosts') => BranchSupport::BRANCHED_TABLE_ICINGA_HOST,
$this->translate('Hostgroups') => BranchSupport::BRANCHED_TABLE_ICINGA_HOSTGROUP,
$this->translate('Services') => BranchSupport::BRANCHED_TABLE_ICINGA_NOTIFICATION,
$this->translate('Servicegroups') => BranchSupport::BRANCHED_TABLE_ICINGA_SCHEDULED_DOWNTIME,
$this->translate('Users') => BranchSupport::BRANCHED_TABLE_ICINGA_SERVICE,
$this->translate('Usergroups') => BranchSupport::BRANCHED_TABLE_ICINGA_SERVICEGROUP,
$this->translate('Timeperiods') => BranchSupport::BRANCHED_TABLE_ICINGA_TIMEPERIOD,
$this->translate('Notifications') => BranchSupport::BRANCHED_TABLE_ICINGA_USER,
$this->translate('Dependencies') => BranchSupport::BRANCHED_TABLE_ICINGA_USERGROUP,
$this->translate('Scheduled Downtimes') => BranchSupport::BRANCHED_TABLE_ICINGA_ZONE,
];
$parts = new HtmlDocument();

View File

@ -11,23 +11,6 @@ class BranchStore
{
const TABLE = 'director_branch';
const TABLE_ACTIVITY = 'director_branch_activity';
const OBJECT_TABLES = [
'branched_icinga_apiuser',
'branched_icinga_command',
'branched_icinga_dependency',
'branched_icinga_endpoint',
'branched_icinga_host',
'branched_icinga_hostgroup',
'branched_icinga_notification',
'branched_icinga_scheduled_downtime',
'branched_icinga_service',
'branched_icinga_service_set',
'branched_icinga_servicegroup',
'branched_icinga_timeperiod',
'branched_icinga_user',
'branched_icinga_usergroup',
'branched_icinga_zone',
];
protected $connection;
@ -62,7 +45,7 @@ class BranchStore
public function cloneBranchForSync(Branch $branch, $newName, $owner)
{
$this->runTransaction(function ($db) use ($branch, $newName, $owner) {
$tables = self::OBJECT_TABLES;
$tables = BranchSupport::OBJECT_TABLES;
$tables[] = self::TABLE_ACTIVITY;
$newBranch = $this->createBranchByName($newName, $owner);
$oldQuotedUuid = DbUtil::quoteBinaryCompat($branch->getUuid()->getBytes(), $db);
@ -105,7 +88,7 @@ class BranchStore
public function wipeBranch(Branch $branch, $after = null)
{
$this->runTransaction(function ($db) use ($branch, $after) {
$tables = self::OBJECT_TABLES;
$tables = BranchSupport::OBJECT_TABLES;
$tables[] = self::TABLE_ACTIVITY;
$quotedUuid = DbUtil::quoteBinaryCompat($branch->getUuid()->getBytes(), $db);
$where = $db->quoteInto('branch_uuid = ?', $quotedUuid);

View File

@ -7,21 +7,70 @@ use Icinga\Module\Director\Objects\SyncRule;
class BranchSupport
{
const BRANCHED_TABLE_PREFIX = 'branched_';
const TABLE_ICINGA_APIUSER = 'icinga_apiuser';
const TABLE_ICINGA_COMMAND = 'icinga_command';
const TABLE_ICINGA_DEPENDENCY = 'icinga_dependency';
const TABLE_ICINGA_ENDPOINT = 'icinga_endpoint';
const TABLE_ICINGA_HOST = 'icinga_host';
const TABLE_ICINGA_HOSTGROUP = 'icinga_hostgroup';
const TABLE_ICINGA_NOTIFICATION = 'icinga_notification';
const TABLE_ICINGA_SCHEDULED_DOWNTIME = 'icinga_scheduled_downtime';
const TABLE_ICINGA_SERVICE = 'icinga_service';
const TABLE_ICINGA_SERVICEGROUP = 'icinga_servicegroup';
const TABLE_ICINGA_TIMEPERIOD = 'icinga_timeperiod';
const TABLE_ICINGA_USER = 'icinga_user';
const TABLE_ICINGA_USERGROUP = 'icinga_usergroup';
const TABLE_ICINGA_ZONE = 'icinga_zone';
const BRANCHED_TABLE_ICINGA_APIUSER = self::BRANCHED_TABLE_PREFIX. self::TABLE_ICINGA_APIUSER;
const BRANCHED_TABLE_ICINGA_COMMAND = self::BRANCHED_TABLE_PREFIX. self::TABLE_ICINGA_COMMAND;
const BRANCHED_TABLE_ICINGA_DEPENDENCY = self::BRANCHED_TABLE_PREFIX. self::TABLE_ICINGA_DEPENDENCY;
const BRANCHED_TABLE_ICINGA_ENDPOINT = self::BRANCHED_TABLE_PREFIX. self::TABLE_ICINGA_ENDPOINT;
const BRANCHED_TABLE_ICINGA_HOST = self::BRANCHED_TABLE_PREFIX. self::TABLE_ICINGA_HOST;
const BRANCHED_TABLE_ICINGA_HOSTGROUP = self::BRANCHED_TABLE_PREFIX. self::TABLE_ICINGA_HOSTGROUP;
const BRANCHED_TABLE_ICINGA_NOTIFICATION = self::BRANCHED_TABLE_PREFIX. self::TABLE_ICINGA_NOTIFICATION;
const BRANCHED_TABLE_ICINGA_SCHEDULED_DOWNTIME = self::BRANCHED_TABLE_PREFIX. self::TABLE_ICINGA_SCHEDULED_DOWNTIME;
const BRANCHED_TABLE_ICINGA_SERVICE = self::BRANCHED_TABLE_PREFIX. self::TABLE_ICINGA_SERVICE;
const BRANCHED_TABLE_ICINGA_SERVICEGROUP = self::BRANCHED_TABLE_PREFIX. self::TABLE_ICINGA_SERVICEGROUP;
const BRANCHED_TABLE_ICINGA_TIMEPERIOD = self::BRANCHED_TABLE_PREFIX. self::TABLE_ICINGA_TIMEPERIOD;
const BRANCHED_TABLE_ICINGA_USER = self::BRANCHED_TABLE_PREFIX. self::TABLE_ICINGA_USER;
const BRANCHED_TABLE_ICINGA_USERGROUP = self::BRANCHED_TABLE_PREFIX. self::TABLE_ICINGA_USERGROUP;
const BRANCHED_TABLE_ICINGA_ZONE = self::BRANCHED_TABLE_PREFIX. self::TABLE_ICINGA_ZONE;
const OBJECT_TABLES = [
self::TABLE_ICINGA_APIUSER,
self::TABLE_ICINGA_COMMAND,
self::TABLE_ICINGA_DEPENDENCY,
self::TABLE_ICINGA_ENDPOINT,
self::TABLE_ICINGA_HOST,
self::TABLE_ICINGA_HOSTGROUP,
self::TABLE_ICINGA_NOTIFICATION,
self::TABLE_ICINGA_SCHEDULED_DOWNTIME,
self::TABLE_ICINGA_SERVICE,
self::TABLE_ICINGA_SERVICEGROUP,
self::TABLE_ICINGA_TIMEPERIOD,
self::TABLE_ICINGA_USER,
self::TABLE_ICINGA_USERGROUP,
self::TABLE_ICINGA_ZONE,
];
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',
self::BRANCHED_TABLE_ICINGA_APIUSER,
self::BRANCHED_TABLE_ICINGA_COMMAND,
self::BRANCHED_TABLE_ICINGA_DEPENDENCY,
self::BRANCHED_TABLE_ICINGA_ENDPOINT,
self::BRANCHED_TABLE_ICINGA_HOST,
self::BRANCHED_TABLE_ICINGA_HOSTGROUP,
self::BRANCHED_TABLE_ICINGA_NOTIFICATION,
self::BRANCHED_TABLE_ICINGA_SCHEDULED_DOWNTIME,
self::BRANCHED_TABLE_ICINGA_SERVICE,
self::BRANCHED_TABLE_ICINGA_SERVICEGROUP,
self::BRANCHED_TABLE_ICINGA_TIMEPERIOD,
self::BRANCHED_TABLE_ICINGA_USER,
self::BRANCHED_TABLE_ICINGA_USERGROUP,
self::BRANCHED_TABLE_ICINGA_ZONE,
];
public static function existsForTableName($table)