From 98cfcafdcdaab244b44881405dbbff7342347381 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 29 Aug 2022 08:55:46 +0200 Subject: [PATCH] BranchSupport: introduce new constants --- .../Branch/BranchModificationInspection.php | 24 +++--- library/Director/Db/Branch/BranchStore.php | 21 +---- library/Director/Db/Branch/BranchSupport.php | 77 +++++++++++++++---- 3 files changed, 79 insertions(+), 43 deletions(-) diff --git a/library/Director/Db/Branch/BranchModificationInspection.php b/library/Director/Db/Branch/BranchModificationInspection.php index 0faf2d28..0181b7db 100644 --- a/library/Director/Db/Branch/BranchModificationInspection.php +++ b/library/Director/Db/Branch/BranchModificationInspection.php @@ -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(); diff --git a/library/Director/Db/Branch/BranchStore.php b/library/Director/Db/Branch/BranchStore.php index 65b8f73c..78bc88ab 100644 --- a/library/Director/Db/Branch/BranchStore.php +++ b/library/Director/Db/Branch/BranchStore.php @@ -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); diff --git a/library/Director/Db/Branch/BranchSupport.php b/library/Director/Db/Branch/BranchSupport.php index dc8e81bb..2d9cf57e 100644 --- a/library/Director/Db/Branch/BranchSupport.php +++ b/library/Director/Db/Branch/BranchSupport.php @@ -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)