/**
  * 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      NagiosMainConfiguration $value A NagiosMainConfiguration object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(NagiosMainConfiguration $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
Ejemplo n.º 2
0
 public function import()
 {
     $job = $this->getEngine()->getJob();
     $config = $this->getEngine()->getConfig();
     $mainCfg = new NagiosMainConfiguration();
     $segment = $this->getSegment();
     $values = $segment->getValues();
     $fileName = $segment->getFilename();
     // Setup the configuration directory for the new config file to match the file we imported
     $mainCfg->setConfigDir(dirname(realpath($fileName)));
     foreach ($values as $key => $entries) {
         foreach ($entries as $entry) {
             $value = $entry['value'];
             $lineNum = $entry['line'];
             if (key_exists($key, $this->fieldMethods) && $this->fieldMethods[$key] != '') {
                 // Okay, let's check that the method DOES exist
                 if (!method_exists($mainCfg, $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], $mainCfg, $value);
                 }
             }
         }
     }
     // If we got here, it's safe to delete the existing main config and save the new one
     $oldConfig = NagiosMainConfigurationPeer::doSelectOne(new Criteria());
     if ($oldConfig) {
         $oldConfig->delete();
     }
     $mainCfg->save();
     $mainCfg->clearAllReferences(true);
     $job->addNotice("NagiosMainImporter finished importing main configuration.");
     return true;
 }