/** * Declares an association between this object and a NagiosTimeperiod object. * * @param NagiosTimeperiod $v * @return NagiosTimeperiodEntry The current object (for fluent API support) * @throws PropelException */ public function setNagiosTimeperiod(NagiosTimeperiod $v = null) { if ($v === null) { $this->setTimeperiodId(NULL); } else { $this->setTimeperiodId($v->getId()); } $this->aNagiosTimeperiod = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the NagiosTimeperiod object, it will not be re-added. if ($v !== null) { $v->addNagiosTimeperiodEntry($this); } return $this; }
public function import() { $job = $this->getEngine()->getJob(); $config = $this->getEngine()->getConfig(); $timePeriod = new NagiosTimeperiod(); $segment = $this->getSegment(); // First check if we have a use $useTemplate = $segment->get("use"); if ($useTemplate) { // Okay, we need to check to see if we have an existing dependency $val = $useTemplate[0]['value']; $c = new Criteria(); $c->add(NagiosTimeperiodPeer::NAME, $val); $c->setIgnoreCase(true); $dependant = NagiosTimeperiodPeer::doSelectOne($c); if ($dependant) { // We need to add all the entries from that time period to ours. $entries = $dependant->getNagiosTimeperiodEntrys(); foreach ($entries as $entry) { $tempEntry = new NagiosTimeperiodEntry(); $tempEntry->setEntry($entry->getEntry()); $tempEntry->setValue($entry->getValue()); $timePeriod->addNagiosTimeperiodEntry($tempEntry); } $exclusions = $dependant->getNagiosTimeperiodExcludesRelatedByTimeperiodId(); foreach ($exclusions as $exclusion) { $tempExclusion = new NagiosTimeperiodExclude(); $tempExclusion->setNagiosTimeperiodRelatedByTimeperiodId($timePeriod); $tempExclusion->setNagiosTimeperiodRelatedByExcludedTimeperiod($exclusion->getNagiosTimeperiodRelatedByExcludedTimePeriod); } $dependent->clearAllReferences(true); } } $values = $segment->getValues(); $fileName = $segment->getFilename(); foreach ($values as $key => $entries) { foreach ($entries as $entry) { if ($key == "exclude") { continue; } $value = $entry['value']; $lineNum = $entry['line']; if ($key == "use") { continue; } if (key_exists($key, $this->fieldMethods) && $this->fieldMethods[$key] != '') { // Okay, let's check that the method DOES exist if (!method_exists($timePeriod, $this->fieldMethods[$key])) { $job->addError("Method " . $this->fieldMethods[$key] . " does not exist for variable: " . $key . " on line " . $lineNum . " in file " . $fileName); if (!$config->getVar('continue_error')) { return false; } } else { call_user_method($this->fieldMethods[$key], $timePeriod, $value); } } else { // It's an entry. Let's rebuild the string and grab the entry and value // This is pretty hackish $pos = $this->preg_pos("/[0-9]{1,2}:[0-9]{1,2}/", $entry['text']); // Look for the first 00:00 $tempLabel = trim(substr($entry['text'], 0, $pos - 1)); $commentPos = strpos($entry['text'], ";"); if ($commentPos === false) { $commentLength = 0; } else { $commentLength = strlen(substr($entry['text'], $commentPos)); } $valLength = strlen($entry['text']) - ($commentLength + $pos); $tempValue = trim(substr($entry['text'], $pos, $valLength)); $tempEntry = new NagiosTimeperiodEntry(); $tempEntry->setEntry($tempLabel); $tempEntry->setValue($tempValue); $timePeriod->addNagiosTimeperiodEntry($tempEntry); $tempEntry->clearAllReferences(true); } } } // Check to see if there is an exclusion $excludes = $segment->get("exclude"); if ($excludes) { $val = $excludes[0]['value']; // Multiple timeperiods are seperated by a comma $timeperiods = explode(",", $val); if (count($timeperiods)) { foreach ($timeperiods as $timeperiod) { $timeperiod = trim($timeperiod); $c = new Criteria(); $c->add(NagiosTimeperiodPeer::NAME, $val); $c->setIgnoreCase(true); $target = NagiosTimeperiodPeer::doSelectOne($c); if (!$target) { $job->addLogEntry("Dependent exclude timeperiod " . $timeperiod . " not found. ", ImportLogEntry::TYPE_NOTICE); return false; } else { $exclusion = new NagiosTimeperiodExclude(); $exclusion->setNagiosTimeperiodRelatedByTimeperiodId($timePeriod); $exclusion->setNagiosTimeperiodRelatedByExcludedTimeperiod($target); $exclusion->clearAllReferences(true); $target->clearAllReferences(true); } } } } $timePeriod->save(); $timePeriod->clearAllReferences(true); $job->addNotice("NagiosTimePeriodImporter finished importing timeperiod: " . $timePeriod->getName()); return true; }