示例#1
0
function newDowntime($downtimeXml)
{
    $downtime = new Downtime();
    foreach ($downtimeXml->attributes() as $key => $value) {
        switch ($key) {
            case "ID":
                $promId = (int) $value;
                break;
            case "PRIMARY_KEY":
                $primaryKey = (string) $value;
                break;
            case "CLASSIFICATION":
                $classification = (string) $value;
                break;
        }
    }
    // 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;
    }
    $downtime->setClassification($classification);
    $downtime->setDescription((string) $downtimeXml->DESCRIPTION);
    $downtime->setSeverity((string) $downtimeXml->SEVERITY);
    $startDate = new DateTime("@" . (string) $downtimeXml->START_DATE);
    $downtime->setStartDate($startDate);
    $endDate = new DateTime("@" . (string) $downtimeXml->END_DATE);
    $downtime->setEndDate($endDate);
    $insertDate = new DateTime("@" . (string) $downtimeXml->INSERT_DATE);
    $downtime->setInsertDate($insertDate);
    $downtime->setPrimaryKey($primaryKey);
    return $downtime;
}
示例#2
0
 /**
  * Ends a downtime
  * (Within the next 60 secs to avoid "Downtime can't be ended in the past" errors).
  * @param \Downtime $dt
  * @param \User $user User making the request
  * @throws \Exception
  */
 public function endDowntime(\Downtime $dt, \User $user = null)
 {
     //Check the portal is not in read only mode, throws exception if it is
     $this->checkPortalIsNotReadOnlyOrUserIsAdmin($user);
     $ses = $dt->getServices();
     $this->authorization($ses, $user);
     // Make sure all dates are treated as UTC!
     //date_default_timezone_set("UTC");
     if (!$dt->isOnGoing()) {
         throw new \Exception("Downtime isn't on-going.");
     }
     $sixtySecs = \DateInterval::createFromDateString('1 minutes');
     $now = new \DateTime(null, new \DateTimeZone('UTC'));
     $sixtySecsFromNow = $now->add($sixtySecs);
     //$this->validateDates($dt->getStartDate(), $end);
     // dt start date is in the future
     if ($dt->getStartDate() >= $sixtySecsFromNow) {
         throw new \Exception("Logic error - Downtime start time is after the requested end time");
     }
     // dt has already ended
     if ($dt->getEndDate() < $now) {
         throw new \Exception("Logic error - Downtime has already ended or will within the next 60 secs");
     }
     // ok. dt endDate is in the future and dt is ongoing/has started.
     $this->em->getConnection()->beginTransaction();
     try {
         $dt->setEndDate($sixtySecsFromNow);
         $this->em->merge($dt);
         $this->em->getConnection()->commit();
         $this->em->flush();
     } catch (\Exception $e) {
         $this->em->getConnection()->rollback();
         $this->em->close();
         throw $e;
     }
 }