diff --git a/lib/Doctrine/deploy/AddCertificationStatuses.php b/lib/Doctrine/deploy/AddCertificationStatuses.php index a3e3307df..f931b79ac 100644 --- a/lib/Doctrine/deploy/AddCertificationStatuses.php +++ b/lib/Doctrine/deploy/AddCertificationStatuses.php @@ -1,24 +1,26 @@ $value) { - if($key == "name") { + foreach ($certStat as $key => $value) { + if ($key == "name") { $name = (string) $value; } } + $doctrineCertStat->setName($name); $entityManager->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..f7dffc646 100644 --- a/lib/Doctrine/deploy/AddCountries.php +++ b/lib/Doctrine/deploy/AddCountries.php @@ -1,30 +1,33 @@ $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); } -$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..4e9f5c088 100644 --- a/lib/Doctrine/deploy/AddDowntimes.php +++ b/lib/Doctrine/deploy/AddDowntimes.php @@ -1,8 +1,8 @@ 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])) { - // 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. + 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. // - // $downtime = $entityManager->createQuery("select d FROM Downtime d WHERE d.primaryKey = ?1") - // ->setParameter(1, (string) $promId.'G0') - // ->getResult(); + // $downtime = $entityManager->createQuery("select d FROM Downtime " . + // "d WHERE d.primaryKey = ?1") + // ->setParameter( + // 1, + // (string) $promId.'G0' + // ) + // ->getResult(); $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 - $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) + // 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 . " "); + if (!isset($services[0])) { + throw new Exception("No SE found with hostname " . + $downtimeXml->HOSTNAME . " "); } // Bidirectional link the el and dt @@ -91,33 +97,38 @@ $GLOBALS['allDowntimes'][$promId] = $downtime; } else { // Find the SE and link it to the downtime - $services = findSEs((string) $downtimeXml->HOSTNAME - , (string) $downtimeXml->SERVICE_TYPE); - - if(!isset($services[0])) { - throw new Exception("No SE found with " - . "hostname " . $downtimeXml->HOSTNAME . " "); + $services = findSEs( + (string) $downtimeXml->HOSTNAME, + (string) $downtimeXml->SERVICE_TYPE + ); + + 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 - // 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'); + 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 - throw new AlreadyLinkedException("Downtime {$downtime->getId()} is already " - . "linked to el {$existingEL->getId()}"); + 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,43 +137,46 @@ //$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 // 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) { + if (count($services) == 2) { $twoSes = true; } else { // we will have to deal with this case and link the - throw new Exception("More than duplicate 2 SEs found: ".$services[0]->getHostName()); + throw new Exception("More than duplicate 2 SEs found: " . + $services[0]->getHostName()); } $knownDup = false; - foreach($duplicateSes as $dup) { - if($dup == $services[0]->getHostName()) { + foreach ($duplicateSes as $dup) { + if ($dup == $services[0]->getHostName()) { $knownDup = true; } } - // 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) { + // 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(); // 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 @@ -173,7 +187,7 @@ } } -foreach($allDowntimes as $downtime) { +foreach ($allDowntimes as $downtime) { $GLOBALS['entityManager']->persist($downtime); } @@ -183,11 +197,11 @@ 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) { + foreach ($downtimeXml->attributes() as $key => $value) { switch($key) { case "ID": $promId = (int) $value; @@ -201,10 +215,10 @@ 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']){ + if ($v4pk > $GLOBALS['largestV4DowntimePK']) { $GLOBALS['largestV4DowntimePK'] = $v4pk; } diff --git a/lib/Doctrine/deploy/AddInfrastructures.php b/lib/Doctrine/deploy/AddInfrastructures.php index 71a618056..f28e7dd6a 100644 --- a/lib/Doctrine/deploy/AddInfrastructures.php +++ b/lib/Doctrine/deploy/AddInfrastructures.php @@ -1,25 +1,27 @@ $value) { - if($key == "name") { + foreach ($xmlInf as $key => $value) { + if ($key == "name") { $name = (string) $value; } } + $doctrineInf->setName($name); $entityManager->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..d21f103f8 100644 --- a/lib/Doctrine/deploy/AddNGIRoles.php +++ b/lib/Doctrine/deploy/AddNGIRoles.php @@ -1,15 +1,16 @@ 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; } @@ -18,72 +19,101 @@ continue; } - // get roletype entity + // 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); + // * one role type */ + 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; } // 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 */ - 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' - || $role->ON_ENTITY == 'LondonT2' || $role->ON_ENTITY == 'Tier1A' - || $role->ON_ENTITY == 'Tier1A') { + // 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' + ) { 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) - ->setParameter('ngi', $ngiName) - ->getResult(); + ->setParameter( + 'ngi', + $ngiName + ) + ->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) + // Check that the role is not a duplicate + // (v4 data contains 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){ - $doctrineRole = new Role($roleType, $doctrineUser, $ngi, 'STATUS_GRANTED'); + 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 c690b8b29..30f02a7cc 100644 --- a/lib/Doctrine/deploy/AddNGIs.php +++ b/lib/Doctrine/deploy/AddNGIs.php @@ -1,11 +1,11 @@ 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")); +// 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 -$localScope = $entityManager->getRepository('Scope')->findOneBy(array("name" => "Local")); +// Add Local Scope so that the specified NGI is +// not part of the EGI project +$localScope = $entityManager->getRepository('Scope') + ->findOneBy(array("name" => "Local")); -foreach($ngis as $xmlNgi) { +foreach ($ngis as $xmlNgi) { $doctrineNgi = new NGI(); $name = ""; $email = ""; @@ -61,14 +65,20 @@ } 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')); + // Convert to date time + $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 . "'"); } } @@ -82,15 +92,15 @@ $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 + // 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); @@ -98,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 1a722d683..140d76bb3 100644 --- a/lib/Doctrine/deploy/AddProjectRoles.php +++ b/lib/Doctrine/deploy/AddProjectRoles.php @@ -1,10 +1,10 @@ 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; } @@ -27,34 +28,44 @@ continue; } - // get roletype entity + // 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); + // * one role type */ + 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; } // 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 */ - 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; } @@ -64,18 +75,29 @@ // 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/AddProjects.php b/lib/Doctrine/deploy/AddProjects.php index b396a781c..a1e45d5ae 100644 --- a/lib/Doctrine/deploy/AddProjects.php +++ b/lib/Doctrine/deploy/AddProjects.php @@ -1,8 +1,8 @@ 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..3217bfa12 100644 --- a/lib/Doctrine/deploy/AddRoleTypes.php +++ b/lib/Doctrine/deploy/AddRoleTypes.php @@ -1,7 +1,7 @@ setName($roleType[0]); //$rt->setClassification($roleType[1]); @@ -42,9 +42,9 @@ foreach ($roleTypeArray as $key => $value) { $rt = new RoleType($value); //echo $value; - if($value != RoleTypeName::GOCDB_ADMIN){ + if ($value != RoleTypeName::GOCDB_ADMIN) { $entityManager->persist($rt); } } -$entityManager->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..9b20f53a4 100644 --- a/lib/Doctrine/deploy/AddScopes.php +++ b/lib/Doctrine/deploy/AddScopes.php @@ -1,32 +1,34 @@ $value) { + foreach ($scope as $key => $value) { switch ($key) { case "name": $name = (string) $value; break; case "reserved": - $reserved = ( $value == 1 ); + $reserved = ($value == 1); break; } } + $doctrineScope->setName($name); $doctrineScope->setReserved($reserved); $entityManager->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..d7827e489 100644 --- a/lib/Doctrine/deploy/AddServiceEndpoints.php +++ b/lib/Doctrine/deploy/AddServiceEndpoints.php @@ -1,67 +1,83 @@ 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) { $egiScope = $egiScope; } // 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) { $localScope = $localScope; } 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(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) { $parentSite = $result; } + $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(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) { @@ -94,13 +110,14 @@ // 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 . " for SE " . $xmlSe->HOSTNAME); + throw new Exception("Unknown scope " . $xmlSe->SCOPE . + " for SE " . $xmlSe->HOSTNAME); } - //set creation date + // Set creation date $creationDate = new \DateTime("now", new DateTimeZone('UTC')); @@ -116,10 +133,12 @@ $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); $entityManager->persist($doctrineEndpointLocation); } -$entityManager->flush(); \ No newline at end of file + +$entityManager->flush(); diff --git a/lib/Doctrine/deploy/AddServiceGroupRoles.php b/lib/Doctrine/deploy/AddServiceGroupRoles.php index 0690473be..38a556f33 100644 --- a/lib/Doctrine/deploy/AddServiceGroupRoles.php +++ b/lib/Doctrine/deploy/AddServiceGroupRoles.php @@ -19,11 +19,14 @@ 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) - ->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(); /* @@ -59,11 +65,15 @@ // 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"; + $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/AddServiceGroups.php b/lib/Doctrine/deploy/AddServiceGroups.php index 715baf169..e5a87eec6 100644 --- a/lib/Doctrine/deploy/AddServiceGroups.php +++ b/lib/Doctrine/deploy/AddServiceGroups.php @@ -1,7 +1,7 @@ $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); } -$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..68fe495d2 100644 --- a/lib/Doctrine/deploy/AddSiteRoles.php +++ b/lib/Doctrine/deploy/AddSiteRoles.php @@ -1,105 +1,133 @@ 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; } - // 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(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*/ - if(count($roleTypes) !== 1) { - throw new Exception(count($roleTypes) . " role types found with name: " . - $role->USER_ROLE); + // * one role type */ + 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"); } // 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 */ - 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)) { + // 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(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); + 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) + // Check that the role is not a duplicate + // (v4 data contains 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){ - $doctrineRole = new Role($roleType, $doctrineUser, $doctrineSite, 'STATUS_GRANTED'); + 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..601e6f850 100644 --- a/lib/Doctrine/deploy/AddSites.php +++ b/lib/Doctrine/deploy/AddSites.php @@ -2,25 +2,27 @@ 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) { +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){ + // Isolate just the number part (slice the 'GO' off the end) + $v4pk = (int) substr($v4pkGO, 0, strlen($v4pkGO)-2); + if ($v4pk > $largestV4SitePk) { $largestV4SitePk = $v4pk; } @@ -35,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); @@ -51,97 +53,134 @@ $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(1, (string) $xmlSite->ROC) - ->getResult(); + ->setParameter( + 1, + (string) $xmlSite->ROC + ) + ->getResult(); + // /* Error checking: ensure each SE's "parent ngi" refers to exactly - // * one ngi */ - if(count($parentNgis) !== 1) { + // * one ngi */ + 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 + // 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(); - // /* 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); + ->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) { + 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 + // 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); + 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)); + $doctrineSite->addScope( + getScope( + $entityManager, + (string) $xmlSite->SCOPE + ) + ); - // get / set the country + // 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); + 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); - // 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(1, (string) $xmlSite->TIER) - ->getResult(); + ->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; } $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(1, (string) $xmlSite->SUBGRID) - ->getResult(); + ->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; } @@ -150,8 +189,11 @@ - //set creation date - $creationDate = new \DateTime("now", new DateTimeZone('UTC')); + // Set creation date + $creationDate = new \DateTime( + "now", + new DateTimeZone('UTC') + ); $doctrineSite->setCreationDate($creationDate); @@ -159,50 +201,69 @@ // 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); - } + } } // 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 // 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); @@ -211,11 +272,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 4df23c52e..e7227c535 100644 --- a/lib/Doctrine/deploy/AddUsers.php +++ b/lib/Doctrine/deploy/AddUsers.php @@ -1,13 +1,14 @@ 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 - if ($user->HOMESITE !== "" && !isBad($user->HOMESITE)) { + // 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"; $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 */ + * 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) { $homeSite = $result; } + $doctrineUser->setHomeSiteDoJoin($homeSite); } $em->persist($doctrineUser); $em->flush(); - $serv->addUserIdentifier($doctrineUser, $identifierArr, $doctrineUser); + $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..6ec5c60c7 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; } @@ -18,35 +19,43 @@ 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, 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' - // next lot is from NGI_IE which was deleted. - , 'csTCDie', 'mpUCDie', 'giNUIMie', 'cpDIASie', 'csQUBuk', 'csUCCie' - , 'scgNUIGie', 'giITTAie', 'obsARMuk', 'giHECie', 'giRCSIie' - , 'giDCUie'); + $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'); - 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 @@ -54,15 +63,17 @@ 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(); + ->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); + * one SCOPE */ + if (count($scopes) !== 1) { + throw new Exception(count($scopes) . " SCOPEs found " . + "with name: " . $scope); } return $scopes[0]; diff --git a/lib/Doctrine/deploy/DeployRequiredDataRunner.php b/lib/Doctrine/deploy/DeployRequiredDataRunner.php index 5b030a921..eee338d98 100644 --- a/lib/Doctrine/deploy/DeployRequiredDataRunner.php +++ b/lib/Doctrine/deploy/DeployRequiredDataRunner.php @@ -13,9 +13,9 @@ * limitations under the License. */ -require_once __DIR__."/AddUtils.php"; +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"); @@ -23,17 +23,17 @@ print_r("Deploying Required Lookup Data\n"); -require __DIR__."/AddInfrastructures.php"; +require __DIR__ . "/AddInfrastructures.php"; echo "Added Infrastructures OK\n"; -require __DIR__."/AddCountries.php"; +require __DIR__ . "/AddCountries.php"; echo "Added Countries OK\n"; -require __DIR__."/AddRoleTypes.php"; +require __DIR__ . "/AddRoleTypes.php"; echo "Added Roles OK\n"; -require __DIR__."/AddCertificationStatuses.php"; +require __DIR__ . "/AddCertificationStatuses.php"; echo "Added Certification Statuses OK\n"; -require __DIR__."/AddServiceTypes.php"; +require __DIR__ . "/AddServiceTypes.php"; echo "Added Service Types OK\n"; diff --git a/lib/Doctrine/deploy/DeploySampleDataRunner.php b/lib/Doctrine/deploy/DeploySampleDataRunner.php index 48f8a60e5..97d80a44f 100644 --- a/lib/Doctrine/deploy/DeploySampleDataRunner.php +++ b/lib/Doctrine/deploy/DeploySampleDataRunner.php @@ -14,44 +14,44 @@ */ -require_once __DIR__."/AddUtils.php"; +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"); } -print_r("Deploying Sample Data from ".$GLOBALS['dataDir']."\n"); +print_r("Deploying Sample Data from " . $GLOBALS['dataDir'] . "\n"); -require __DIR__."/AddProjects.php"; +require __DIR__ . "/AddProjects.php"; echo "Added Projects OK\n"; -require __DIR__."/AddScopes.php"; +require __DIR__ . "/AddScopes.php"; echo "Added Scopes OK\n"; -require __DIR__."/AddNGIs.php"; +require __DIR__ . "/AddNGIs.php"; echo "Added NGIs OK\n"; -require __DIR__."/AddSites.php"; +require __DIR__ . "/AddSites.php"; echo "Added Sites and JOINED to NGIs OK\n"; -require __DIR__."/AddServiceEndpoints.php"; +require __DIR__ . "/AddServiceEndpoints.php"; echo "Added Services, EndpointLocations and JOINED associations OK\n"; -require __DIR__."/AddServiceGroups.php"; +require __DIR__ . "/AddServiceGroups.php"; echo "Added Service Groups OK\n"; -require __DIR__."/AddUsers.php"; +require __DIR__ . "/AddUsers.php"; echo "Added Users OK\n"; -require __DIR__."/AddSiteRoles.php"; +require __DIR__ . "/AddSiteRoles.php"; echo "Added Site level Roles OK\n"; -require __DIR__."/AddNGIRoles.php"; +require __DIR__ . "/AddNGIRoles.php"; echo "Added NGI level Roles OK\n"; -require __DIR__."/AddProjectRoles.php"; +require __DIR__ . "/AddProjectRoles.php"; echo "Added EGI level Roles OK\n"; require __DIR__ . "/AddServiceGroupRoles.php";