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;
 }
 public function import()
 {
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("FruityTimeperiodImporter beginning to import Timeperiod Configuration.");
     // Timeperiods
     foreach ($this->dbConn->query("SELECT * FROM nagios_timeperiods", PDO::FETCH_ASSOC) as $timeperiod) {
         // Check for existing timeperiod
         if (NagiosTimeperiodPeer::getByName($timeperiod['timeperiod_name'])) {
             $job->addNotice("Fruity Timeperiod Importer:  The timeperiod " . $timeperiod['timeperiod_name'] . " already exists.  Aborting it's import.");
             continue;
         }
         $newTimeperiod = new NagiosTimeperiod();
         $newTimeperiod->setName($timeperiod['timeperiod_name']);
         $newTimeperiod->setAlias($timeperiod['alias']);
         $newTimeperiod->save();
         if (!empty($timeperiod['sunday'])) {
             $entry = new NagiosTimeperiodEntry();
             $entry->setEntry('sunday');
             $entry->setValue($timeperiod['sunday']);
             $entry->setNagiosTimeperiod($newTimeperiod);
             $entry->save();
         }
         if (!empty($timeperiod['monday'])) {
             $entry = new NagiosTimeperiodEntry();
             $entry->setEntry('monday');
             $entry->setValue($timeperiod['monday']);
             $entry->setNagiosTimeperiod($newTimeperiod);
             $entry->save();
         }
         if (!empty($timeperiod['tuesday'])) {
             $entry = new NagiosTimeperiodEntry();
             $entry->setEntry('tuesday');
             $entry->setValue($timeperiod['tuesday']);
             $entry->setNagiosTimeperiod($newTimeperiod);
             $entry->save();
         }
         if (!empty($timeperiod['wednesday'])) {
             $entry = new NagiosTimeperiodEntry();
             $entry->setEntry('wednesday');
             $entry->setValue($timeperiod['wednesday']);
             $entry->setNagiosTimeperiod($newTimeperiod);
             $entry->save();
         }
         if (!empty($timeperiod['thursday'])) {
             $entry = new NagiosTimeperiodEntry();
             $entry->setEntry('thursday');
             $entry->setValue($timeperiod['thursday']);
             $entry->setNagiosTimeperiod($newTimeperiod);
             $entry->save();
         }
         if (!empty($timeperiod['friday'])) {
             $entry = new NagiosTimeperiodEntry();
             $entry->setEntry('friday');
             $entry->setValue($timeperiod['friday']);
             $entry->setNagiosTimeperiod($newTimeperiod);
             $entry->save();
         }
         if (!empty($timeperiod['saturday'])) {
             $entry = new NagiosTimeperiodEntry();
             $entry->setEntry('saturday');
             $entry->setValue($timeperiod['saturday']);
             $entry->setNagiosTimeperiod($newTimeperiod);
             $entry->save();
         }
     }
     $job->addNotice("FruityTimeperiodImporter finished importing Timeperiod Configuration.");
 }
Example #3
0
                     }
                 }
             }
             if ($err) {
                 $error = "Entry value must be comma-delimited list of proper values.";
             } else {
                 // Check for existing entry with that name!
                 $c = new Criteria();
                 $c->add(NagiosTimeperiodEntryPeer::TIMEPERIOD_ID, $timeperiod->getId());
                 $c->add(NagiosTimeperiodEntryPeer::ENTRY, $entry);
                 $foundEntry = NagiosTimeperiodEntryPeer::doSelectOne($c);
                 if ($foundEntry) {
                     $error = "That entry already exists.  Remove it then add it with the new value.";
                 } else {
                     // Okay, let's add.
                     $newEntry = new NagiosTimeperiodEntry();
                     $newEntry->setTimeperiodId($timeperiod->getId());
                     $newEntry->setEntry($entry);
                     $newEntry->setValue($value);
                     $newEntry->save();
                     $success = "Entry added.";
                     $entry = '';
                     $value = '';
                 }
             }
         }
     }
 } else {
     if ($_POST['request'] == 'exclusion_add') {
         // first hceck to see if the exclusion exists.
         $c = new Criteria();
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      NagiosTimeperiodEntry $value A NagiosTimeperiodEntry object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(NagiosTimeperiodEntry $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }