public function addpropertyAction()
 {
     $this->view->stayHere = true;
     $edit = false;
     if ($id = $this->params->get('id')) {
         $edit = true;
     }
     $form = $this->view->form = $this->loadForm('syncProperty')->setDb($this->db());
     if ($edit) {
         $form->loadObject($id);
         $rule_id = $form->getObject()->rule_id;
         $form->setRule(SyncRule::load($rule_id, $this->db()));
     } elseif ($rule_id = $this->params->get('rule_id')) {
         $form->setRule(SyncRule::load($rule_id, $this->db()));
     }
     $form->setSuccessUrl('director/syncrule/property', array('rule_id' => $rule_id));
     $form->handleRequest();
     $tabs = $this->getTabs()->add('edit', array('url' => 'director/syncrule/edit', 'urlParams' => array('id' => $rule_id), 'label' => $this->translate('Edit sync rule')));
     if ($edit) {
         $tabs->add('property', array('label' => $this->translate('Properties'), 'url' => 'director/syncrule/property', 'urlParams' => array('rule_id' => $rule_id)));
     } else {
         $tabs->add('property', array('label' => $this->translate('Properties'), 'url' => 'director/syncrule/property', 'urlParams' => array('rule_id' => $rule_id)));
     }
     $tabs->activate('property');
     $this->view->title = $this->translate('Sync property');
     // add/edit
     $this->view->table = $this->loadTable('syncproperty')->enforceFilter(Filter::where('rule_id', $rule_id))->setConnection($this->db());
     $this->render('list/table', null, true);
 }
 public function onSuccess()
 {
     $sourceColumn = $this->getValue('source_column');
     if ($sourceColumn === self::EXPRESSION) {
         unset($this->source_column);
         $this->removeElement('source_column');
     } else {
         if (!$this->getElement('source_expression')) {
             $this->addHidden('source_expression', '${' . $sourceColumn . '}');
         }
     }
     $object = $this->getObject();
     $object->rule_id = $this->rule->id;
     // ?!
     $destination = $this->getValue('destination_field');
     if ($destination === 'vars.*') {
         $destination = $this->getValue('customvar');
         $object->destination_field = 'vars.' . $destination;
     }
     if ($object->hasBeenModified()) {
         if (!$object->hasBeenLoadedFromDb()) {
             $object->priority = $this->rule->getPriorityForNextProperty();
         }
     }
     return parent::onSuccess();
 }
 public function indexAction()
 {
     $edit = false;
     if ($id = $this->params->get('id')) {
         $edit = true;
     }
     if ($edit) {
         $this->view->title = $this->translate('Edit sync property rule');
         $this->getTabs()->add('edit', array('url' => 'director/syncproperty/edit' . '?id=' . $id, 'label' => $this->view->title))->activate('edit');
     } else {
         $this->view->title = $this->translate('Add sync property rule');
         $this->getTabs()->add('add', array('url' => 'director/syncproperty/add', 'label' => $this->view->title))->activate('add');
     }
     $form = $this->view->form = $this->loadForm('syncProperty')->setDb($this->db());
     if ($edit) {
         $form->loadObject($id);
         $rule_id = $form->getObject()->rule_id;
         $form->setRule(SyncRule::load($rule_id, $this->db()));
     } elseif ($rule_id = $this->params->get('rule_id')) {
         $form->setRule(SyncRule::load($rule_id, $this->db()));
     }
     $form->setSuccessUrl('director/syncrule/property', array('rule_id' => $rule_id));
     $form->handleRequest();
     $this->render('object/form', null, true);
 }
Example #4
0
 protected function runScheduledSyncs()
 {
     // TODO: import-triggered:
     //      foreach $rule->involvedImports() -> if changedsince -> ... syncChangedRows
     foreach (SyncRule::loadAll($this->db) as $rule) {
         Benchmark::measure('Checking sync rule ' . $rule->rule_name);
         $mod = Sync::getExpectedModifications($rule);
         if (count($mod) > 0) {
             printf('Sync rule "%s" provides changes, triggering sync... ', $rule->rule_name);
             Benchmark::measure('Got modifications for sync rule ' . $rule->rule_name);
             if (Sync::run($rule)) {
                 Benchmark::measure('Successfully synced rule ' . $rule->rule_name);
                 print "SUCCEEDED\n";
             }
         }
     }
     return $this;
 }
Example #5
0
 protected function getRowClasses($row)
 {
     if (!$this->revalidate) {
         return array();
     }
     try {
         // $mod = Sync::hasModifications(
         $mod = Sync::getExpectedModifications(SyncRule::load($row->id, $this->connection()));
         if (count($mod) > 0) {
             $row->rule_name = $row->rule_name . ' (' . count($mod) . ')';
             return 'pending-changes';
         } else {
             return 'in-sync';
         }
     } catch (Exception $e) {
         $row->rule_name = $row->rule_name . ' (' . $e->getMessage() . ')';
         return 'failing';
     }
 }
Example #6
0
 /**
  * Runs a SyncRule and applies all resulting changes
  *
  * TODO: Should return the id of the related sync_history table entry.
  *       Such a table does not yet exist, so 42 is the answer right now.
  *
  * @param  SyncRule $rule The synchronization rule that should be applied
  *
  * @return int
  */
 protected function runWithRule(SyncRule $rule)
 {
     $db = $rule->getConnection();
     // TODO: Evaluate whether fetching data should happen within the same transaction
     $objects = $this->prepareSyncForRule($rule);
     $dba = $db->getDbAdapter();
     $dba->beginTransaction();
     foreach ($objects as $object) {
         if ($object instanceof IcingaObject && $object->isTemplate()) {
             if ($object->hasBeenModified()) {
                 throw new IcingaException('Sync is not allowed to modify template "%s"', $object->{$objectKey});
             }
             continue;
         }
         if ($object->shouldBeRemoved()) {
             $object->delete($db);
             continue;
         }
         if ($object->hasBeenModified()) {
             $object->store($db);
         }
     }
     $dba->commit();
     return 42;
     // We have no sync_run history table yet
 }