From fc3deb17f342f60aec28d3eb55809fdb5f8c408f Mon Sep 17 00:00:00 2001 From: rowan04 Date: Thu, 14 Sep 2023 13:24:18 +0000 Subject: [PATCH 1/5] Add space before and after '.' concatenator in sample data deploy scripts - not doing this produces a codacy/codeclimate fail --- .../deploy/AddCertificationStatuses.php | 6 ++--- lib/Doctrine/deploy/AddCountries.php | 6 ++--- lib/Doctrine/deploy/AddDowntimes.php | 7 +++--- lib/Doctrine/deploy/AddInfrastructures.php | 6 ++--- lib/Doctrine/deploy/AddNGIRoles.php | 4 ++-- lib/Doctrine/deploy/AddNGIs.php | 4 ++-- lib/Doctrine/deploy/AddProjectRoles.php | 4 ++-- lib/Doctrine/deploy/AddProjects.php | 4 ++-- lib/Doctrine/deploy/AddRoleTypes.php | 8 +++---- lib/Doctrine/deploy/AddScopes.php | 6 ++--- lib/Doctrine/deploy/AddServiceEndpoints.php | 4 ++-- lib/Doctrine/deploy/AddServiceGroups.php | 4 ++-- lib/Doctrine/deploy/AddServiceTypes.php | 6 ++--- lib/Doctrine/deploy/AddSiteRoles.php | 4 ++-- lib/Doctrine/deploy/AddUsers.php | 6 ++--- .../deploy/DeployRequiredDataRunner.php | 12 +++++----- .../deploy/DeploySampleDataRunner.php | 24 +++++++++---------- 17 files changed, 58 insertions(+), 57 deletions(-) diff --git a/lib/Doctrine/deploy/AddCertificationStatuses.php b/lib/Doctrine/deploy/AddCertificationStatuses.php index a3e3307df..260e619c3 100644 --- a/lib/Doctrine/deploy/AddCertificationStatuses.php +++ b/lib/Doctrine/deploy/AddCertificationStatuses.php @@ -1,7 +1,7 @@ persist($doctrineCertStat); } -$entityManager->flush(); \ No newline at end of file +$entityManager->flush(); diff --git a/lib/Doctrine/deploy/AddCountries.php b/lib/Doctrine/deploy/AddCountries.php index a43d33a74..c3a2bbe2e 100644 --- a/lib/Doctrine/deploy/AddCountries.php +++ b/lib/Doctrine/deploy/AddCountries.php @@ -1,7 +1,7 @@ persist($doctrineCountry); } -$entityManager->flush(); \ No newline at end of file +$entityManager->flush(); diff --git a/lib/Doctrine/deploy/AddDowntimes.php b/lib/Doctrine/deploy/AddDowntimes.php index ac4075e8b..93bda4aa6 100644 --- a/lib/Doctrine/deploy/AddDowntimes.php +++ b/lib/Doctrine/deploy/AddDowntimes.php @@ -1,8 +1,8 @@ getHostName()); + throw new Exception("More than duplicate 2 SEs found: " . + $services[0]->getHostName()); } $knownDup = false; diff --git a/lib/Doctrine/deploy/AddInfrastructures.php b/lib/Doctrine/deploy/AddInfrastructures.php index 71a618056..52ea04e5d 100644 --- a/lib/Doctrine/deploy/AddInfrastructures.php +++ b/lib/Doctrine/deploy/AddInfrastructures.php @@ -1,7 +1,7 @@ persist($doctrineInf); } -$entityManager->flush(); \ No newline at end of file +$entityManager->flush(); diff --git a/lib/Doctrine/deploy/AddNGIRoles.php b/lib/Doctrine/deploy/AddNGIRoles.php index 4b9de7882..722cfb4b7 100644 --- a/lib/Doctrine/deploy/AddNGIRoles.php +++ b/lib/Doctrine/deploy/AddNGIRoles.php @@ -1,7 +1,7 @@ persist($proj); -$entityManager->flush(); \ No newline at end of file +$entityManager->flush(); diff --git a/lib/Doctrine/deploy/AddRoleTypes.php b/lib/Doctrine/deploy/AddRoleTypes.php index 143585843..9ee135c04 100644 --- a/lib/Doctrine/deploy/AddRoleTypes.php +++ b/lib/Doctrine/deploy/AddRoleTypes.php @@ -1,7 +1,7 @@ flush(); \ No newline at end of file +$entityManager->flush(); diff --git a/lib/Doctrine/deploy/AddScopes.php b/lib/Doctrine/deploy/AddScopes.php index 1a23abeac..cec9d78c0 100644 --- a/lib/Doctrine/deploy/AddScopes.php +++ b/lib/Doctrine/deploy/AddScopes.php @@ -1,7 +1,7 @@ persist($doctrineScope); } -$entityManager->flush(); \ No newline at end of file +$entityManager->flush(); diff --git a/lib/Doctrine/deploy/AddServiceEndpoints.php b/lib/Doctrine/deploy/AddServiceEndpoints.php index 18cb4021e..5862bbf4a 100644 --- a/lib/Doctrine/deploy/AddServiceEndpoints.php +++ b/lib/Doctrine/deploy/AddServiceEndpoints.php @@ -1,7 +1,7 @@ persist($doctrineSe); $entityManager->persist($doctrineEndpointLocation); } -$entityManager->flush(); \ No newline at end of file +$entityManager->flush(); diff --git a/lib/Doctrine/deploy/AddServiceGroups.php b/lib/Doctrine/deploy/AddServiceGroups.php index 715baf169..006283e13 100644 --- a/lib/Doctrine/deploy/AddServiceGroups.php +++ b/lib/Doctrine/deploy/AddServiceGroups.php @@ -1,7 +1,7 @@ persist($doctrineSt); } -$entityManager->flush(); \ No newline at end of file +$entityManager->flush(); diff --git a/lib/Doctrine/deploy/AddSiteRoles.php b/lib/Doctrine/deploy/AddSiteRoles.php index b8fc466b0..a5ee9dfca 100644 --- a/lib/Doctrine/deploy/AddSiteRoles.php +++ b/lib/Doctrine/deploy/AddSiteRoles.php @@ -1,7 +1,7 @@ Date: Thu, 14 Sep 2023 14:05:13 +0000 Subject: [PATCH 2/5] Add space after if and foreach in sample data deploy scripts - to fix code style issues that get flagged by codacy/codeclimate --- .../deploy/AddCertificationStatuses.php | 7 ++- lib/Doctrine/deploy/AddCountries.php | 10 ++-- lib/Doctrine/deploy/AddDowntimes.php | 45 +++++++------- lib/Doctrine/deploy/AddInfrastructures.php | 7 ++- lib/Doctrine/deploy/AddNGIRoles.php | 29 +++++---- lib/Doctrine/deploy/AddNGIs.php | 4 +- lib/Doctrine/deploy/AddProjectRoles.php | 16 ++--- lib/Doctrine/deploy/AddRoleTypes.php | 4 +- lib/Doctrine/deploy/AddScopes.php | 5 +- lib/Doctrine/deploy/AddServiceEndpoints.php | 5 ++ lib/Doctrine/deploy/AddServiceGroups.php | 2 +- lib/Doctrine/deploy/AddServiceTypes.php | 9 +-- lib/Doctrine/deploy/AddSiteRoles.php | 39 ++++++------ lib/Doctrine/deploy/AddSites.php | 60 ++++++++++++------- lib/Doctrine/deploy/AddUsers.php | 4 ++ lib/Doctrine/deploy/AddUtils.php | 6 +- .../deploy/DeployRequiredDataRunner.php | 2 +- .../deploy/DeploySampleDataRunner.php | 2 +- 18 files changed, 149 insertions(+), 107 deletions(-) diff --git a/lib/Doctrine/deploy/AddCertificationStatuses.php b/lib/Doctrine/deploy/AddCertificationStatuses.php index 260e619c3..fb72cd961 100644 --- a/lib/Doctrine/deploy/AddCertificationStatuses.php +++ b/lib/Doctrine/deploy/AddCertificationStatuses.php @@ -9,14 +9,15 @@ $certStatsFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . "/CertificationStatuses.xml"; $certStats = simplexml_load_file($certStatsFileName); -foreach($certStats as $certStat) { +foreach ($certStats as $certStat) { $doctrineCertStat = new CertificationStatus(); $name = ""; - foreach($certStat as $key => $value) { - if($key == "name") { + foreach ($certStat as $key => $value) { + if ($key == "name") { $name = (string) $value; } } + $doctrineCertStat->setName($name); $entityManager->persist($doctrineCertStat); } diff --git a/lib/Doctrine/deploy/AddCountries.php b/lib/Doctrine/deploy/AddCountries.php index c3a2bbe2e..b57f26c11 100644 --- a/lib/Doctrine/deploy/AddCountries.php +++ b/lib/Doctrine/deploy/AddCountries.php @@ -10,18 +10,20 @@ $countriesFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . "/Countries.xml"; $countries = simplexml_load_file($countriesFileName); -foreach($countries as $country) { +foreach ($countries as $country) { $doctrineCountry = new Country(); $code = ""; $name = ""; - foreach($country as $key => $value) { - if($key == "name") { + foreach ($country as $key => $value) { + if ($key == "name") { $code = (string) $value; } - if($key == "description") { + + if ($key == "description") { $name = (string) $value; } } + $doctrineCountry->setName($name); $doctrineCountry->setCode($code); $entityManager->persist($doctrineCountry); diff --git a/lib/Doctrine/deploy/AddDowntimes.php b/lib/Doctrine/deploy/AddDowntimes.php index 93bda4aa6..aaa2deeab 100644 --- a/lib/Doctrine/deploy/AddDowntimes.php +++ b/lib/Doctrine/deploy/AddDowntimes.php @@ -47,15 +47,15 @@ // SE will be named in a different $downtimeXml that will duplicate // all the downtime specific fields. - foreach($downtimeXml->attributes() as $key => $value) { - if((string) $key == "ID") { + foreach ($downtimeXml->attributes() as $key => $value) { + if ((string) $key == "ID") { $promId = (int) $value; } } $downtime = null; // See if we've already entered a downtime with this prom ID - if(isset($allDowntimes[$promId])) { + if (isset($allDowntimes[$promId])) { // load $downtime from db by $promId rather than loading from global array // This assumes xml ID attribute (without 'G0' appended) is the same as // xml PRIMARY_KEY attribute. @@ -66,7 +66,7 @@ $downtime = $allDowntimes[$promId]; } - if(!isset($downtime)) { + if (!isset($downtime)) { // Create a new downtime, add the SE to it $downtime = newDowntime($downtimeXml); // Finds one or more SEs by hostname and service type @@ -77,7 +77,7 @@ // more than one SE (see the comment at the top of this file) // However if the downtime isn't yet created we always // link to the first SE found. - if(!isset($services[0])) { + if (!isset($services[0])) { throw new Exception("No SE found with " . "hostname " . $downtimeXml->HOSTNAME . " "); } @@ -94,10 +94,11 @@ $services = findSEs((string) $downtimeXml->HOSTNAME , (string) $downtimeXml->SERVICE_TYPE); - if(!isset($services[0])) { + if (!isset($services[0])) { throw new Exception("No SE found with " . "hostname " . $downtimeXml->HOSTNAME . " "); } + try { // TODO? - We should probably iterate each el and try to link each // to this DT. Will still need to throw alreadylinked exception when @@ -107,15 +108,15 @@ // (the duplicate SE count is tested for the expected 2 duplicates // below in catch block). $els = $services[0]->getEndpointLocations(); - if(count($els) > 1){ + if (count($els) > 1){ throw new LogicException('Coding error - there should only be one EL per Service'); } // Check this endpoint isn't already linked to downtime. // The els have already been persisted/flushed against // the DB and so already have IDs. - foreach($downtime->getEndpointLocations() as $existingEL) { - if($existingEL == $els[0]) { // their Ids will be the same + foreach ($downtime->getEndpointLocations() as $existingEL) { + if ($existingEL == $els[0]) { // their Ids will be the same throw new AlreadyLinkedException("Downtime {$downtime->getId()} is already " . "linked to el {$existingEL->getId()}"); } @@ -126,7 +127,7 @@ //$downtime->addService($services[0]); } catch (Exception $e) { - if($e instanceof AlreadyLinkedException) { + if ($e instanceof AlreadyLinkedException) { // Downtime is already linked to this SE // Check whether this exception is caused by a known issue @@ -134,7 +135,7 @@ // Issue is known if two SEs are found and the hostname is // a known duplicate $twoSes = false; - if(count($services) == 2) { + if (count($services) == 2) { $twoSes = true; } else { // we will have to deal with this case and link the @@ -143,8 +144,8 @@ } $knownDup = false; - foreach($duplicateSes as $dup) { - if($dup == $services[0]->getHostName()) { + foreach ($duplicateSes as $dup) { + if ($dup == $services[0]->getHostName()) { $knownDup = true; } } @@ -153,17 +154,17 @@ // where a downtime currently links to one SE that's a known // duplicate and it needs to link to the other (duplicated) SE. // The other SE will always be the second result in $services ([1]) - if($twoSes && $knownDup) { + if ($twoSes && $knownDup) { //$downtime->addService($services[1]); $els = $services[1]->getEndpointLocations(); // Check this SE isn't already registered - //foreach($downtime->getEndpointLocations() as $existingEL) { - // if($existingEL == $els[0]) { - // throw new AlreadyLinkedException("Downtime {$downtime->getId()} is already " - // . "linked to el {$existingEL->getId()}"); - // } + //foreach ($downtime->getEndpointLocations() as $existingEL) { + // if ($existingEL == $els[0]) { + // throw new AlreadyLinkedException("Downtime {$downtime->getId()} is already " + // . "linked to el {$existingEL->getId()}"); + // } //} // Bidirectional link the el and dt @@ -174,7 +175,7 @@ } } -foreach($allDowntimes as $downtime) { +foreach ($allDowntimes as $downtime) { $GLOBALS['entityManager']->persist($downtime); } @@ -188,7 +189,7 @@ // SimpleXML element. function newDowntime($downtimeXml) { $downtime = new Downtime(); - foreach($downtimeXml->attributes() as $key => $value) { + foreach ($downtimeXml->attributes() as $key => $value) { switch($key) { case "ID": $promId = (int) $value; @@ -205,7 +206,7 @@ function newDowntime($downtimeXml) { // Get the largest v4 downtime PK which is an integer appended by the string 'G0' // slice off the 'G0' and get the integer value. $v4pk = (int)substr($primaryKey, 0, strlen($primaryKey)-2); - if($v4pk > $GLOBALS['largestV4DowntimePK']){ + if ($v4pk > $GLOBALS['largestV4DowntimePK']){ $GLOBALS['largestV4DowntimePK'] = $v4pk; } diff --git a/lib/Doctrine/deploy/AddInfrastructures.php b/lib/Doctrine/deploy/AddInfrastructures.php index 52ea04e5d..a02550ff3 100644 --- a/lib/Doctrine/deploy/AddInfrastructures.php +++ b/lib/Doctrine/deploy/AddInfrastructures.php @@ -10,14 +10,15 @@ $infrastructureFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . "/Infrastructures.xml"; $infs = simplexml_load_file($infrastructureFileName); -foreach($infs as $xmlInf) { +foreach ($infs as $xmlInf) { $doctrineInf = new Infrastructure(); $name = ""; - foreach($xmlInf as $key => $value) { - if($key == "name") { + foreach ($xmlInf as $key => $value) { + if ($key == "name") { $name = (string) $value; } } + $doctrineInf->setName($name); $entityManager->persist($doctrineInf); } diff --git a/lib/Doctrine/deploy/AddNGIRoles.php b/lib/Doctrine/deploy/AddNGIRoles.php index 722cfb4b7..836385a41 100644 --- a/lib/Doctrine/deploy/AddNGIRoles.php +++ b/lib/Doctrine/deploy/AddNGIRoles.php @@ -6,10 +6,10 @@ $usersRolesFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . "/UsersAndRoles.xml"; $usersRoles = simplexml_load_file($usersRolesFileName); -foreach($usersRoles as $user) { - foreach($user->USER_ROLE as $role) { +foreach ($usersRoles as $user) { + foreach ($user->USER_ROLE as $role) { // Check for blank role, skip if it's blank - if((string) $role->USER_ROLE == "") { + if ((string) $role->USER_ROLE == "") { continue; } @@ -25,11 +25,12 @@ ->getResult(); // /* Error checking: ensure each role type refers to exactly // * one role type*/ - if(count($roleTypes) !== 1) { + if (count($roleTypes) !== 1) { throw new Exception(count($roleTypes) . " role types found with name: " . $role->USER_ROLE); } - foreach($roleTypes as $result) { + + foreach ($roleTypes as $result) { $roleType = $result; } @@ -41,17 +42,18 @@ // /* Error checking: ensure each "user" refers to exactly // * one user */ - if(count($users) !== 1) { + if (count($users) !== 1) { throw new Exception(count($users) . " users found with DN: " . $user->CERTDN); } - foreach($users as $doctrineUser) { + + foreach ($users as $doctrineUser) { $doctrineUser = $doctrineUser; } // Check for invalid NGIs and skip // typically these are decomissioned ROCs - if($role->ON_ENTITY == 'GridIreland' || $role->ON_ENTITY == 'NGS' + if ($role->ON_ENTITY == 'GridIreland' || $role->ON_ENTITY == 'NGS' || $role->ON_ENTITY == 'LondonT2' || $role->ON_ENTITY == 'Tier1A' || $role->ON_ENTITY == 'Tier1A') { continue; @@ -65,24 +67,25 @@ ->getResult(); // /* Error checking: ensure each "ngi" refers to exactly // * one ngi */ - if(count($ngis) !== 1) { + if (count($ngis) !== 1) { throw new Exception(count($ngis) . " ngis found name: " . $ngiName); } - foreach($ngis as $ngi) { + + foreach ($ngis as $ngi) { $ngi = $ngi; } //check that the role is not a duplicate (v4 data contaisn duplicates) $ExistingUserRoles = $doctrineUser->getRoles(); $thisIsADuplicateRole=false; - foreach($ExistingUserRoles as $role){ - if($role->getRoleType() == $roleType and $role->getOwnedEntity() == $ngi and $role->getStatus() == 'STATUS_GRANTED'){ + foreach ($ExistingUserRoles as $role){ + if ($role->getRoleType() == $roleType and $role->getOwnedEntity() == $ngi and $role->getStatus() == 'STATUS_GRANTED'){ $thisIsADuplicateRole = true; } } - if(!$thisIsADuplicateRole){ + if (!$thisIsADuplicateRole){ $doctrineRole = new Role($roleType, $doctrineUser, $ngi, 'STATUS_GRANTED'); $entityManager->persist($doctrineRole); } diff --git a/lib/Doctrine/deploy/AddNGIs.php b/lib/Doctrine/deploy/AddNGIs.php index 7839081c6..6063eb2e9 100644 --- a/lib/Doctrine/deploy/AddNGIs.php +++ b/lib/Doctrine/deploy/AddNGIs.php @@ -21,7 +21,7 @@ //Add Local Scope so specified NGI is not part of EGI project $localScope = $entityManager->getRepository('Scope')->findOneBy(array("name" => "Local")); -foreach($ngis as $xmlNgi) { +foreach ($ngis as $xmlNgi) { $doctrineNgi = new NGI(); $name = ""; $email = ""; @@ -82,7 +82,7 @@ $doctrineNgi->setSecurityEmail($securityEmail); // TODO - //if($cdateon == null) throw new Exception("CDATEON is null"); + //if ($cdateon == null) throw new Exception("CDATEON is null"); //$doctrineNgi->setCreationDate($cdateon); // if the NGI has id 67518 (NGI_HU) do not add it to EGI Project diff --git a/lib/Doctrine/deploy/AddProjectRoles.php b/lib/Doctrine/deploy/AddProjectRoles.php index 62c7577b6..2ef40444e 100644 --- a/lib/Doctrine/deploy/AddProjectRoles.php +++ b/lib/Doctrine/deploy/AddProjectRoles.php @@ -15,10 +15,10 @@ $usersRolesFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . "/UsersAndRoles.xml"; $usersRoles = simplexml_load_file($usersRolesFileName); -foreach($usersRoles as $user) { - foreach($user->USER_ROLE as $role) { +foreach ($usersRoles as $user) { + foreach ($user->USER_ROLE as $role) { // Check for blank role, skip if it's blank - if((string) $role->USER_ROLE == "") { + if ((string) $role->USER_ROLE == "") { continue; } @@ -34,11 +34,12 @@ ->getResult(); // /* Error checking: ensure each role type refers to exactly // * one role type*/ - if(count($roleTypes) !== 1) { + if (count($roleTypes) !== 1) { throw new Exception(count($roleTypes) . " role types found with name: " . $role->USER_ROLE); } - foreach($roleTypes as $result) { + + foreach ($roleTypes as $result) { $roleType = $result; } @@ -50,11 +51,12 @@ // /* Error checking: ensure each "user" refers to exactly // * one user */ - if(count($users) !== 1) { + if (count($users) !== 1) { throw new Exception(count($users) . " users found with DN: " . $user->CERTDN); } - foreach($users as $doctrineUser) { + + foreach ($users as $doctrineUser) { $doctrineUser = $doctrineUser; } diff --git a/lib/Doctrine/deploy/AddRoleTypes.php b/lib/Doctrine/deploy/AddRoleTypes.php index 9ee135c04..79977dad3 100644 --- a/lib/Doctrine/deploy/AddRoleTypes.php +++ b/lib/Doctrine/deploy/AddRoleTypes.php @@ -30,7 +30,7 @@ array("Regional Staff", "") ); -foreach($roleTypeArray as $roleType) { +foreach ($roleTypeArray as $roleType) { $rt = new RoleType($roleType[0], $roleType[1]); //$rt->setName($roleType[0]); //$rt->setClassification($roleType[1]); @@ -42,7 +42,7 @@ foreach ($roleTypeArray as $key => $value) { $rt = new RoleType($value); //echo $value; - if($value != RoleTypeName::GOCDB_ADMIN){ + if ($value != RoleTypeName::GOCDB_ADMIN){ $entityManager->persist($rt); } } diff --git a/lib/Doctrine/deploy/AddScopes.php b/lib/Doctrine/deploy/AddScopes.php index cec9d78c0..b4978afb6 100644 --- a/lib/Doctrine/deploy/AddScopes.php +++ b/lib/Doctrine/deploy/AddScopes.php @@ -10,11 +10,11 @@ $scopesFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . "/Scopes.xml"; $scopes = simplexml_load_file($scopesFileName); -foreach($scopes as $scope) { +foreach ($scopes as $scope) { $doctrineScope = new Scope(); $name = ""; $reserved = false; - foreach($scope as $key => $value) { + foreach ($scope as $key => $value) { switch ($key) { case "name": $name = (string) $value; @@ -24,6 +24,7 @@ break; } } + $doctrineScope->setName($name); $doctrineScope->setReserved($reserved); $entityManager->persist($doctrineScope); diff --git a/lib/Doctrine/deploy/AddServiceEndpoints.php b/lib/Doctrine/deploy/AddServiceEndpoints.php index 5862bbf4a..bf604dec4 100644 --- a/lib/Doctrine/deploy/AddServiceEndpoints.php +++ b/lib/Doctrine/deploy/AddServiceEndpoints.php @@ -17,6 +17,7 @@ if (count($scopes) !== 1) { throw new Exception(count($scopes) . " scopes found with short name: EGI"); } + foreach ($scopes as $egiScope) { $egiScope = $egiScope; } @@ -28,6 +29,7 @@ if (count($scopes) !== 1) { throw new Exception(count($scopes) . " scopes found with short name: Local"); } + foreach ($scopes as $localScope) { $localScope = $localScope; } @@ -46,9 +48,11 @@ throw new Exception(count($parentSites) . " sites found with short name: " . $xmlSe->SITENAME . ". SE hostname is " . $xmlSe->HOSTNAME); } + foreach ($parentSites as $result) { $parentSite = $result; } + $doctrineSe->setParentSiteDoJoin($parentSite); // get the hosting service type @@ -122,4 +126,5 @@ $entityManager->persist($doctrineSe); $entityManager->persist($doctrineEndpointLocation); } + $entityManager->flush(); diff --git a/lib/Doctrine/deploy/AddServiceGroups.php b/lib/Doctrine/deploy/AddServiceGroups.php index 006283e13..e5a87eec6 100644 --- a/lib/Doctrine/deploy/AddServiceGroups.php +++ b/lib/Doctrine/deploy/AddServiceGroups.php @@ -21,7 +21,7 @@ exit; } -foreach($sts as $st) { +foreach ($sts as $st) { $instance = new ServiceGroup(); $name = ""; $desc = ""; diff --git a/lib/Doctrine/deploy/AddServiceTypes.php b/lib/Doctrine/deploy/AddServiceTypes.php index ce8700576..dedf93294 100644 --- a/lib/Doctrine/deploy/AddServiceTypes.php +++ b/lib/Doctrine/deploy/AddServiceTypes.php @@ -10,19 +10,20 @@ $stFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . "/ServiceTypes.xml"; $sts = simplexml_load_file($stFileName); -foreach($sts as $st) { +foreach ($sts as $st) { $doctrineSt = new ServiceType(); $name = ""; $desc = ""; - foreach($st as $key => $value) { - if($key == "SERVICE_TYPE_NAME") { + foreach ($st as $key => $value) { + if ($key == "SERVICE_TYPE_NAME") { $name = (string) $value; } - if($key == "SERVICE_TYPE_DESC") { + if ($key == "SERVICE_TYPE_DESC") { $desc = (string) $value; } } + $doctrineSt->setName($name); $doctrineSt->setDescription($desc); $entityManager->persist($doctrineSt); diff --git a/lib/Doctrine/deploy/AddSiteRoles.php b/lib/Doctrine/deploy/AddSiteRoles.php index a5ee9dfca..357b6eb43 100644 --- a/lib/Doctrine/deploy/AddSiteRoles.php +++ b/lib/Doctrine/deploy/AddSiteRoles.php @@ -11,15 +11,15 @@ $usersRolesFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . "/UsersAndRoles.xml"; $usersRoles = simplexml_load_file($usersRolesFileName); -foreach($usersRoles as $user) { - foreach($user->USER_ROLE as $role) { +foreach ($usersRoles as $user) { + foreach ($user->USER_ROLE as $role) { // Check for blank role, skip if it's blank - if((string) $role->USER_ROLE == "") { + if ((string) $role->USER_ROLE == "") { continue; } // Skip all non-site roles - if((string) $role->ENTITY_TYPE !== "site") { + if ((string) $role->ENTITY_TYPE !== "site") { continue; } @@ -31,14 +31,16 @@ ->getResult(); // /* Error checking: ensure each role type refers to exactly // * one role type*/ - if(count($roleTypes) !== 1) { + if (count($roleTypes) !== 1) { throw new Exception(count($roleTypes) . " role types found with name: " . $role->USER_ROLE); } - foreach($roleTypes as $result) { + + foreach ($roleTypes as $result) { $roleType = $result; } - if(!($roleType instanceof RoleType)) { + + if (!($roleType instanceof RoleType)) { throw new Exception("Not a doctrine role type"); } @@ -50,22 +52,22 @@ // /* Error checking: ensure each "user" refers to exactly // * one user */ - if(count($users) !== 1) { + if (count($users) !== 1) { throw new Exception(count($users) . " users found with DN: " . $user->CERTDN); } - foreach($users as $doctrineUser) { + foreach ($users as $doctrineUser) { $doctrineUser = $doctrineUser; } - if(!($doctrineUser instanceof User)) { + if (!($doctrineUser instanceof User)) { throw new Exception("Not a doctrine user"); } // Check for invalid sites and skip adding this role // typically these sites don't have an NGI, country or production status - if(isBad((string) $role->ON_ENTITY)) { + if (isBad((string) $role->ON_ENTITY)) { continue; } @@ -76,30 +78,33 @@ ->getResult(); // /* Error checking: ensure each "site" refers to exactly // * one site */ - if(count($sites) !== 1) { + if (count($sites) !== 1) { throw new Exception(count($sites) . " sites found with short name: " . $role->ON_ENTITY); } - foreach($sites as $doctrineSite) { + + foreach ($sites as $doctrineSite) { $doctrineSite = $doctrineSite; } - if(!($doctrineSite instanceof Site)) { + + if (!($doctrineSite instanceof Site)) { throw new Exception("Not a doctrine site"); } //check that the role is not a duplicate (v4 data contaisn duplicates) $ExistingUserRoles = $doctrineUser->getRoles(); $thisIsADuplicateRole=false; - foreach($ExistingUserRoles as $role){ - if($role->getRoleType() == $roleType and $role->getOwnedEntity() == $doctrineSite and $role->getStatus() == 'STATUS_GRANTED'){ + foreach ($ExistingUserRoles as $role){ + if ($role->getRoleType() == $roleType and $role->getOwnedEntity() == $doctrineSite and $role->getStatus() == 'STATUS_GRANTED'){ $thisIsADuplicateRole = true; } } - if(!$thisIsADuplicateRole){ + if (!$thisIsADuplicateRole){ $doctrineRole = new Role($roleType, $doctrineUser, $doctrineSite, 'STATUS_GRANTED'); $entityManager->persist($doctrineRole); } } } + $entityManager->flush(); diff --git a/lib/Doctrine/deploy/AddSites.php b/lib/Doctrine/deploy/AddSites.php index c6640e32a..9a339c115 100644 --- a/lib/Doctrine/deploy/AddSites.php +++ b/lib/Doctrine/deploy/AddSites.php @@ -13,14 +13,14 @@ $xmlCertStatusLinkDates = simplexml_load_file(__DIR__ . "/" . $GLOBALS['dataDir'] . "/CertStatusDate.xml"); $largestV4SitePk = 0; -foreach($sites as $xmlSite) { +foreach ($sites as $xmlSite) { // Check whether this site has a larger v4 primary key // than any other recorded so far $v4pkGO = trim((string) $xmlSite->PRIMARY_KEY); // isolate just the number part (slice the 'GO' off the end) $v4pk = (int)substr($v4pkGO, 0, strlen($v4pkGO)-2); - if($v4pk > $largestV4SitePk){ + if ($v4pk > $largestV4SitePk){ $largestV4SitePk = $v4pk; } @@ -35,10 +35,10 @@ $doctrineSite->setTelephone((string) $xmlSite->CONTACT_TEL); $doctrineSite->setGiisUrl((string) $xmlSite->GIIS_URL); $doctrineSite->setTimezoneId((string) $xmlSite->TIMEZONE); - if(strlen((string)$xmlSite->LATITUDE) > 0){ + if (strlen((string)$xmlSite->LATITUDE) > 0){ $doctrineSite->setLatitude((float)$xmlSite->LATITUDE); } - if(strlen((string)$xmlSite->LONGITUDE) > 0){ + if (strlen((string)$xmlSite->LONGITUDE) > 0){ $doctrineSite->setLongitude((float)$xmlSite->LONGITUDE); } $doctrineSite->setCsirtEmail((string) $xmlSite->CSIRT_EMAIL); @@ -56,15 +56,18 @@ $parentNgis = $entityManager->createQuery($dql) ->setParameter(1, (string) $xmlSite->ROC) ->getResult(); + // /* Error checking: ensure each SE's "parent ngi" refers to exactly // * one ngi */ - if(count($parentNgis) !== 1) { + if (count($parentNgis) !== 1) { throw new Exception(count($parentNgis) . " NGIs found with name: " . $xmlSite->ROC); } - foreach($parentNgis as $result) { + + foreach ($parentNgis as $result) { $parentNgi = $result; } + $doctrineSite->setNgiDoJoin($parentNgi); // get the target infrastructure @@ -72,15 +75,18 @@ $infs = $entityManager->createQuery($dql) ->setParameter('name', (string) $xmlSite->PRODUCTION_INFRASTRUCTURE) ->getResult(); + // /* Error checking: ensure each SE's "PRODUCTION_INFRASTRUCTURE" refers to exactly // * one PRODUCTION_INFRASTRUCTURE */ - if(count($infs) !== 1) { + if (count($infs) !== 1) { throw new Exception(count($infs) . " Infrastructures found with name: " . $xmlSite->PRODUCTION_INFRASTRUCTURE); } - foreach($infs as $inf) { + + foreach ($infs as $inf) { $inf = $inf; } + $doctrineSite->setInfrastructure($inf); // get the cert status @@ -88,15 +94,18 @@ $certStatuses = $entityManager->createQuery($dql) ->setParameter(1, (string) $xmlSite->CERTIFICATION_STATUS) ->getResult(); + /* Error checking: ensure each Site's "cert status" refers to exactly * one cert status */ - if(count($certStatuses) !== 1) { + if (count($certStatuses) !== 1) { throw new Exception(count($certStatuses) . " cert statuses found with name: " . $xmlSite->CERTIFICATION_STATUS); } - foreach($certStatuses as $certStatus) { + + foreach ($certStatuses as $certStatus) { $certStatus = $certStatus; } + $doctrineSite->setCertificationStatus($certStatus); $doctrineSite->addScope(getScope($entityManager, (string) $xmlSite->SCOPE)); @@ -106,15 +115,18 @@ $countries = $entityManager->createQuery($dql) ->setParameter(1, (string) $xmlSite->COUNTRY) ->getResult(); + /* Error checking: ensure each country refers to exactly * one country */ - if(count($countries) !== 1) { + if (count($countries) !== 1) { throw new Exception(count($countries) . " country found with name: " . $xmlSite->COUNTRY); } - foreach($countries as $country) { + + foreach ($countries as $country) { $country = $country; } + $doctrineSite->setCountry($country); @@ -123,10 +135,11 @@ $tiers = $entityManager->createQuery($dql) ->setParameter(1, (string) $xmlSite->TIER) ->getResult(); + /* Error checking: ensure each tier refers to exactly * one TIER */ - if(count($tiers) == 1) { - foreach($tiers as $tier) { + if (count($tiers) == 1) { + foreach ($tiers as $tier) { $tier = $tier; } @@ -138,10 +151,11 @@ $subGrids = $entityManager->createQuery($dql) ->setParameter(1, (string) $xmlSite->SUBGRID) ->getResult(); + /* Error checking: ensure each subgrid refers to exactly * one subgrid */ - if(count($subGrids) == 1) { - foreach($subGrids as $subGrid) { + if (count($subGrids) == 1) { + foreach ($subGrids as $subGrid) { $subGrid = $subGrid; } @@ -159,17 +173,17 @@ // The date of the CURRENT certStatus in v4 is recorded as // a link/linkType object using the dateOn property. For simplicity, we // store this date as an attribute on the Site. - foreach($xmlCertStatusLinkDates as $xmlCertStatusLinkDate){ + foreach ($xmlCertStatusLinkDates as $xmlCertStatusLinkDate){ $targetSiteName = (string) $xmlCertStatusLinkDate->name; // only interested in the current site - if($targetSiteName == $doctrineSite->getShortName()){ + if ($targetSiteName == $doctrineSite->getShortName()){ // '01-JUL-13 11.09.10.000000 AM' which has the php datetime // format of 'd-M-y H.i.s A' provided we trim off the '.000000' (millisecs) // Note, '.000000' is present in all the elements. $xmlLinkDateString = (string) $xmlCertStatusLinkDate->cert_date; $xmlLinkDateString = preg_replace('/\.000000/', "", $xmlLinkDateString); $linkDate = \DateTime::createFromFormat('d-M-y H.i.s A', $xmlLinkDateString, new \DateTimeZone('UTC')); - if(!$linkDate) { + if (!$linkDate) { throw new Exception("Can't parse date/time " . $xmlLinkDateString . " for site " . $doctrineSite->getShortName() . ". Correct format: 27-JUL-11 02.02.03 PM" ); } @@ -189,10 +203,10 @@ // necessarily correspond with the date of the CURRENT certification status. // Rather, the date of the CURRENT certStatus in v4 is recorded as // a link/linkType object using the dateOn property. - foreach($xmlCertStatusChanges as $xmlCertStatusChange){ + foreach ($xmlCertStatusChanges as $xmlCertStatusChange){ $targetSiteName = (string) $xmlCertStatusChange->SITE; // only interested in the current site - if($targetSiteName == $doctrineSite->getShortName()){ + if ($targetSiteName == $doctrineSite->getShortName()){ $doctrineCertStatusChangeLog = new \CertificationStatusLog(); $doctrineCertStatusChangeLog->setAddedBy((string) $xmlCertStatusChange->CHANGED_BY); $doctrineCertStatusChangeLog->setOldStatus((string) $xmlCertStatusChange->OLD_STATUS); @@ -211,11 +225,11 @@ // echo "\nPersisting Sites"; // $i = 0; -// foreach($allSites as $site) { +// foreach ($allSites as $site) { // $i++; // $entityManager->persist($site); // // Flush periodically to free memory. -// if($i % 10000 == 0) { +// if ($i % 10000 == 0) { // echo "."; // $entityManager->flush(); // } diff --git a/lib/Doctrine/deploy/AddUsers.php b/lib/Doctrine/deploy/AddUsers.php index 4a1de5421..8ed0e8f5f 100644 --- a/lib/Doctrine/deploy/AddUsers.php +++ b/lib/Doctrine/deploy/AddUsers.php @@ -26,6 +26,7 @@ if (isset($idStrings[$idString])) { continue; } + $idStrings[$idString] = true; $doctrineUser = new \User(); @@ -53,9 +54,11 @@ throw new \Exception(count($homeSites) . " sites found with short name: " . $user->HOMESITE . ". user DN is " . $user->CERTDN); } + foreach ($homeSites as $result) { $homeSite = $result; } + $doctrineUser->setHomeSiteDoJoin($homeSite); } @@ -63,6 +66,7 @@ $em->flush(); $serv->addUserIdentifier($doctrineUser, $identifierArr, $doctrineUser); } + $em->getConnection()->commit(); } catch (\Exception $e) { $em->getConnection()->rollback(); diff --git a/lib/Doctrine/deploy/AddUtils.php b/lib/Doctrine/deploy/AddUtils.php index a029702f6..1ab6ea264 100644 --- a/lib/Doctrine/deploy/AddUtils.php +++ b/lib/Doctrine/deploy/AddUtils.php @@ -41,12 +41,13 @@ function isBad($site) { , 'scgNUIGie', 'giITTAie', 'obsARMuk', 'giHECie', 'giRCSIie' , 'giDCUie'); - if(sizeof(array_intersect(array($site), $badSites)) == 0) { + if (sizeof(array_intersect(array($site), $badSites)) == 0) { return false; } else { return true; } } + /** * Return a scope object given a scope name * @param EntityManager $entityManager @@ -59,9 +60,10 @@ function getScope($entityManager, $scope) { $scopes = $entityManager->createQuery($dql) ->setParameter(1, $scope) ->getResult(); + /* Error checking: ensure each Site's "SCOPE" refers to exactly * one SCOPE */ - if(count($scopes) !== 1) { + if (count($scopes) !== 1) { throw new Exception(count($scopes) . " SCOPEs found with name: " . $scope); } diff --git a/lib/Doctrine/deploy/DeployRequiredDataRunner.php b/lib/Doctrine/deploy/DeployRequiredDataRunner.php index 1da3f354e..eee338d98 100644 --- a/lib/Doctrine/deploy/DeployRequiredDataRunner.php +++ b/lib/Doctrine/deploy/DeployRequiredDataRunner.php @@ -15,7 +15,7 @@ require_once __DIR__ . "/AddUtils.php"; -if(isset($argv[1])) { +if (isset($argv[1])) { $GLOBALS['dataDir'] = $argv[1]; } else { die("Please specify your data directory (requiredData) \n"); diff --git a/lib/Doctrine/deploy/DeploySampleDataRunner.php b/lib/Doctrine/deploy/DeploySampleDataRunner.php index 2141ab351..97d80a44f 100644 --- a/lib/Doctrine/deploy/DeploySampleDataRunner.php +++ b/lib/Doctrine/deploy/DeploySampleDataRunner.php @@ -16,7 +16,7 @@ require_once __DIR__ . "/AddUtils.php"; -if(isset($argv[1])) { +if (isset($argv[1])) { $GLOBALS['dataDir'] = $argv[1]; } else { die("Please specify your data directory (sampleData) \n"); From 42764e816d3bc09173980b7b59d421937f2ea37c Mon Sep 17 00:00:00 2001 From: rowan04 Date: Thu, 21 Sep 2023 15:28:20 +0000 Subject: [PATCH 3/5] Split up long lines in sample data deploy scripts - lines over 80 characters flag codeclimate fails - this splits up long lines in the deploy directory --- .../deploy/AddCertificationStatuses.php | 7 +- lib/Doctrine/deploy/AddCountries.php | 7 +- lib/Doctrine/deploy/AddDowntimes.php | 88 ++++++++------- lib/Doctrine/deploy/AddInfrastructures.php | 7 +- lib/Doctrine/deploy/AddNGIRoles.php | 35 ++++-- lib/Doctrine/deploy/AddNGIs.php | 23 ++-- lib/Doctrine/deploy/AddProjectRoles.php | 36 +++--- lib/Doctrine/deploy/AddScopes.php | 7 +- lib/Doctrine/deploy/AddServiceEndpoints.php | 37 ++++--- lib/Doctrine/deploy/AddServiceGroupRoles.php | 6 +- lib/Doctrine/deploy/AddServiceTypes.php | 4 +- lib/Doctrine/deploy/AddSiteRoles.php | 49 ++++++--- lib/Doctrine/deploy/AddSites.php | 103 +++++++++++------- lib/Doctrine/deploy/AddUsers.php | 24 ++-- lib/Doctrine/deploy/AddUtils.php | 59 +++++----- 15 files changed, 297 insertions(+), 195 deletions(-) diff --git a/lib/Doctrine/deploy/AddCertificationStatuses.php b/lib/Doctrine/deploy/AddCertificationStatuses.php index fb72cd961..a95afedc9 100644 --- a/lib/Doctrine/deploy/AddCertificationStatuses.php +++ b/lib/Doctrine/deploy/AddCertificationStatuses.php @@ -2,11 +2,12 @@ require_once __DIR__ . "/../bootstrap.php"; require_once __DIR__ . "/AddUtils.php"; -/* AddNGIs.php: Loads a list of cert statuses from an XML file and inserts them into - * the doctrine prototype. +/* AddNGIs.php: Loads a list of cert statuses from an XML file and + * inserts them into the doctrine prototype. * XML format is the xml input format of the cert status seed data */ -$certStatsFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . "/CertificationStatuses.xml"; +$certStatsFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . + "/CertificationStatuses.xml"; $certStats = simplexml_load_file($certStatsFileName); foreach ($certStats as $certStat) { diff --git a/lib/Doctrine/deploy/AddCountries.php b/lib/Doctrine/deploy/AddCountries.php index b57f26c11..f7dffc646 100644 --- a/lib/Doctrine/deploy/AddCountries.php +++ b/lib/Doctrine/deploy/AddCountries.php @@ -3,11 +3,12 @@ require_once __DIR__ . "/../bootstrap.php"; require_once __DIR__ . "/AddUtils.php"; -/* AddCountries.php: Loads a list of countries from an XML file and inserts them into - * the doctrine prototype. +/* AddCountries.php: Loads a list of countries from an XML file and + * inserts them into the doctrine prototype. */ -$countriesFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . "/Countries.xml"; +$countriesFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . + "/Countries.xml"; $countries = simplexml_load_file($countriesFileName); foreach ($countries as $country) { diff --git a/lib/Doctrine/deploy/AddDowntimes.php b/lib/Doctrine/deploy/AddDowntimes.php index aaa2deeab..5d79a9eb7 100644 --- a/lib/Doctrine/deploy/AddDowntimes.php +++ b/lib/Doctrine/deploy/AddDowntimes.php @@ -17,15 +17,15 @@ // this out. // // The duplicates are all SRM services apart from cert-ce-01 (CE) and -// hyx.grid.icm.edu.pl (Unicore6.StorageManagement) - something may be wrong with the -// SRM service type the PROM GOCDB causing duplicate service eps -// to be registered. Either that or there's a business reason +// hyx.grid.icm.edu.pl (Unicore6.StorageManagement) - something may be +// wrong with the SRM service type the PROM GOCDB causing duplicate +// service eps to be registered. Either that or there's a business reason // for registering two. $duplicateSes = array ("se.reef.man.poznan.pl", "lcg05.sinp.msu.ru", - "grid-se.ii.edu.mk", - "storage01.lcg.cscs.ch", "grid002.ics.forth.gr", - "eymir.grid.metu.edu.tr", "torik1.ulakbim.gov.tr", - "hyx.grid.icm.edu.pl", "cert-ce-01.cnaf.infn.it", // cert-ce-01 is a CE, not SRM + "grid-se.ii.edu.mk", "storage01.lcg.cscs.ch", + "grid002.ics.forth.gr", "eymir.grid.metu.edu.tr", + "torik1.ulakbim.gov.tr", "hyx.grid.icm.edu.pl", + "cert-ce-01.cnaf.infn.it", // cert-ce-01 is a CE, not SRM "se01.mosigrid.utcluj.ro"); // Hack: the above SEs appear twice with the same service type. (nightmare) // However in most cases both SEs share the same downtimes... @@ -37,15 +37,16 @@ $allDowntimes = array(); -$downtimeFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . "/Downtimes.xml"; +$downtimeFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . + "/Downtimes.xml"; $downtimes = simplexml_load_file($downtimeFileName); $largestV4DowntimePK = 0; foreach ($downtimes as $downtimeXml) { // Each "downtimeXML" element is one SE's downtime. // If a single downtime affects many SEs, each - // SE will be named in a different $downtimeXml that will duplicate - // all the downtime specific fields. + // SE will be named in a different $downtimeXml that will + // duplicate all the downtime specific fields. foreach ($downtimeXml->attributes() as $key => $value) { if ((string) $key == "ID") { @@ -56,11 +57,12 @@ $downtime = null; // See if we've already entered a downtime with this prom ID if (isset($allDowntimes[$promId])) { - // load $downtime from db by $promId rather than loading from global array - // This assumes xml ID attribute (without 'G0' appended) is the same as - // xml PRIMARY_KEY attribute. + // load $downtime from db by $promId rather than loading from global + // array. This assumes xml ID attribute (without 'G0' appended) is + // the same as xml PRIMARY_KEY attribute. // - // $downtime = $entityManager->createQuery("select d FROM Downtime d WHERE d.primaryKey = ?1") + // $downtime = $entityManager->createQuery("select d FROM Downtime " . + // "d WHERE d.primaryKey = ?1") // ->setParameter(1, (string) $promId.'G0') // ->getResult(); $downtime = $allDowntimes[$promId]; @@ -70,16 +72,16 @@ // Create a new downtime, add the SE to it $downtime = newDowntime($downtimeXml); // Finds one or more SEs by hostname and service type - $services = findSEs((string) $downtimeXml->HOSTNAME - , (string) $downtimeXml->SERVICE_TYPE); + $services = findSEs((string) $downtimeXml->HOSTNAME, + (string) $downtimeXml->SERVICE_TYPE); // There are some edge cases where findSEs returns // more than one SE (see the comment at the top of this file) // However if the downtime isn't yet created we always // link to the first SE found. if (!isset($services[0])) { - throw new Exception("No SE found with " - . "hostname " . $downtimeXml->HOSTNAME . " "); + throw new Exception("No SE found with hostname " . + $downtimeXml->HOSTNAME . " "); } // Bidirectional link the el and dt @@ -91,25 +93,26 @@ $GLOBALS['allDowntimes'][$promId] = $downtime; } else { // Find the SE and link it to the downtime - $services = findSEs((string) $downtimeXml->HOSTNAME - , (string) $downtimeXml->SERVICE_TYPE); + $services = findSEs((string) $downtimeXml->HOSTNAME, + (string) $downtimeXml->SERVICE_TYPE); if (!isset($services[0])) { - throw new Exception("No SE found with " - . "hostname " . $downtimeXml->HOSTNAME . " "); + throw new Exception("No SE found with hostname " . + $downtimeXml->HOSTNAME . " "); } try { // TODO? - We should probably iterate each el and try to link each - // to this DT. Will still need to throw alreadylinked exception when - // trying to link a SE that is already linked to the downtime - // in order to detect the SE duplicates. But iterating may only be necessary - // if it emerges that there are instances of more than 2 duplicate SEs - // (the duplicate SE count is tested for the expected 2 duplicates - // below in catch block). + // to this DT. Will still need to throw alreadylinked exception + // when trying to link a SE that is already linked to the downtime + // in order to detect the SE duplicates. But iterating may only be + // necessary if it emerges that there are instances of more than 2 + // duplicate SEs (the duplicate SE count is tested for the expected + // 2 duplicates below in catch block). $els = $services[0]->getEndpointLocations(); if (count($els) > 1){ - throw new LogicException('Coding error - there should only be one EL per Service'); + throw new LogicException('Coding error - there should only ' . + 'be one EL per Service'); } // Check this endpoint isn't already linked to downtime. @@ -117,8 +120,9 @@ // the DB and so already have IDs. foreach ($downtime->getEndpointLocations() as $existingEL) { if ($existingEL == $els[0]) { // their Ids will be the same - throw new AlreadyLinkedException("Downtime {$downtime->getId()} is already " - . "linked to el {$existingEL->getId()}"); + throw new AlreadyLinkedException("Downtime " . + "{$downtime->getId()} is already linked to el " . + "{$existingEL->getId()}"); } } @@ -150,10 +154,11 @@ } } - // If the above two tests are true then we've hit an edge case - // where a downtime currently links to one SE that's a known - // duplicate and it needs to link to the other (duplicated) SE. - // The other SE will always be the second result in $services ([1]) + // If the above two tests are true then we've hit an edge + // case where a downtime currently links to one SE that's + // a known duplicate and it needs to link to the other + // (duplicated) SE. The other SE will always be the second + // result in $services ([1]) if ($twoSes && $knownDup) { //$downtime->addService($services[1]); $els = $services[1]->getEndpointLocations(); @@ -162,8 +167,9 @@ // Check this SE isn't already registered //foreach ($downtime->getEndpointLocations() as $existingEL) { // if ($existingEL == $els[0]) { - // throw new AlreadyLinkedException("Downtime {$downtime->getId()} is already " - // . "linked to el {$existingEL->getId()}"); + // throw new AlreadyLinkedException("Downtime " . + // "{$downtime->getId()} is already linked to el " . + // "{$existingEL->getId()}"); // } //} @@ -185,8 +191,8 @@ print_r($e); } -// Creates a new Doctrine downtime entity from the output of a get_downtime -// SimpleXML element. +// Creates a new Doctrine downtime entity from the output of a +// get_downtime SimpleXML element. function newDowntime($downtimeXml) { $downtime = new Downtime(); foreach ($downtimeXml->attributes() as $key => $value) { @@ -203,8 +209,8 @@ function newDowntime($downtimeXml) { } } - // Get the largest v4 downtime PK which is an integer appended by the string 'G0' - // slice off the 'G0' and get the integer value. + // Get the largest v4 downtime PK which is an integer appended by + // the string 'G0' slice off the 'G0' and get the integer value. $v4pk = (int)substr($primaryKey, 0, strlen($primaryKey)-2); if ($v4pk > $GLOBALS['largestV4DowntimePK']){ $GLOBALS['largestV4DowntimePK'] = $v4pk; diff --git a/lib/Doctrine/deploy/AddInfrastructures.php b/lib/Doctrine/deploy/AddInfrastructures.php index a02550ff3..c2814b76c 100644 --- a/lib/Doctrine/deploy/AddInfrastructures.php +++ b/lib/Doctrine/deploy/AddInfrastructures.php @@ -3,11 +3,12 @@ require_once __DIR__ . "/../bootstrap.php"; require_once __DIR__ . "/AddUtils.php"; -/* AddNGIs.php: Loads a list of infrastructures from an XML file and inserts them into - * the doctrine prototype. +/* AddNGIs.php: Loads a list of infrastructures from an XML file and + * inserts them into the doctrine prototype. * XML format is the xml input production status format. */ -$infrastructureFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . "/Infrastructures.xml"; +$infrastructureFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . + "/Infrastructures.xml"; $infs = simplexml_load_file($infrastructureFileName); foreach ($infs as $xmlInf) { diff --git a/lib/Doctrine/deploy/AddNGIRoles.php b/lib/Doctrine/deploy/AddNGIRoles.php index 836385a41..6705d9cd6 100644 --- a/lib/Doctrine/deploy/AddNGIRoles.php +++ b/lib/Doctrine/deploy/AddNGIRoles.php @@ -3,7 +3,8 @@ require_once __DIR__ . "/../bootstrap.php"; require_once __DIR__ . "/AddUtils.php"; -$usersRolesFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . "/UsersAndRoles.xml"; +$usersRolesFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . + "/UsersAndRoles.xml"; $usersRoles = simplexml_load_file($usersRolesFileName); foreach ($usersRoles as $user) { @@ -21,13 +22,14 @@ // get roletype entity $dql = "SELECT rt FROM RoleType rt WHERE rt.name = :roleType"; $roleTypes = $entityManager->createQuery($dql) - ->setParameter(':roleType', (string) $role->USER_ROLE) - ->getResult(); + ->setParameter(':roleType', + (string) $role->USER_ROLE) + ->getResult(); // /* Error checking: ensure each role type refers to exactly // * one role type*/ if (count($roleTypes) !== 1) { - throw new Exception(count($roleTypes) . " role types found with name: " . - $role->USER_ROLE); + throw new Exception(count($roleTypes) . " role types found " . + "with name: " . $role->USER_ROLE); } foreach ($roleTypes as $result) { @@ -35,10 +37,12 @@ } // Get user entity - $dql = "SELECT u FROM User u JOIN u.userIdentifiers up WHERE up.keyValue = :keyValue"; + $dql = "SELECT u FROM User u JOIN u.userIdentifiers " . + "up WHERE up.keyValue = :keyValue"; $users = $entityManager->createQuery($dql) - ->setParameter('keyValue', trim((string) $user->CERTDN)) - ->getResult(); + ->setParameter('keyValue', + trim((string) $user->CERTDN)) + ->getResult(); // /* Error checking: ensure each "user" refers to exactly // * one user */ @@ -63,8 +67,8 @@ $ngiName = (string) $role->ON_ENTITY; $dql = "SELECT n FROM NGI n WHERE n.name = :ngi"; $ngis = $entityManager->createQuery($dql) - ->setParameter('ngi', $ngiName) - ->getResult(); + ->setParameter('ngi', $ngiName) + ->getResult(); // /* Error checking: ensure each "ngi" refers to exactly // * one ngi */ if (count($ngis) !== 1) { @@ -80,13 +84,20 @@ $ExistingUserRoles = $doctrineUser->getRoles(); $thisIsADuplicateRole=false; foreach ($ExistingUserRoles as $role){ - if ($role->getRoleType() == $roleType and $role->getOwnedEntity() == $ngi and $role->getStatus() == 'STATUS_GRANTED'){ + if ($role->getRoleType() == $roleType + and $role->getOwnedEntity() == $ngi + and $role->getStatus() == 'STATUS_GRANTED') { $thisIsADuplicateRole = true; } } if (!$thisIsADuplicateRole){ - $doctrineRole = new Role($roleType, $doctrineUser, $ngi, 'STATUS_GRANTED'); + $doctrineRole = new Role( + $roleType, + $doctrineUser, + $ngi, + 'STATUS_GRANTED' + ); $entityManager->persist($doctrineRole); } } diff --git a/lib/Doctrine/deploy/AddNGIs.php b/lib/Doctrine/deploy/AddNGIs.php index 6063eb2e9..bd50ed035 100644 --- a/lib/Doctrine/deploy/AddNGIs.php +++ b/lib/Doctrine/deploy/AddNGIs.php @@ -4,8 +4,8 @@ require_once __DIR__ . "/AddUtils.php"; /** - * AddNGIs.php: Loads a list of NGIs from an XML file and inserts them into - * the doctrine prototype. + * AddNGIs.php: Loads a list of NGIs from an XML file and + * inserts them into the doctrine prototype. * XML format is the output from get_roc_list PI query. */ @@ -13,13 +13,16 @@ $ngis = simplexml_load_file($ngisFileName); // Find the EGI project object -$egiProject = $entityManager->getRepository('Project')->findOneBy(array("name" => "EGI")); +$egiProject = $entityManager->getRepository('Project') + ->findOneBy(array("name" => "EGI")); //Find the EGI scope tag -$egiScope = $entityManager->getRepository('Scope')->findOneBy(array("name" => "EGI")); +$egiScope = $entityManager->getRepository('Scope') + ->findOneBy(array("name" => "EGI")); //Add Local Scope so specified NGI is not part of EGI project -$localScope = $entityManager->getRepository('Scope')->findOneBy(array("name" => "Local")); +$localScope = $entityManager->getRepository('Scope') + ->findOneBy(array("name" => "Local")); foreach ($ngis as $xmlNgi) { $doctrineNgi = new NGI(); @@ -61,14 +64,18 @@ } if ((string) $key == "CDATEON") { - // $cdateonString has the following format: '12-JAN-10 14.12.56.000000' + // $cdateonString has the following format: + // '12-JAN-10 14.12.56.000000' $cdateonString = (string) $value; //convert to date time - $creationDate = DateTime::createFromFormat('d-M-y G.i.s.u', $cdateonString, new DateTimeZone('UTC')); + $creationDate = DateTime::createFromFormat( + 'd-M-y G.i.s.u', $cdateonString, + new DateTimeZone('UTC')); if ($creationDate == false) { - throw new LogicException("Datetime in unexpected format. datetime: '" . $cdateonString . "'"); + throw new LogicException("Datetime in unexpected " . + "format. datetime: '" . $cdateonString . "'"); } } diff --git a/lib/Doctrine/deploy/AddProjectRoles.php b/lib/Doctrine/deploy/AddProjectRoles.php index 2ef40444e..d863f6bcf 100644 --- a/lib/Doctrine/deploy/AddProjectRoles.php +++ b/lib/Doctrine/deploy/AddProjectRoles.php @@ -12,7 +12,8 @@ * project exists more than once, the role is not added to a project. */ -$usersRolesFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . "/UsersAndRoles.xml"; +$usersRolesFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . + "/UsersAndRoles.xml"; $usersRoles = simplexml_load_file($usersRolesFileName); foreach ($usersRoles as $user) { @@ -30,13 +31,14 @@ // get roletype entity $dql = "SELECT rt FROM RoleType rt WHERE rt.name = :roleType"; $roleTypes = $entityManager->createQuery($dql) - ->setParameter(':roleType', (string) $role->USER_ROLE) + ->setParameter(':roleType', + (string) $role->USER_ROLE) ->getResult(); // /* Error checking: ensure each role type refers to exactly // * one role type*/ if (count($roleTypes) !== 1) { - throw new Exception(count($roleTypes) . " role types found with name: " . - $role->USER_ROLE); + throw new Exception(count($roleTypes) . " role types found " . + "with name: " . $role->USER_ROLE); } foreach ($roleTypes as $result) { @@ -44,10 +46,12 @@ } // Get user entity - $dql = "SELECT u FROM User u JOIN u.userIdentifiers up WHERE up.keyValue = :keyValue"; + $dql = "SELECT u FROM User u JOIN u.userIdentifiers up " . + "WHERE up.keyValue = :keyValue"; $users = $entityManager->createQuery($dql) - ->setParameter('keyValue', trim((string) $user->CERTDN)) - ->getResult(); + ->setParameter('keyValue', + trim((string) $user->CERTDN)) + ->getResult(); // /* Error checking: ensure each "user" refers to exactly // * one user */ @@ -66,18 +70,24 @@ // Querying the project entity $dql = "SELECT p FROM Project p WHERE p.name = :project"; $projects = $entityManager->createQuery($dql) - ->setParameter('project', $projectName) - ->getResult(); + ->setParameter('project', $projectName) + ->getResult(); // Error check: ensure each 'project' refers to exactly one project if (count($projects) !== 1) { - throw new Exception(count($projects) . " Projects found with name: " . - $projectName); + throw new Exception(count($projects) . " Projects found " . + "with name: " . $projectName); } // Finding the project object and adding the role to it - $getProject = $entityManager->getRepository('Project')->findOneBy(array("name" => $projectName)); - $doctrineRole = new Role($roleType, $doctrineUser, $getProject, 'STATUS_GRANTED'); + $getProject = $entityManager->getRepository('Project') + ->findOneBy(array("name" => $projectName)); + $doctrineRole = new Role( + $roleType, + $doctrineUser, + $getProject, + 'STATUS_GRANTED' + ); $entityManager->persist($doctrineRole); } } diff --git a/lib/Doctrine/deploy/AddScopes.php b/lib/Doctrine/deploy/AddScopes.php index b4978afb6..8950da765 100644 --- a/lib/Doctrine/deploy/AddScopes.php +++ b/lib/Doctrine/deploy/AddScopes.php @@ -3,11 +3,12 @@ require_once __DIR__ . "/../bootstrap.php"; require_once __DIR__ . "/AddUtils.php"; -/* AddNGIs.php: Loads a list of scopes from an XML file and inserts them into - * the doctrine prototype. +/* AddNGIs.php: Loads a list of scopes from an XML file and + * inserts them into the doctrine prototype. * XML format is the xml input format for scope data */ -$scopesFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . "/Scopes.xml"; +$scopesFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . + "/Scopes.xml"; $scopes = simplexml_load_file($scopesFileName); foreach ($scopes as $scope) { diff --git a/lib/Doctrine/deploy/AddServiceEndpoints.php b/lib/Doctrine/deploy/AddServiceEndpoints.php index bf604dec4..0b85de6c8 100644 --- a/lib/Doctrine/deploy/AddServiceEndpoints.php +++ b/lib/Doctrine/deploy/AddServiceEndpoints.php @@ -12,10 +12,12 @@ // Get EGI scope entity to join to later $dql = "SELECT s from Scope s WHERE s.name = 'EGI'"; -$scopes = $entityManager->createQuery($dql)->getResult(); +$scopes = $entityManager->createQuery($dql) + ->getResult(); /* Error checking: ensure we have the EGI scope */ if (count($scopes) !== 1) { - throw new Exception(count($scopes) . " scopes found with short name: EGI"); + throw new Exception(count($scopes) . " scopes found with " . + "short name: EGI"); } foreach ($scopes as $egiScope) { @@ -24,10 +26,12 @@ // Get local scope entity to join to later $dql = "SELECT s from Scope s WHERE s.name = 'Local'"; -$scopes = $entityManager->createQuery($dql)->getResult(); +$scopes = $entityManager->createQuery($dql) + ->getResult(); /* Error checking: ensure we have the local scope */ if (count($scopes) !== 1) { - throw new Exception(count($scopes) . " scopes found with short name: Local"); + throw new Exception(count($scopes) . " scopes found with " . + "short name: Local"); } foreach ($scopes as $localScope) { @@ -39,14 +43,16 @@ // get the hosting site entity $dql = "SELECT s from Site s WHERE s.shortName = ?1"; $parentSites = $entityManager->createQuery($dql) - ->setParameter(1, (string) $xmlSe->SITENAME) - ->getResult(); + ->setParameter(1, + (string) $xmlSe->SITENAME) + ->getResult(); /* Error checking: ensure each SE's "parent site" refers to exactly * one ngi */ if (count($parentSites) !== 1) { - throw new Exception(count($parentSites) . " sites found with short name: " . - $xmlSe->SITENAME . ". SE hostname is " . $xmlSe->HOSTNAME); + throw new Exception(count($parentSites) . " sites found " . + "with short name: " . $xmlSe->SITENAME . + ". SE hostname is " . $xmlSe->HOSTNAME); } foreach ($parentSites as $result) { @@ -58,14 +64,15 @@ // get the hosting service type $dql = "SELECT s from ServiceType s WHERE s.name = ?1"; $sts = $entityManager->createQuery($dql) - ->setParameter(1, (string) $xmlSe->SERVICE_TYPE) - ->getResult(); + ->setParameter(1, + (string) $xmlSe->SERVICE_TYPE) + ->getResult(); /* Error checking: ensure each SE's "SERVICE_TYPE" refers to exactly * one SERVICE_TYPE */ if (count($sts) !== 1) { - throw new Exception(count($sts) . " SERVICE_TYPEs found with name: " . - $xmlSe->SERVICE_TYPE); + throw new Exception(count($sts) . " SERVICE_TYPEs found " . + "with name: " . $xmlSe->SERVICE_TYPE); } foreach ($sts as $st) { @@ -101,7 +108,8 @@ } else if ((String) $xmlSe->SCOPE == 'Local') { $doctrineSe->addScope($localScope); } else { - throw new Exception("Unknown scope " . $xmlSe->SCOPE . " for SE " . $xmlSe->HOSTNAME); + throw new Exception("Unknown scope " . $xmlSe->SCOPE . + " for SE " . $xmlSe->HOSTNAME); } //set creation date @@ -120,7 +128,8 @@ $doctrineEndpointLocation = new EndpointLocation(); $doctrineEndpointLocation->setUrl((string) $xmlSe->URL); $doctrineEndpointLocation->setName('sampleEndpoint'); - $doctrineEndpointLocation->setInterfaceName((string)$doctrineSe->getServiceType()->getName()); + $doctrineEndpointLocation->setInterfaceName((string)$doctrineSe + ->getServiceType()->getName()); $doctrineSe->addEndpointLocationDoJoin($doctrineEndpointLocation); $entityManager->persist($doctrineSe); diff --git a/lib/Doctrine/deploy/AddServiceGroupRoles.php b/lib/Doctrine/deploy/AddServiceGroupRoles.php index 0690473be..5c01d0bdf 100644 --- a/lib/Doctrine/deploy/AddServiceGroupRoles.php +++ b/lib/Doctrine/deploy/AddServiceGroupRoles.php @@ -61,9 +61,11 @@ // get serviceGroup entity $sgName = (string) $role->ON_ENTITY; - $dql = "SELECT sg FROM ServiceGroup sg WHERE sg.name = :service_group"; + $dql = "SELECT sg FROM ServiceGroup sg WHERE " . + "sg.name = :service_group"; $serviceGroups = $entityManager->createQuery($dql) - ->setParameter('service_group', $sgName) + ->setParameter('service_group', + $sgName) ->getResult(); /* diff --git a/lib/Doctrine/deploy/AddServiceTypes.php b/lib/Doctrine/deploy/AddServiceTypes.php index dedf93294..b88ebab83 100644 --- a/lib/Doctrine/deploy/AddServiceTypes.php +++ b/lib/Doctrine/deploy/AddServiceTypes.php @@ -3,8 +3,8 @@ require_once __DIR__ . "/../bootstrap.php"; require_once __DIR__ . "/AddUtils.php"; -/* Loads a list of service types from an XML file and inserts them into - * the doctrine prototype. +/* Loads a list of service types from an XML file and + * inserts them into the doctrine prototype. * XML format is the PROM GOCDB PI output for get_service_type */ $stFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . "/ServiceTypes.xml"; diff --git a/lib/Doctrine/deploy/AddSiteRoles.php b/lib/Doctrine/deploy/AddSiteRoles.php index 357b6eb43..aff724541 100644 --- a/lib/Doctrine/deploy/AddSiteRoles.php +++ b/lib/Doctrine/deploy/AddSiteRoles.php @@ -4,11 +4,12 @@ require_once __DIR__ . "/AddUtils.php"; /** - * AddNGIs.php: Loads a list of Site roles from an XML file and inserts them into - * the doctrine prototype. + * AddNGIs.php: Loads a list of Site roles from an XML file and + * inserts them into the doctrine prototype. * XML format is the output from get_user_doctrine PI query. */ -$usersRolesFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . "/UsersAndRoles.xml"; +$usersRolesFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . + "/UsersAndRoles.xml"; $usersRoles = simplexml_load_file($usersRolesFileName); foreach ($usersRoles as $user) { @@ -27,13 +28,14 @@ // get the roletype entity $dql = "SELECT rt FROM RoleType rt WHERE rt.name = ?1"; $roleTypes = $entityManager->createQuery($dql) - ->setParameter(1, (string) $role->USER_ROLE) - ->getResult(); + ->setParameter(1, + (string) $role->USER_ROLE) + ->getResult(); // /* Error checking: ensure each role type refers to exactly - // * one role type*/ + // * one role type */ if (count($roleTypes) !== 1) { - throw new Exception(count($roleTypes) . " role types found with name: " . - $role->USER_ROLE); + throw new Exception(count($roleTypes) . " role types found " . + "with name: " . $role->USER_ROLE); } foreach ($roleTypes as $result) { @@ -45,10 +47,12 @@ } // Get user entity - $dql = "SELECT u FROM User u JOIN u.userIdentifiers up WHERE up.keyValue = :keyValue"; + $dql = "SELECT u FROM User u JOIN u.userIdentifiers up " . + "WHERE up.keyValue = :keyValue"; $users = $entityManager->createQuery($dql) - ->setParameter('keyValue', trim((string) $user->CERTDN)) - ->getResult(); + ->setParameter('keyValue', + trim((string) $user->CERTDN)) + ->getResult(); // /* Error checking: ensure each "user" refers to exactly // * one user */ @@ -66,7 +70,8 @@ } // Check for invalid sites and skip adding this role - // typically these sites don't have an NGI, country or production status + // typically these sites don't have an NGI, + // country or production status if (isBad((string) $role->ON_ENTITY)) { continue; } @@ -74,13 +79,14 @@ // get the site entity $dql = "SELECT s FROM Site s WHERE s.shortName = ?1"; $sites = $entityManager->createQuery($dql) - ->setParameter(1, (string) $role->ON_ENTITY) - ->getResult(); + ->setParameter(1, + (string) $role->ON_ENTITY) + ->getResult(); // /* Error checking: ensure each "site" refers to exactly // * one site */ if (count($sites) !== 1) { - throw new Exception(count($sites) . " sites found with short name: " . - $role->ON_ENTITY); + throw new Exception(count($sites) . " sites found " . + "with short name: " . $role->ON_ENTITY); } foreach ($sites as $doctrineSite) { @@ -95,13 +101,20 @@ $ExistingUserRoles = $doctrineUser->getRoles(); $thisIsADuplicateRole=false; foreach ($ExistingUserRoles as $role){ - if ($role->getRoleType() == $roleType and $role->getOwnedEntity() == $doctrineSite and $role->getStatus() == 'STATUS_GRANTED'){ + if ($role->getRoleType() == $roleType + and $role->getOwnedEntity() == $doctrineSite + and $role->getStatus() == 'STATUS_GRANTED'){ $thisIsADuplicateRole = true; } } if (!$thisIsADuplicateRole){ - $doctrineRole = new Role($roleType, $doctrineUser, $doctrineSite, 'STATUS_GRANTED'); + $doctrineRole = new Role( + $roleType, + $doctrineUser, + $doctrineSite, + 'STATUS_GRANTED' + ); $entityManager->persist($doctrineRole); } } diff --git a/lib/Doctrine/deploy/AddSites.php b/lib/Doctrine/deploy/AddSites.php index 9a339c115..603502d21 100644 --- a/lib/Doctrine/deploy/AddSites.php +++ b/lib/Doctrine/deploy/AddSites.php @@ -2,15 +2,17 @@ require_once __DIR__ . "/../bootstrap.php"; require_once __DIR__ . "/AddUtils.php"; -/* AddSites.php: Loads a list of sites from an XML file and inserts them into - * the doctrine prototype. +/* AddSites.php: Loads a list of sites from an XML file and + * inserts them into the doctrine prototype. * XML format is the output from get_site PI query. */ $sitesFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . "/Sites.xml"; $sites = simplexml_load_file($sitesFileName); -$xmlCertStatusChanges = simplexml_load_file( __DIR__ . "/" . $GLOBALS['dataDir'] . "/CertStatusChanges.xml"); -$xmlCertStatusLinkDates = simplexml_load_file(__DIR__ . "/" . $GLOBALS['dataDir'] . "/CertStatusDate.xml"); +$xmlCertStatusChanges = simplexml_load_file( __DIR__ . "/" . + $GLOBALS['dataDir'] . "/CertStatusChanges.xml"); +$xmlCertStatusLinkDates = simplexml_load_file(__DIR__ . "/" . + $GLOBALS['dataDir'] . "/CertStatusDate.xml"); $largestV4SitePk = 0; foreach ($sites as $xmlSite) { @@ -54,11 +56,12 @@ // get the parent NGI entity $dql = "SELECT n FROM NGI n WHERE n.name = ?1"; $parentNgis = $entityManager->createQuery($dql) - ->setParameter(1, (string) $xmlSite->ROC) - ->getResult(); + ->setParameter(1, + (string) $xmlSite->ROC) + ->getResult(); // /* Error checking: ensure each SE's "parent ngi" refers to exactly - // * one ngi */ + // * one ngi */ if (count($parentNgis) !== 1) { throw new Exception(count($parentNgis) . " NGIs found with name: " . $xmlSite->ROC); @@ -73,14 +76,15 @@ // get the target infrastructure $dql = "SELECT i FROM Infrastructure i WHERE i.name = :name"; $infs = $entityManager->createQuery($dql) - ->setParameter('name', (string) $xmlSite->PRODUCTION_INFRASTRUCTURE) - ->getResult(); + ->setParameter('name', + (string) $xmlSite->PRODUCTION_INFRASTRUCTURE) + ->getResult(); - // /* Error checking: ensure each SE's "PRODUCTION_INFRASTRUCTURE" refers to exactly - // * one PRODUCTION_INFRASTRUCTURE */ + // /* Error checking: ensure each SE's "PRODUCTION_INFRASTRUCTURE" + // * refers to exactly one PRODUCTION_INFRASTRUCTURE */ if (count($infs) !== 1) { - throw new Exception(count($infs) . " Infrastructures found with name: " . - $xmlSite->PRODUCTION_INFRASTRUCTURE); + throw new Exception(count($infs) . " Infrastructures found " . + "with name: " . $xmlSite->PRODUCTION_INFRASTRUCTURE); } foreach ($infs as $inf) { @@ -92,14 +96,15 @@ // get the cert status $dql = "SELECT c FROM CertificationStatus c WHERE c.name = ?1"; $certStatuses = $entityManager->createQuery($dql) - ->setParameter(1, (string) $xmlSite->CERTIFICATION_STATUS) - ->getResult(); + ->setParameter(1, + (string) $xmlSite->CERTIFICATION_STATUS) + ->getResult(); /* Error checking: ensure each Site's "cert status" refers to exactly * one cert status */ if (count($certStatuses) !== 1) { - throw new Exception(count($certStatuses) . " cert statuses found with name: " . - $xmlSite->CERTIFICATION_STATUS); + throw new Exception(count($certStatuses) . " cert statuses found " . + "with name: " . $xmlSite->CERTIFICATION_STATUS); } foreach ($certStatuses as $certStatus) { @@ -108,19 +113,21 @@ $doctrineSite->setCertificationStatus($certStatus); - $doctrineSite->addScope(getScope($entityManager, (string) $xmlSite->SCOPE)); + $doctrineSite->addScope(getScope($entityManager, + (string) $xmlSite->SCOPE)); // get / set the country $dql = "SELECT c FROM Country c WHERE c.name = ?1"; $countries = $entityManager->createQuery($dql) - ->setParameter(1, (string) $xmlSite->COUNTRY) - ->getResult(); + ->setParameter(1, + (string) $xmlSite->COUNTRY) + ->getResult(); /* Error checking: ensure each country refers to exactly * one country */ if (count($countries) !== 1) { - throw new Exception(count($countries) . " country found with name: " . - $xmlSite->COUNTRY); + throw new Exception(count($countries) . " country found " . + "with name: " . $xmlSite->COUNTRY); } foreach ($countries as $country) { @@ -133,8 +140,9 @@ // get the Tier (optional value) $dql = "SELECT t FROM Tier t WHERE t.name = ?1"; $tiers = $entityManager->createQuery($dql) - ->setParameter(1, (string) $xmlSite->TIER) - ->getResult(); + ->setParameter(1, + (string) $xmlSite->TIER) + ->getResult(); /* Error checking: ensure each tier refers to exactly * one TIER */ @@ -149,8 +157,9 @@ // get the SubGrid (optional value) $dql = "SELECT s FROM SubGrid s WHERE s.name = ?1"; $subGrids = $entityManager->createQuery($dql) - ->setParameter(1, (string) $xmlSite->SUBGRID) - ->getResult(); + ->setParameter(1, + (string) $xmlSite->SUBGRID) + ->getResult(); /* Error checking: ensure each subgrid refers to exactly * one subgrid */ @@ -165,7 +174,8 @@ //set creation date - $creationDate = new \DateTime("now", new DateTimeZone('UTC')); + $creationDate = new \DateTime("now", + new DateTimeZone('UTC')); $doctrineSite->setCreationDate($creationDate); @@ -178,14 +188,19 @@ // only interested in the current site if ($targetSiteName == $doctrineSite->getShortName()){ // '01-JUL-13 11.09.10.000000 AM' which has the php datetime - // format of 'd-M-y H.i.s A' provided we trim off the '.000000' (millisecs) + // format of 'd-M-y H.i.s A' provided we + // trim off the '.000000' (millisecs) // Note, '.000000' is present in all the elements. $xmlLinkDateString = (string) $xmlCertStatusLinkDate->cert_date; - $xmlLinkDateString = preg_replace('/\.000000/', "", $xmlLinkDateString); - $linkDate = \DateTime::createFromFormat('d-M-y H.i.s A', $xmlLinkDateString, new \DateTimeZone('UTC')); + $xmlLinkDateString = preg_replace('/\.000000/', "", + $xmlLinkDateString); + $linkDate = \DateTime::createFromFormat('d-M-y H.i.s A', + $xmlLinkDateString, new \DateTimeZone('UTC')); if (!$linkDate) { - throw new Exception("Can't parse date/time " . $xmlLinkDateString . " for site " . - $doctrineSite->getShortName() . ". Correct format: 27-JUL-11 02.02.03 PM" ); + throw new Exception("Can't parse date/time " . + $xmlLinkDateString . " for site " . + $doctrineSite->getShortName() . + ". Correct format: 27-JUL-11 02.02.03 PM" ); } $doctrineSite->setCertificationStatusChangeDate($linkDate); @@ -195,8 +210,9 @@ // Add the Site's certification status history/log. - // If the Site certStatus has never been updated from its initial state, - // then no changes will have occurred and the log will be empty for that Site. + // If the Site certStatus has never been updated from + // its initial state, then no changes will have occurred + // and the log will be empty for that Site. // // Importantly, because the v4 certStatus change log was added AFTER some // sites were already added to GOCDB4, the LAST AddedDate does NOT @@ -208,14 +224,21 @@ // only interested in the current site if ($targetSiteName == $doctrineSite->getShortName()){ $doctrineCertStatusChangeLog = new \CertificationStatusLog(); - $doctrineCertStatusChangeLog->setAddedBy((string) $xmlCertStatusChange->CHANGED_BY); - $doctrineCertStatusChangeLog->setOldStatus((string) $xmlCertStatusChange->OLD_STATUS); - $doctrineCertStatusChangeLog->setNewStatus((string) $xmlCertStatusChange->NEW_STATUS); - $doctrineCertStatusChangeLog->setReason((string) $xmlCertStatusChange->COMMENT); - $insertDate = new DateTime("@" . (string) $xmlCertStatusChange->UNIX_TIME); + $doctrineCertStatusChangeLog->setAddedBy((string) + $xmlCertStatusChange->CHANGED_BY); + $doctrineCertStatusChangeLog->setOldStatus((string) + $xmlCertStatusChange->OLD_STATUS); + $doctrineCertStatusChangeLog->setNewStatus((string) + $xmlCertStatusChange->NEW_STATUS); + $doctrineCertStatusChangeLog->setReason((string) + $xmlCertStatusChange->COMMENT); + $insertDate = new DateTime("@" . + (string) $xmlCertStatusChange->UNIX_TIME); $doctrineCertStatusChangeLog->setAddedDate($insertDate); $entityManager->persist($doctrineCertStatusChangeLog); - $doctrineSite->addCertificationStatusLog($doctrineCertStatusChangeLog); + $doctrineSite->addCertificationStatusLog( + $doctrineCertStatusChangeLog + ); } } diff --git a/lib/Doctrine/deploy/AddUsers.php b/lib/Doctrine/deploy/AddUsers.php index 8ed0e8f5f..7567886c7 100644 --- a/lib/Doctrine/deploy/AddUsers.php +++ b/lib/Doctrine/deploy/AddUsers.php @@ -7,7 +7,8 @@ $em = \Factory::getEntityManager(); $serv = \Factory::getUserService(); -$usersRolesFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . "/UsersAndRoles.xml"; +$usersRolesFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . + "/UsersAndRoles.xml"; $usersRoles = simplexml_load_file($usersRolesFileName); // Used to check for duplicates $idStrings = array(); @@ -36,8 +37,10 @@ $doctrineUser->setTitle((string) $user->TITLE); $doctrineUser->setEmail((string) $user->EMAIL); $doctrineUser->setTelephone((string) $user->TEL); - $doctrineUser->setWorkingHoursStart((string) $user->WORKING_HOURS_START); - $doctrineUser->setWorkingHoursEnd((string) $user->WORKING_HOURS_END); + $doctrineUser->setWorkingHoursStart((string) + $user->WORKING_HOURS_START); + $doctrineUser->setWorkingHoursEnd((string) + $user->WORKING_HOURS_END); $doctrineUser->setAdmin(false); // Roughly half of users don't have a home site set @@ -45,14 +48,15 @@ // Get the home site entity $dql = "SELECT s from Site s WHERE s.shortName = ?1"; $homeSites = $em->createQuery($dql) - ->setParameter(1, (string) $user->HOMESITE) - ->getResult(); + ->setParameter(1, (string) $user->HOMESITE) + ->getResult(); /* Error checking: ensure each "home site" refers to exactly * one home site */ if (count($homeSites) !== 1) { - throw new \Exception(count($homeSites) . " sites found with short name: " . - $user->HOMESITE . ". user DN is " . $user->CERTDN); + throw new \Exception(count($homeSites) . " sites found " . + "with short name: " . $user->HOMESITE . + ". user DN is " . $user->CERTDN); } foreach ($homeSites as $result) { @@ -64,7 +68,11 @@ $em->persist($doctrineUser); $em->flush(); - $serv->addUserIdentifier($doctrineUser, $identifierArr, $doctrineUser); + $serv->addUserIdentifier( + $doctrineUser, + $identifierArr, + $doctrineUser + ); } $em->getConnection()->commit(); diff --git a/lib/Doctrine/deploy/AddUtils.php b/lib/Doctrine/deploy/AddUtils.php index 1ab6ea264..dd7359c26 100644 --- a/lib/Doctrine/deploy/AddUtils.php +++ b/lib/Doctrine/deploy/AddUtils.php @@ -3,14 +3,15 @@ // Finds one or more services by hostname and service type function findSEs($hostName, $serviceType) { - $dql = "SELECT s FROM Service s JOIN s.serviceType st" - . " WHERE s.hostName = :hostName AND st.name = :serviceType"; + $dql = "SELECT s FROM Service s JOIN s.serviceType st " . + "WHERE s.hostName = :hostName AND " . + "st.name = :serviceType"; $services = $GLOBALS['entityManager'] - ->createQuery($dql) - ->setParameter(":hostName", $hostName) - ->setParameter(":serviceType", $serviceType) - ->getResult(); + ->createQuery($dql) + ->setParameter(":hostName", $hostName) + ->setParameter(":serviceType", $serviceType) + ->getResult(); return $services; } @@ -19,27 +20,34 @@ function findSEs($hostName, $serviceType) { * Uses a list of known bad sites */ function isBad($site) { /* Roles over these sites are in the production data but can't be inserted - * into v5 because they don't have an NGI or a domain. v5 doesn't import sites without an NGI - * or domain + * into v5 because they don't have an NGI or a domain. v5 doesn't import + * sites without an NGI or domain * * Sites ignored becuase of no parent NGI: - * Australia-UNIMELB-LCG2, GUP-JKU,UNIBAS, FZK-PPS, MA-01-CNRST, All sites under - * ROC_IGALC which was closed Apr-2013, all NGI_IE sites closed Jul-2013. + * Australia-UNIMELB-LCG2, GUP-JKU,UNIBAS, FZK-PPS, MA-01-CNRST, + * All sites under ROC_IGALC which was closed Apr-2013, + * all NGI_IE sites closed Jul-2013. * PPS-CNAF is a broken site with a production status of pps - * 15.08.13: Removed 'UFRJ-IF', from this list as it appears to be fixed (??) - * 15.08.13: Removed 'EELA-UNLP', from this list as it appears to be fixed (??) - * 15.08.13: Removed 'ULA-MERIDA', from this list as it appears to be fixed (??) - * 15.08.13: Removed 'ZA-MERAKA', 'ZA-WITS-CORE', 'ZA-UJ', 'ZA-CHPC' as NGI_ZA has been reinstated + * 15.08.13: Removed 'UFRJ-IF', from this list as it + * appears to be fixed (??) + * 15.08.13: Removed 'EELA-UNLP', from this list as it + * appears to be fixed (??) + * 15.08.13: Removed 'ULA-MERIDA', from this list as it + * appears to be fixed (??) + * 15.08.13: Removed 'ZA-MERAKA', 'ZA-WITS-CORE', 'ZA-UJ', + * 'ZA-CHPC' as NGI_ZA has been reinstated */ - $badSites = array('Australia-UNIMELB-LCG2', 'PPS-CNAF', 'GUP-JKU', 'UNIBAS', 'FZK-PPS' - , 'MA-01-CNRST', 'EELA-UC', 'CEFET-RJ', 'CMM-UChile', 'CPTEC-INPE' - , 'CUBAENERGIA', 'EPN', 'FING', 'GRID-CEDIA', 'GRyDs-USB' - , 'INCOR-HCFMUSP', 'UFCG-LSD', 'UIS-BUCARAMANGA', 'UTP-PANAMA', 'ITWM-PPS' , 'HU-BERLIN', 'SCAI-PPS' - , 'FZK-SC', 'FZK-Test', 'FZK-Test', 'GRIDOPS-GRIDVIEW', 'GSI-LCG2-PPS' + $badSites = array('Australia-UNIMELB-LCG2', 'PPS-CNAF', 'GUP-JKU', + 'UNIBAS', 'FZK-PPS', 'MA-01-CNRST', 'EELA-UC', 'CEFET-RJ', + 'CMM-UChile', 'CPTEC-INPE', 'CUBAENERGIA', 'EPN', 'FING', + 'GRID-CEDIA', 'GRyDs-USB', 'INCOR-HCFMUSP', 'UFCG-LSD', + 'UIS-BUCARAMANGA', 'UTP-PANAMA', 'ITWM-PPS' , 'HU-BERLIN', + 'SCAI-PPS', 'FZK-SC', 'FZK-Test', 'FZK-Test', + 'GRIDOPS-GRIDVIEW', 'GSI-LCG2-PPS', // next lot is from NGI_IE which was deleted. - , 'csTCDie', 'mpUCDie', 'giNUIMie', 'cpDIASie', 'csQUBuk', 'csUCCie' - , 'scgNUIGie', 'giITTAie', 'obsARMuk', 'giHECie', 'giRCSIie' - , 'giDCUie'); + 'csTCDie', 'mpUCDie', 'giNUIMie', 'cpDIASie', 'csQUBuk', + 'csUCCie', 'scgNUIGie', 'giITTAie', 'obsARMuk', 'giHECie', + 'giRCSIie', 'giDCUie'); if (sizeof(array_intersect(array($site), $badSites)) == 0) { return false; @@ -58,13 +66,14 @@ function getScope($entityManager, $scope) { // get the scope $dql = "SELECT s FROM Scope s WHERE s.name = ?1"; $scopes = $entityManager->createQuery($dql) - ->setParameter(1, $scope) - ->getResult(); + ->setParameter(1, $scope) + ->getResult(); /* Error checking: ensure each Site's "SCOPE" refers to exactly * one SCOPE */ if (count($scopes) !== 1) { - throw new Exception(count($scopes) . " SCOPEs found with name: " . $scope); + throw new Exception(count($scopes) . " SCOPEs found " . + "with name: " . $scope); } return $scopes[0]; From a13ac7db82d9c8b00b5385e20206a6206015e84a Mon Sep 17 00:00:00 2001 From: rowan04 Date: Thu, 28 Sep 2023 13:08:23 +0000 Subject: [PATCH 4/5] Fix multi-line function calls - opening parenthesis at end of line - one argument per line - closing parenthesis on own line - indentation fixes - spaces after closing parenthesis before an opening parenthesis - some issue fixes suggested by codeclimate --- lib/Doctrine/deploy/AddDowntimes.php | 16 +- lib/Doctrine/deploy/AddNGIRoles.php | 37 +++-- lib/Doctrine/deploy/AddNGIs.php | 10 +- lib/Doctrine/deploy/AddProjectRoles.php | 23 ++- lib/Doctrine/deploy/AddRoleTypes.php | 2 +- lib/Doctrine/deploy/AddScopes.php | 2 +- lib/Doctrine/deploy/AddServiceEndpoints.php | 17 ++- lib/Doctrine/deploy/AddServiceGroupRoles.php | 16 +- lib/Doctrine/deploy/AddSiteRoles.php | 28 ++-- lib/Doctrine/deploy/AddSites.php | 152 +++++++++++-------- lib/Doctrine/deploy/AddUsers.php | 7 +- lib/Doctrine/deploy/AddUtils.php | 6 +- 12 files changed, 196 insertions(+), 120 deletions(-) diff --git a/lib/Doctrine/deploy/AddDowntimes.php b/lib/Doctrine/deploy/AddDowntimes.php index 5d79a9eb7..da43206fc 100644 --- a/lib/Doctrine/deploy/AddDowntimes.php +++ b/lib/Doctrine/deploy/AddDowntimes.php @@ -72,8 +72,10 @@ // Create a new downtime, add the SE to it $downtime = newDowntime($downtimeXml); // Finds one or more SEs by hostname and service type - $services = findSEs((string) $downtimeXml->HOSTNAME, - (string) $downtimeXml->SERVICE_TYPE); + $services = findSEs( + (string) $downtimeXml->HOSTNAME, + (string) $downtimeXml->SERVICE_TYPE + ); // There are some edge cases where findSEs returns // more than one SE (see the comment at the top of this file) @@ -93,8 +95,10 @@ $GLOBALS['allDowntimes'][$promId] = $downtime; } else { // Find the SE and link it to the downtime - $services = findSEs((string) $downtimeXml->HOSTNAME, - (string) $downtimeXml->SERVICE_TYPE); + $services = findSEs( + (string) $downtimeXml->HOSTNAME, + (string) $downtimeXml->SERVICE_TYPE + ); if (!isset($services[0])) { throw new Exception("No SE found with hostname " . @@ -110,7 +114,7 @@ // duplicate SEs (the duplicate SE count is tested for the expected // 2 duplicates below in catch block). $els = $services[0]->getEndpointLocations(); - if (count($els) > 1){ + if (count($els) > 1) { throw new LogicException('Coding error - there should only ' . 'be one EL per Service'); } @@ -212,7 +216,7 @@ function newDowntime($downtimeXml) { // Get the largest v4 downtime PK which is an integer appended by // the string 'G0' slice off the 'G0' and get the integer value. $v4pk = (int)substr($primaryKey, 0, strlen($primaryKey)-2); - if ($v4pk > $GLOBALS['largestV4DowntimePK']){ + if ($v4pk > $GLOBALS['largestV4DowntimePK']) { $GLOBALS['largestV4DowntimePK'] = $v4pk; } diff --git a/lib/Doctrine/deploy/AddNGIRoles.php b/lib/Doctrine/deploy/AddNGIRoles.php index 6705d9cd6..7894f63a4 100644 --- a/lib/Doctrine/deploy/AddNGIRoles.php +++ b/lib/Doctrine/deploy/AddNGIRoles.php @@ -22,8 +22,10 @@ // get roletype entity $dql = "SELECT rt FROM RoleType rt WHERE rt.name = :roleType"; $roleTypes = $entityManager->createQuery($dql) - ->setParameter(':roleType', - (string) $role->USER_ROLE) + ->setParameter( + ':roleType', + (string) $role->USER_ROLE + ) ->getResult(); // /* Error checking: ensure each role type refers to exactly // * one role type*/ @@ -40,8 +42,10 @@ $dql = "SELECT u FROM User u JOIN u.userIdentifiers " . "up WHERE up.keyValue = :keyValue"; $users = $entityManager->createQuery($dql) - ->setParameter('keyValue', - trim((string) $user->CERTDN)) + ->setParameter( + 'keyValue', + trim((string) $user->CERTDN) + ) ->getResult(); // /* Error checking: ensure each "user" refers to exactly @@ -57,9 +61,13 @@ // Check for invalid NGIs and skip // typically these are decomissioned ROCs - if ($role->ON_ENTITY == 'GridIreland' || $role->ON_ENTITY == 'NGS' - || $role->ON_ENTITY == 'LondonT2' || $role->ON_ENTITY == 'Tier1A' - || $role->ON_ENTITY == 'Tier1A') { + if ( + $role->ON_ENTITY == 'GridIreland' + || $role->ON_ENTITY == 'NGS' + || $role->ON_ENTITY == 'LondonT2' + || $role->ON_ENTITY == 'Tier1A' + || $role->ON_ENTITY == 'Tier1A' + ) { continue; } @@ -67,7 +75,10 @@ $ngiName = (string) $role->ON_ENTITY; $dql = "SELECT n FROM NGI n WHERE n.name = :ngi"; $ngis = $entityManager->createQuery($dql) - ->setParameter('ngi', $ngiName) + ->setParameter( + 'ngi', + $ngiName + ) ->getResult(); // /* Error checking: ensure each "ngi" refers to exactly // * one ngi */ @@ -83,15 +94,17 @@ //check that the role is not a duplicate (v4 data contaisn duplicates) $ExistingUserRoles = $doctrineUser->getRoles(); $thisIsADuplicateRole=false; - foreach ($ExistingUserRoles as $role){ - if ($role->getRoleType() == $roleType + foreach ($ExistingUserRoles as $role) { + if ( + $role->getRoleType() == $roleType and $role->getOwnedEntity() == $ngi - and $role->getStatus() == 'STATUS_GRANTED') { + and $role->getStatus() == 'STATUS_GRANTED' + ) { $thisIsADuplicateRole = true; } } - if (!$thisIsADuplicateRole){ + if (!$thisIsADuplicateRole) { $doctrineRole = new Role( $roleType, $doctrineUser, diff --git a/lib/Doctrine/deploy/AddNGIs.php b/lib/Doctrine/deploy/AddNGIs.php index bd50ed035..58441c329 100644 --- a/lib/Doctrine/deploy/AddNGIs.php +++ b/lib/Doctrine/deploy/AddNGIs.php @@ -70,12 +70,14 @@ //convert to date time $creationDate = DateTime::createFromFormat( - 'd-M-y G.i.s.u', $cdateonString, - new DateTimeZone('UTC')); + 'd-M-y G.i.s.u', + $cdateonString, + new DateTimeZone('UTC') + ); if ($creationDate == false) { - throw new LogicException("Datetime in unexpected " . - "format. datetime: '" . $cdateonString . "'"); + throw new LogicException("Datetime in unexpected " . + "format. datetime: '" . $cdateonString . "'"); } } diff --git a/lib/Doctrine/deploy/AddProjectRoles.php b/lib/Doctrine/deploy/AddProjectRoles.php index d863f6bcf..f626ea76e 100644 --- a/lib/Doctrine/deploy/AddProjectRoles.php +++ b/lib/Doctrine/deploy/AddProjectRoles.php @@ -31,9 +31,11 @@ // get roletype entity $dql = "SELECT rt FROM RoleType rt WHERE rt.name = :roleType"; $roleTypes = $entityManager->createQuery($dql) - ->setParameter(':roleType', - (string) $role->USER_ROLE) - ->getResult(); + ->setParameter( + ':roleType', + (string) $role->USER_ROLE + ) + ->getResult(); // /* Error checking: ensure each role type refers to exactly // * one role type*/ if (count($roleTypes) !== 1) { @@ -49,8 +51,10 @@ $dql = "SELECT u FROM User u JOIN u.userIdentifiers up " . "WHERE up.keyValue = :keyValue"; $users = $entityManager->createQuery($dql) - ->setParameter('keyValue', - trim((string) $user->CERTDN)) + ->setParameter( + 'keyValue', + trim((string) $user->CERTDN) + ) ->getResult(); // /* Error checking: ensure each "user" refers to exactly @@ -70,7 +74,10 @@ // Querying the project entity $dql = "SELECT p FROM Project p WHERE p.name = :project"; $projects = $entityManager->createQuery($dql) - ->setParameter('project', $projectName) + ->setParameter( + 'project', + $projectName + ) ->getResult(); // Error check: ensure each 'project' refers to exactly one project @@ -81,7 +88,9 @@ // Finding the project object and adding the role to it $getProject = $entityManager->getRepository('Project') - ->findOneBy(array("name" => $projectName)); + ->findOneBy( + array("name" => $projectName) + ); $doctrineRole = new Role( $roleType, $doctrineUser, diff --git a/lib/Doctrine/deploy/AddRoleTypes.php b/lib/Doctrine/deploy/AddRoleTypes.php index 79977dad3..3217bfa12 100644 --- a/lib/Doctrine/deploy/AddRoleTypes.php +++ b/lib/Doctrine/deploy/AddRoleTypes.php @@ -42,7 +42,7 @@ foreach ($roleTypeArray as $key => $value) { $rt = new RoleType($value); //echo $value; - if ($value != RoleTypeName::GOCDB_ADMIN){ + if ($value != RoleTypeName::GOCDB_ADMIN) { $entityManager->persist($rt); } } diff --git a/lib/Doctrine/deploy/AddScopes.php b/lib/Doctrine/deploy/AddScopes.php index 8950da765..2d52e1d1f 100644 --- a/lib/Doctrine/deploy/AddScopes.php +++ b/lib/Doctrine/deploy/AddScopes.php @@ -21,7 +21,7 @@ $name = (string) $value; break; case "reserved": - $reserved = ( $value == 1 ); + $reserved = ($value == 1); break; } } diff --git a/lib/Doctrine/deploy/AddServiceEndpoints.php b/lib/Doctrine/deploy/AddServiceEndpoints.php index 0b85de6c8..c2c44f2bc 100644 --- a/lib/Doctrine/deploy/AddServiceEndpoints.php +++ b/lib/Doctrine/deploy/AddServiceEndpoints.php @@ -7,7 +7,8 @@ * XML file and inserts them into the doctrine prototype. * XML format is the output from get_service_endpoints PI query. */ -$seFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . "/ServiceEndpoints.xml"; +$seFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . + "/ServiceEndpoints.xml"; $ses = simplexml_load_file($seFileName); // Get EGI scope entity to join to later @@ -43,8 +44,10 @@ // get the hosting site entity $dql = "SELECT s from Site s WHERE s.shortName = ?1"; $parentSites = $entityManager->createQuery($dql) - ->setParameter(1, - (string) $xmlSe->SITENAME) + ->setParameter( + 1, + (string) $xmlSe->SITENAME + ) ->getResult(); /* Error checking: ensure each SE's "parent site" refers to exactly @@ -64,8 +67,10 @@ // get the hosting service type $dql = "SELECT s from ServiceType s WHERE s.name = ?1"; $sts = $entityManager->createQuery($dql) - ->setParameter(1, - (string) $xmlSe->SERVICE_TYPE) + ->setParameter( + 1, + (string) $xmlSe->SERVICE_TYPE + ) ->getResult(); /* Error checking: ensure each SE's "SERVICE_TYPE" refers to exactly @@ -105,7 +110,7 @@ // Set the scope if ((string) $xmlSe->SCOPE == "EGI") { $doctrineSe->addScope($egiScope); - } else if ((String) $xmlSe->SCOPE == 'Local') { + } elseif ((string) $xmlSe->SCOPE == 'Local') { $doctrineSe->addScope($localScope); } else { throw new Exception("Unknown scope " . $xmlSe->SCOPE . diff --git a/lib/Doctrine/deploy/AddServiceGroupRoles.php b/lib/Doctrine/deploy/AddServiceGroupRoles.php index 5c01d0bdf..81f0f1a5c 100644 --- a/lib/Doctrine/deploy/AddServiceGroupRoles.php +++ b/lib/Doctrine/deploy/AddServiceGroupRoles.php @@ -23,7 +23,10 @@ $userRole = (string) $role->USER_ROLE; $dql = "SELECT rt FROM RoleType rt WHERE rt.name = :roleType"; $roleTypes = $entityManager->createQuery($dql) - ->setParameter(':roleType', $userRole) + ->setParameter( + ':roleType', + $userRole + ) ->getResult(); /* @@ -44,7 +47,10 @@ $dql = "SELECT u FROM User u JOIN u.userIdentifiers up " . "WHERE up.keyValue = :keyValue"; $users = $entityManager->createQuery($dql) - ->setParameter('keyValue', trim($userDN)) + ->setParameter( + 'keyValue', + trim($userDN) + ) ->getResult(); /* @@ -64,8 +70,10 @@ $dql = "SELECT sg FROM ServiceGroup sg WHERE " . "sg.name = :service_group"; $serviceGroups = $entityManager->createQuery($dql) - ->setParameter('service_group', - $sgName) + ->setParameter( + 'service_group', + $sgName + ) ->getResult(); /* diff --git a/lib/Doctrine/deploy/AddSiteRoles.php b/lib/Doctrine/deploy/AddSiteRoles.php index aff724541..b3a1e6315 100644 --- a/lib/Doctrine/deploy/AddSiteRoles.php +++ b/lib/Doctrine/deploy/AddSiteRoles.php @@ -28,8 +28,10 @@ // get the roletype entity $dql = "SELECT rt FROM RoleType rt WHERE rt.name = ?1"; $roleTypes = $entityManager->createQuery($dql) - ->setParameter(1, - (string) $role->USER_ROLE) + ->setParameter( + 1, + (string) $role->USER_ROLE + ) ->getResult(); // /* Error checking: ensure each role type refers to exactly // * one role type */ @@ -50,8 +52,10 @@ $dql = "SELECT u FROM User u JOIN u.userIdentifiers up " . "WHERE up.keyValue = :keyValue"; $users = $entityManager->createQuery($dql) - ->setParameter('keyValue', - trim((string) $user->CERTDN)) + ->setParameter( + 'keyValue', + trim((string) $user->CERTDN) + ) ->getResult(); // /* Error checking: ensure each "user" refers to exactly @@ -79,8 +83,10 @@ // get the site entity $dql = "SELECT s FROM Site s WHERE s.shortName = ?1"; $sites = $entityManager->createQuery($dql) - ->setParameter(1, - (string) $role->ON_ENTITY) + ->setParameter( + 1, + (string) $role->ON_ENTITY + ) ->getResult(); // /* Error checking: ensure each "site" refers to exactly // * one site */ @@ -100,15 +106,17 @@ //check that the role is not a duplicate (v4 data contaisn duplicates) $ExistingUserRoles = $doctrineUser->getRoles(); $thisIsADuplicateRole=false; - foreach ($ExistingUserRoles as $role){ - if ($role->getRoleType() == $roleType + foreach ($ExistingUserRoles as $role) { + if ( + $role->getRoleType() == $roleType and $role->getOwnedEntity() == $doctrineSite - and $role->getStatus() == 'STATUS_GRANTED'){ + and $role->getStatus() == 'STATUS_GRANTED' + ) { $thisIsADuplicateRole = true; } } - if (!$thisIsADuplicateRole){ + if (!$thisIsADuplicateRole) { $doctrineRole = new Role( $roleType, $doctrineUser, diff --git a/lib/Doctrine/deploy/AddSites.php b/lib/Doctrine/deploy/AddSites.php index 603502d21..3f6296e5c 100644 --- a/lib/Doctrine/deploy/AddSites.php +++ b/lib/Doctrine/deploy/AddSites.php @@ -9,7 +9,7 @@ $sitesFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . "/Sites.xml"; $sites = simplexml_load_file($sitesFileName); -$xmlCertStatusChanges = simplexml_load_file( __DIR__ . "/" . +$xmlCertStatusChanges = simplexml_load_file(__DIR__ . "/" . $GLOBALS['dataDir'] . "/CertStatusChanges.xml"); $xmlCertStatusLinkDates = simplexml_load_file(__DIR__ . "/" . $GLOBALS['dataDir'] . "/CertStatusDate.xml"); @@ -21,8 +21,8 @@ // than any other recorded so far $v4pkGO = trim((string) $xmlSite->PRIMARY_KEY); // isolate just the number part (slice the 'GO' off the end) - $v4pk = (int)substr($v4pkGO, 0, strlen($v4pkGO)-2); - if ($v4pk > $largestV4SitePk){ + $v4pk = (int) substr($v4pkGO, 0, strlen($v4pkGO)-2); + if ($v4pk > $largestV4SitePk) { $largestV4SitePk = $v4pk; } @@ -37,11 +37,11 @@ $doctrineSite->setTelephone((string) $xmlSite->CONTACT_TEL); $doctrineSite->setGiisUrl((string) $xmlSite->GIIS_URL); $doctrineSite->setTimezoneId((string) $xmlSite->TIMEZONE); - if (strlen((string)$xmlSite->LATITUDE) > 0){ - $doctrineSite->setLatitude((float)$xmlSite->LATITUDE); + if (strlen((string) $xmlSite->LATITUDE) > 0) { + $doctrineSite->setLatitude((float) $xmlSite->LATITUDE); } - if (strlen((string)$xmlSite->LONGITUDE) > 0){ - $doctrineSite->setLongitude((float)$xmlSite->LONGITUDE); + if (strlen((string) $xmlSite->LONGITUDE) > 0) { + $doctrineSite->setLongitude((float) $xmlSite->LONGITUDE); } $doctrineSite->setCsirtEmail((string) $xmlSite->CSIRT_EMAIL); $doctrineSite->setIpRange((string) $xmlSite->IP_RANGE); @@ -56,8 +56,10 @@ // get the parent NGI entity $dql = "SELECT n FROM NGI n WHERE n.name = ?1"; $parentNgis = $entityManager->createQuery($dql) - ->setParameter(1, - (string) $xmlSite->ROC) + ->setParameter( + 1, + (string) $xmlSite->ROC + ) ->getResult(); // /* Error checking: ensure each SE's "parent ngi" refers to exactly @@ -76,8 +78,10 @@ // get the target infrastructure $dql = "SELECT i FROM Infrastructure i WHERE i.name = :name"; $infs = $entityManager->createQuery($dql) - ->setParameter('name', - (string) $xmlSite->PRODUCTION_INFRASTRUCTURE) + ->setParameter( + 'name', + (string) $xmlSite->PRODUCTION_INFRASTRUCTURE + ) ->getResult(); // /* Error checking: ensure each SE's "PRODUCTION_INFRASTRUCTURE" @@ -96,8 +100,10 @@ // get the cert status $dql = "SELECT c FROM CertificationStatus c WHERE c.name = ?1"; $certStatuses = $entityManager->createQuery($dql) - ->setParameter(1, - (string) $xmlSite->CERTIFICATION_STATUS) + ->setParameter( + 1, + (string) $xmlSite->CERTIFICATION_STATUS + ) ->getResult(); /* Error checking: ensure each Site's "cert status" refers to exactly @@ -113,14 +119,20 @@ $doctrineSite->setCertificationStatus($certStatus); - $doctrineSite->addScope(getScope($entityManager, - (string) $xmlSite->SCOPE)); + $doctrineSite->addScope( + getScope( + $entityManager, + (string) $xmlSite->SCOPE + ) + ); // get / set the country $dql = "SELECT c FROM Country c WHERE c.name = ?1"; $countries = $entityManager->createQuery($dql) - ->setParameter(1, - (string) $xmlSite->COUNTRY) + ->setParameter( + 1, + (string) $xmlSite->COUNTRY + ) ->getResult(); /* Error checking: ensure each country refers to exactly @@ -140,8 +152,10 @@ // get the Tier (optional value) $dql = "SELECT t FROM Tier t WHERE t.name = ?1"; $tiers = $entityManager->createQuery($dql) - ->setParameter(1, - (string) $xmlSite->TIER) + ->setParameter( + 1, + (string) $xmlSite->TIER + ) ->getResult(); /* Error checking: ensure each tier refers to exactly @@ -157,8 +171,10 @@ // get the SubGrid (optional value) $dql = "SELECT s FROM SubGrid s WHERE s.name = ?1"; $subGrids = $entityManager->createQuery($dql) - ->setParameter(1, - (string) $xmlSite->SUBGRID) + ->setParameter( + 1, + (string) $xmlSite->SUBGRID + ) ->getResult(); /* Error checking: ensure each subgrid refers to exactly @@ -174,8 +190,10 @@ //set creation date - $creationDate = new \DateTime("now", - new DateTimeZone('UTC')); + $creationDate = new \DateTime( + "now", + new DateTimeZone('UTC') + ); $doctrineSite->setCreationDate($creationDate); @@ -183,29 +201,35 @@ // The date of the CURRENT certStatus in v4 is recorded as // a link/linkType object using the dateOn property. For simplicity, we // store this date as an attribute on the Site. - foreach ($xmlCertStatusLinkDates as $xmlCertStatusLinkDate){ - $targetSiteName = (string) $xmlCertStatusLinkDate->name; - // only interested in the current site - if ($targetSiteName == $doctrineSite->getShortName()){ - // '01-JUL-13 11.09.10.000000 AM' which has the php datetime - // format of 'd-M-y H.i.s A' provided we - // trim off the '.000000' (millisecs) - // Note, '.000000' is present in all the elements. - $xmlLinkDateString = (string) $xmlCertStatusLinkDate->cert_date; - $xmlLinkDateString = preg_replace('/\.000000/', "", - $xmlLinkDateString); - $linkDate = \DateTime::createFromFormat('d-M-y H.i.s A', - $xmlLinkDateString, new \DateTimeZone('UTC')); - if (!$linkDate) { - throw new Exception("Can't parse date/time " . - $xmlLinkDateString . " for site " . - $doctrineSite->getShortName() . - ". Correct format: 27-JUL-11 02.02.03 PM" ); - } + foreach ($xmlCertStatusLinkDates as $xmlCertStatusLinkDate) { + $targetSiteName = (string) $xmlCertStatusLinkDate->name; + // only interested in the current site + if ($targetSiteName == $doctrineSite->getShortName()) { + // '01-JUL-13 11.09.10.000000 AM' which has the php datetime + // format of 'd-M-y H.i.s A' provided we + // trim off the '.000000' (millisecs) + // Note, '.000000' is present in all the elements. + $xmlLinkDateString = (string) $xmlCertStatusLinkDate->cert_date; + $xmlLinkDateString = preg_replace( + '/\.000000/', + "", + $xmlLinkDateString + ); + $linkDate = \DateTime::createFromFormat( + 'd-M-y H.i.s A', + $xmlLinkDateString, + new \DateTimeZone('UTC') + ); + if (!$linkDate) { + throw new Exception("Can't parse date/time " . + $xmlLinkDateString . " for site " . + $doctrineSite->getShortName() . + ". Correct format: 27-JUL-11 02.02.03 PM"); + } $doctrineSite->setCertificationStatusChangeDate($linkDate); - } + } } @@ -219,27 +243,27 @@ // necessarily correspond with the date of the CURRENT certification status. // Rather, the date of the CURRENT certStatus in v4 is recorded as // a link/linkType object using the dateOn property. - foreach ($xmlCertStatusChanges as $xmlCertStatusChange){ - $targetSiteName = (string) $xmlCertStatusChange->SITE; - // only interested in the current site - if ($targetSiteName == $doctrineSite->getShortName()){ - $doctrineCertStatusChangeLog = new \CertificationStatusLog(); - $doctrineCertStatusChangeLog->setAddedBy((string) - $xmlCertStatusChange->CHANGED_BY); - $doctrineCertStatusChangeLog->setOldStatus((string) - $xmlCertStatusChange->OLD_STATUS); - $doctrineCertStatusChangeLog->setNewStatus((string) - $xmlCertStatusChange->NEW_STATUS); - $doctrineCertStatusChangeLog->setReason((string) - $xmlCertStatusChange->COMMENT); - $insertDate = new DateTime("@" . - (string) $xmlCertStatusChange->UNIX_TIME); - $doctrineCertStatusChangeLog->setAddedDate($insertDate); - $entityManager->persist($doctrineCertStatusChangeLog); - $doctrineSite->addCertificationStatusLog( - $doctrineCertStatusChangeLog - ); - } + foreach ($xmlCertStatusChanges as $xmlCertStatusChange) { + $targetSiteName = (string) $xmlCertStatusChange->SITE; + // only interested in the current site + if ($targetSiteName == $doctrineSite->getShortName()) { + $doctrineCertStatusChangeLog = new \CertificationStatusLog(); + $doctrineCertStatusChangeLog->setAddedBy((string) + $xmlCertStatusChange->CHANGED_BY); + $doctrineCertStatusChangeLog->setOldStatus((string) + $xmlCertStatusChange->OLD_STATUS); + $doctrineCertStatusChangeLog->setNewStatus((string) + $xmlCertStatusChange->NEW_STATUS); + $doctrineCertStatusChangeLog->setReason((string) + $xmlCertStatusChange->COMMENT); + $insertDate = new DateTime("@" . + (string) $xmlCertStatusChange->UNIX_TIME); + $doctrineCertStatusChangeLog->setAddedDate($insertDate); + $entityManager->persist($doctrineCertStatusChangeLog); + $doctrineSite->addCertificationStatusLog( + $doctrineCertStatusChangeLog + ); + } } $entityManager->persist($doctrineSite); diff --git a/lib/Doctrine/deploy/AddUsers.php b/lib/Doctrine/deploy/AddUsers.php index 7567886c7..e75ca6124 100644 --- a/lib/Doctrine/deploy/AddUsers.php +++ b/lib/Doctrine/deploy/AddUsers.php @@ -44,11 +44,14 @@ $doctrineUser->setAdmin(false); // Roughly half of users don't have a home site set - if ($user->HOMESITE !== "" && !isBad($user->HOMESITE)) { + if ($user->HOMESITE !== "" && !isBad($user->HOMESITE)) { // Get the home site entity $dql = "SELECT s from Site s WHERE s.shortName = ?1"; $homeSites = $em->createQuery($dql) - ->setParameter(1, (string) $user->HOMESITE) + ->setParameter( + 1, + (string) $user->HOMESITE + ) ->getResult(); /* Error checking: ensure each "home site" refers to exactly diff --git a/lib/Doctrine/deploy/AddUtils.php b/lib/Doctrine/deploy/AddUtils.php index dd7359c26..9ff328e64 100644 --- a/lib/Doctrine/deploy/AddUtils.php +++ b/lib/Doctrine/deploy/AddUtils.php @@ -19,9 +19,9 @@ function findSEs($hostName, $serviceType) { /* Is the passed site invalid? * Uses a list of known bad sites */ function isBad($site) { - /* Roles over these sites are in the production data but can't be inserted - * into v5 because they don't have an NGI or a domain. v5 doesn't import - * sites without an NGI or domain + /* Roles over these sites are in the production data but can't be + * inserted into v5 because they don't have an NGI or a domain. + * v5 doesn't import sites without an NGI or domain * * Sites ignored becuase of no parent NGI: * Australia-UNIMELB-LCG2, GUP-JKU,UNIBAS, FZK-PPS, MA-01-CNRST, From f3d39d7eefbae9566545b2788b65dde081c1b722 Mon Sep 17 00:00:00 2001 From: rowan04 Date: Thu, 28 Sep 2023 14:58:19 +0000 Subject: [PATCH 5/5] Improve comment syntax in sample data deploy scripts --- .../deploy/AddCertificationStatuses.php | 6 +++--- lib/Doctrine/deploy/AddDowntimes.php | 18 +++++++++-------- lib/Doctrine/deploy/AddInfrastructures.php | 2 +- lib/Doctrine/deploy/AddNGIRoles.php | 15 ++++++++------ lib/Doctrine/deploy/AddNGIs.php | 15 +++++++------- lib/Doctrine/deploy/AddProjectRoles.php | 7 ++++--- lib/Doctrine/deploy/AddScopes.php | 2 +- lib/Doctrine/deploy/AddServiceEndpoints.php | 6 +++--- lib/Doctrine/deploy/AddServiceGroupRoles.php | 4 ++-- lib/Doctrine/deploy/AddSiteRoles.php | 18 +++++++++-------- lib/Doctrine/deploy/AddSites.php | 20 +++++++++---------- lib/Doctrine/deploy/AddUsers.php | 5 +++-- lib/Doctrine/deploy/AddUtils.php | 6 +++--- 13 files changed, 67 insertions(+), 57 deletions(-) diff --git a/lib/Doctrine/deploy/AddCertificationStatuses.php b/lib/Doctrine/deploy/AddCertificationStatuses.php index a95afedc9..f931b79ac 100644 --- a/lib/Doctrine/deploy/AddCertificationStatuses.php +++ b/lib/Doctrine/deploy/AddCertificationStatuses.php @@ -2,9 +2,9 @@ require_once __DIR__ . "/../bootstrap.php"; require_once __DIR__ . "/AddUtils.php"; -/* AddNGIs.php: Loads a list of cert statuses from an XML file and - * inserts them into the doctrine prototype. - * XML format is the xml input format of the cert status seed data +/* AddCertificationStatuses.php: Loads a list of cert statuses from + * an XML file and inserts them into the doctrine prototype. + * XML format is the xml input format of the cert status seed data. */ $certStatsFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . "/CertificationStatuses.xml"; diff --git a/lib/Doctrine/deploy/AddDowntimes.php b/lib/Doctrine/deploy/AddDowntimes.php index da43206fc..4e9f5c088 100644 --- a/lib/Doctrine/deploy/AddDowntimes.php +++ b/lib/Doctrine/deploy/AddDowntimes.php @@ -30,10 +30,9 @@ // Hack: the above SEs appear twice with the same service type. (nightmare) // However in most cases both SEs share the same downtimes... -// AddDowntimes.php: Loads a list of downtimes from an +// AddDowntimes.php: Loads a list of downtimes from an // XML file and inserts them into the doctrine prototype. -// XML format is the output from get_service_endpoints PI query. -// +// XML format is the output from get_downtime PI query. $allDowntimes = array(); @@ -57,14 +56,17 @@ $downtime = null; // See if we've already entered a downtime with this prom ID if (isset($allDowntimes[$promId])) { - // load $downtime from db by $promId rather than loading from global + // Load $downtime from db by $promId rather than loading from global // array. This assumes xml ID attribute (without 'G0' appended) is // the same as xml PRIMARY_KEY attribute. // // $downtime = $entityManager->createQuery("select d FROM Downtime " . // "d WHERE d.primaryKey = ?1") - // ->setParameter(1, (string) $promId.'G0') - // ->getResult(); + // ->setParameter( + // 1, + // (string) $promId.'G0' + // ) + // ->getResult(); $downtime = $allDowntimes[$promId]; } @@ -78,7 +80,7 @@ ); // There are some edge cases where findSEs returns - // more than one SE (see the comment at the top of this file) + // more than one SE (see the comment at the top of this file). // However if the downtime isn't yet created we always // link to the first SE found. if (!isset($services[0])) { @@ -141,7 +143,7 @@ // Check whether this exception is caused by a known issue // with duplicate SEs (see comment at the top of the file). // Issue is known if two SEs are found and the hostname is - // a known duplicate + // a known duplicate. $twoSes = false; if (count($services) == 2) { $twoSes = true; diff --git a/lib/Doctrine/deploy/AddInfrastructures.php b/lib/Doctrine/deploy/AddInfrastructures.php index c2814b76c..f28e7dd6a 100644 --- a/lib/Doctrine/deploy/AddInfrastructures.php +++ b/lib/Doctrine/deploy/AddInfrastructures.php @@ -3,7 +3,7 @@ require_once __DIR__ . "/../bootstrap.php"; require_once __DIR__ . "/AddUtils.php"; -/* AddNGIs.php: Loads a list of infrastructures from an XML file and +/* AddInfrastructures.php: Loads a list of infrastructures from an XML file and * inserts them into the doctrine prototype. * XML format is the xml input production status format. */ diff --git a/lib/Doctrine/deploy/AddNGIRoles.php b/lib/Doctrine/deploy/AddNGIRoles.php index 7894f63a4..d21f103f8 100644 --- a/lib/Doctrine/deploy/AddNGIRoles.php +++ b/lib/Doctrine/deploy/AddNGIRoles.php @@ -19,7 +19,7 @@ continue; } - // get roletype entity + // Get roletype entity $dql = "SELECT rt FROM RoleType rt WHERE rt.name = :roleType"; $roleTypes = $entityManager->createQuery($dql) ->setParameter( @@ -27,8 +27,9 @@ (string) $role->USER_ROLE ) ->getResult(); + // /* Error checking: ensure each role type refers to exactly - // * one role type*/ + // * one role type */ if (count($roleTypes) !== 1) { throw new Exception(count($roleTypes) . " role types found " . "with name: " . $role->USER_ROLE); @@ -59,8 +60,8 @@ $doctrineUser = $doctrineUser; } - // Check for invalid NGIs and skip - // typically these are decomissioned ROCs + // Check for invalid NGIs and skip. + // Typically these are decomissioned ROCs. if ( $role->ON_ENTITY == 'GridIreland' || $role->ON_ENTITY == 'NGS' @@ -71,7 +72,7 @@ continue; } - // get ngi entity + // Get ngi entity $ngiName = (string) $role->ON_ENTITY; $dql = "SELECT n FROM NGI n WHERE n.name = :ngi"; $ngis = $entityManager->createQuery($dql) @@ -80,6 +81,7 @@ $ngiName ) ->getResult(); + // /* Error checking: ensure each "ngi" refers to exactly // * one ngi */ if (count($ngis) !== 1) { @@ -91,7 +93,8 @@ $ngi = $ngi; } - //check that the role is not a duplicate (v4 data contaisn duplicates) + // Check that the role is not a duplicate + // (v4 data contains duplicates) $ExistingUserRoles = $doctrineUser->getRoles(); $thisIsADuplicateRole=false; foreach ($ExistingUserRoles as $role) { diff --git a/lib/Doctrine/deploy/AddNGIs.php b/lib/Doctrine/deploy/AddNGIs.php index 58441c329..30f02a7cc 100644 --- a/lib/Doctrine/deploy/AddNGIs.php +++ b/lib/Doctrine/deploy/AddNGIs.php @@ -16,11 +16,12 @@ $egiProject = $entityManager->getRepository('Project') ->findOneBy(array("name" => "EGI")); -//Find the EGI scope tag +// Find the EGI scope tag $egiScope = $entityManager->getRepository('Scope') ->findOneBy(array("name" => "EGI")); -//Add Local Scope so specified NGI is not part of EGI project +// Add Local Scope so that the specified NGI is +// not part of the EGI project $localScope = $entityManager->getRepository('Scope') ->findOneBy(array("name" => "Local")); @@ -68,7 +69,7 @@ // '12-JAN-10 14.12.56.000000' $cdateonString = (string) $value; - //convert to date time + // Convert to date time $creationDate = DateTime::createFromFormat( 'd-M-y G.i.s.u', $cdateonString, @@ -94,12 +95,12 @@ //if ($cdateon == null) throw new Exception("CDATEON is null"); //$doctrineNgi->setCreationDate($cdateon); - // if the NGI has id 67518 (NGI_HU) do not add it to EGI Project + // If the NGI has id 67518 (NGI_HU) do not add it to EGI Project if ($objectID == "67518") { $doctrineNgi->addScope($localScope); $entityManager->persist($doctrineNgi); } else { - // add NGI to EGI project and give it EGI scope + // Add NGI to EGI project and give it EGI scope $egiProject->addNgi($doctrineNgi); $doctrineNgi->addScope($egiScope); $entityManager->persist($doctrineNgi); @@ -107,6 +108,6 @@ } -// don't need to merge egiProject -//$entityManager->merge($egiProject); +// Don't need to merge egiProject +// $entityManager->merge($egiProject); $entityManager->flush(); diff --git a/lib/Doctrine/deploy/AddProjectRoles.php b/lib/Doctrine/deploy/AddProjectRoles.php index f626ea76e..140d76bb3 100644 --- a/lib/Doctrine/deploy/AddProjectRoles.php +++ b/lib/Doctrine/deploy/AddProjectRoles.php @@ -4,7 +4,7 @@ require_once __DIR__ . "/AddUtils.php"; /** - * AddEgiRoles.php: Loads a list of roles from the get_user PI + * AddProjectRoles.php: Loads a list of roles from the get_user PI * query output (XML), finds what project entity the role is over, * if the project entity refers to exactly one project the role is * added to that project and inserted into the doctrine prototype. @@ -28,7 +28,7 @@ continue; } - // get roletype entity + // Get roletype entity $dql = "SELECT rt FROM RoleType rt WHERE rt.name = :roleType"; $roleTypes = $entityManager->createQuery($dql) ->setParameter( @@ -36,8 +36,9 @@ (string) $role->USER_ROLE ) ->getResult(); + // /* Error checking: ensure each role type refers to exactly - // * one role type*/ + // * one role type */ if (count($roleTypes) !== 1) { throw new Exception(count($roleTypes) . " role types found " . "with name: " . $role->USER_ROLE); diff --git a/lib/Doctrine/deploy/AddScopes.php b/lib/Doctrine/deploy/AddScopes.php index 2d52e1d1f..9b20f53a4 100644 --- a/lib/Doctrine/deploy/AddScopes.php +++ b/lib/Doctrine/deploy/AddScopes.php @@ -3,7 +3,7 @@ require_once __DIR__ . "/../bootstrap.php"; require_once __DIR__ . "/AddUtils.php"; -/* AddNGIs.php: Loads a list of scopes from an XML file and +/* AddScopes.php: Loads a list of scopes from an XML file and * inserts them into the doctrine prototype. * XML format is the xml input format for scope data */ diff --git a/lib/Doctrine/deploy/AddServiceEndpoints.php b/lib/Doctrine/deploy/AddServiceEndpoints.php index c2c44f2bc..d7827e489 100644 --- a/lib/Doctrine/deploy/AddServiceEndpoints.php +++ b/lib/Doctrine/deploy/AddServiceEndpoints.php @@ -41,7 +41,7 @@ foreach ($ses as $xmlSe) { $doctrineSe = new Service(); - // get the hosting site entity + // Get the hosting site entity $dql = "SELECT s from Site s WHERE s.shortName = ?1"; $parentSites = $entityManager->createQuery($dql) ->setParameter( @@ -64,7 +64,7 @@ $doctrineSe->setParentSiteDoJoin($parentSite); - // get the hosting service type + // Get the hosting service type $dql = "SELECT s from ServiceType s WHERE s.name = ?1"; $sts = $entityManager->createQuery($dql) ->setParameter( @@ -117,7 +117,7 @@ " for SE " . $xmlSe->HOSTNAME); } - //set creation date + // Set creation date $creationDate = new \DateTime("now", new DateTimeZone('UTC')); diff --git a/lib/Doctrine/deploy/AddServiceGroupRoles.php b/lib/Doctrine/deploy/AddServiceGroupRoles.php index 81f0f1a5c..38a556f33 100644 --- a/lib/Doctrine/deploy/AddServiceGroupRoles.php +++ b/lib/Doctrine/deploy/AddServiceGroupRoles.php @@ -19,7 +19,7 @@ continue; } - // get roletype entity + // Get roletype entity $userRole = (string) $role->USER_ROLE; $dql = "SELECT rt FROM RoleType rt WHERE rt.name = :roleType"; $roleTypes = $entityManager->createQuery($dql) @@ -65,7 +65,7 @@ // Set $doctrineUser as the first and only user in the users array $doctrineUser = $users[0]; - // get serviceGroup entity + // Get serviceGroup entity $sgName = (string) $role->ON_ENTITY; $dql = "SELECT sg FROM ServiceGroup sg WHERE " . "sg.name = :service_group"; diff --git a/lib/Doctrine/deploy/AddSiteRoles.php b/lib/Doctrine/deploy/AddSiteRoles.php index b3a1e6315..68fe495d2 100644 --- a/lib/Doctrine/deploy/AddSiteRoles.php +++ b/lib/Doctrine/deploy/AddSiteRoles.php @@ -4,7 +4,7 @@ require_once __DIR__ . "/AddUtils.php"; /** - * AddNGIs.php: Loads a list of Site roles from an XML file and + * AddSiteRoles.php: Loads a list of Site roles from an XML file and * inserts them into the doctrine prototype. * XML format is the output from get_user_doctrine PI query. */ @@ -24,8 +24,7 @@ continue; } - // Find the role type - // get the roletype entity + // Find the role type and get the roletype entity $dql = "SELECT rt FROM RoleType rt WHERE rt.name = ?1"; $roleTypes = $entityManager->createQuery($dql) ->setParameter( @@ -33,6 +32,7 @@ (string) $role->USER_ROLE ) ->getResult(); + // /* Error checking: ensure each role type refers to exactly // * one role type */ if (count($roleTypes) !== 1) { @@ -73,14 +73,14 @@ throw new Exception("Not a doctrine user"); } - // Check for invalid sites and skip adding this role - // typically these sites don't have an NGI, - // country or production status + // Check for invalid sites and skip adding this role. + // Typically these sites don't have an NGI, + // country or production status. if (isBad((string) $role->ON_ENTITY)) { continue; } - // get the site entity + // Get the site entity $dql = "SELECT s FROM Site s WHERE s.shortName = ?1"; $sites = $entityManager->createQuery($dql) ->setParameter( @@ -88,6 +88,7 @@ (string) $role->ON_ENTITY ) ->getResult(); + // /* Error checking: ensure each "site" refers to exactly // * one site */ if (count($sites) !== 1) { @@ -103,7 +104,8 @@ throw new Exception("Not a doctrine site"); } - //check that the role is not a duplicate (v4 data contaisn duplicates) + // Check that the role is not a duplicate + // (v4 data contains duplicates) $ExistingUserRoles = $doctrineUser->getRoles(); $thisIsADuplicateRole=false; foreach ($ExistingUserRoles as $role) { diff --git a/lib/Doctrine/deploy/AddSites.php b/lib/Doctrine/deploy/AddSites.php index 3f6296e5c..601e6f850 100644 --- a/lib/Doctrine/deploy/AddSites.php +++ b/lib/Doctrine/deploy/AddSites.php @@ -20,7 +20,7 @@ // Check whether this site has a larger v4 primary key // than any other recorded so far $v4pkGO = trim((string) $xmlSite->PRIMARY_KEY); - // isolate just the number part (slice the 'GO' off the end) + // Isolate just the number part (slice the 'GO' off the end) $v4pk = (int) substr($v4pkGO, 0, strlen($v4pkGO)-2); if ($v4pk > $largestV4SitePk) { $largestV4SitePk = $v4pk; @@ -53,7 +53,7 @@ $doctrineSite->setAlarmEmail((string) $xmlSite->ALARM_EMAIL); $doctrineSite->setHelpdeskEmail((string) $xmlSite->HELPDESKEMAIL); - // get the parent NGI entity + // Get the parent NGI entity $dql = "SELECT n FROM NGI n WHERE n.name = ?1"; $parentNgis = $entityManager->createQuery($dql) ->setParameter( @@ -75,7 +75,7 @@ $doctrineSite->setNgiDoJoin($parentNgi); - // get the target infrastructure + // Get the target infrastructure $dql = "SELECT i FROM Infrastructure i WHERE i.name = :name"; $infs = $entityManager->createQuery($dql) ->setParameter( @@ -97,7 +97,7 @@ $doctrineSite->setInfrastructure($inf); - // get the cert status + // Get the cert status $dql = "SELECT c FROM CertificationStatus c WHERE c.name = ?1"; $certStatuses = $entityManager->createQuery($dql) ->setParameter( @@ -126,7 +126,7 @@ ) ); - // get / set the country + // Get / set the country $dql = "SELECT c FROM Country c WHERE c.name = ?1"; $countries = $entityManager->createQuery($dql) ->setParameter( @@ -149,7 +149,7 @@ $doctrineSite->setCountry($country); - // get the Tier (optional value) + // Get the Tier (optional value) $dql = "SELECT t FROM Tier t WHERE t.name = ?1"; $tiers = $entityManager->createQuery($dql) ->setParameter( @@ -168,7 +168,7 @@ $doctrineSite->setTier($tier); } - // get the SubGrid (optional value) + // Get the SubGrid (optional value) $dql = "SELECT s FROM SubGrid s WHERE s.name = ?1"; $subGrids = $entityManager->createQuery($dql) ->setParameter( @@ -189,7 +189,7 @@ - //set creation date + // Set creation date $creationDate = new \DateTime( "now", new DateTimeZone('UTC') @@ -203,7 +203,7 @@ // store this date as an attribute on the Site. foreach ($xmlCertStatusLinkDates as $xmlCertStatusLinkDate) { $targetSiteName = (string) $xmlCertStatusLinkDate->name; - // only interested in the current site + // Only interested in the current site if ($targetSiteName == $doctrineSite->getShortName()) { // '01-JUL-13 11.09.10.000000 AM' which has the php datetime // format of 'd-M-y H.i.s A' provided we @@ -245,7 +245,7 @@ // a link/linkType object using the dateOn property. foreach ($xmlCertStatusChanges as $xmlCertStatusChange) { $targetSiteName = (string) $xmlCertStatusChange->SITE; - // only interested in the current site + // Only interested in the current site if ($targetSiteName == $doctrineSite->getShortName()) { $doctrineCertStatusChangeLog = new \CertificationStatusLog(); $doctrineCertStatusChangeLog->setAddedBy((string) diff --git a/lib/Doctrine/deploy/AddUsers.php b/lib/Doctrine/deploy/AddUsers.php index e75ca6124..e7227c535 100644 --- a/lib/Doctrine/deploy/AddUsers.php +++ b/lib/Doctrine/deploy/AddUsers.php @@ -43,7 +43,8 @@ $user->WORKING_HOURS_END); $doctrineUser->setAdmin(false); - // Roughly half of users don't have a home site set + // Check if users don't have a homesite set, or + // if the homesite is 'bad'. if ($user->HOMESITE !== "" && !isBad($user->HOMESITE)) { // Get the home site entity $dql = "SELECT s from Site s WHERE s.shortName = ?1"; @@ -55,7 +56,7 @@ ->getResult(); /* Error checking: ensure each "home site" refers to exactly - * one home site */ + * one home site */ if (count($homeSites) !== 1) { throw new \Exception(count($homeSites) . " sites found " . "with short name: " . $user->HOMESITE . diff --git a/lib/Doctrine/deploy/AddUtils.php b/lib/Doctrine/deploy/AddUtils.php index 9ff328e64..6ec5c60c7 100644 --- a/lib/Doctrine/deploy/AddUtils.php +++ b/lib/Doctrine/deploy/AddUtils.php @@ -44,7 +44,7 @@ function isBad($site) { 'UIS-BUCARAMANGA', 'UTP-PANAMA', 'ITWM-PPS' , 'HU-BERLIN', 'SCAI-PPS', 'FZK-SC', 'FZK-Test', 'FZK-Test', 'GRIDOPS-GRIDVIEW', 'GSI-LCG2-PPS', - // next lot is from NGI_IE which was deleted. + // Next lot is from NGI_IE which was deleted. 'csTCDie', 'mpUCDie', 'giNUIMie', 'cpDIASie', 'csQUBuk', 'csUCCie', 'scgNUIGie', 'giITTAie', 'obsARMuk', 'giHECie', 'giRCSIie', 'giDCUie'); @@ -63,14 +63,14 @@ function isBad($site) { * @return \Scope */ function getScope($entityManager, $scope) { - // get the scope + // Get the scope $dql = "SELECT s FROM Scope s WHERE s.name = ?1"; $scopes = $entityManager->createQuery($dql) ->setParameter(1, $scope) ->getResult(); /* Error checking: ensure each Site's "SCOPE" refers to exactly - * one SCOPE */ + * one SCOPE */ if (count($scopes) !== 1) { throw new Exception(count($scopes) . " SCOPEs found " . "with name: " . $scope);