Example #1
0
 /**
  * Saves a node to the Ldap store
  *
  * @param Node $node Node to be saved
  *
  * @return boolean True if node got created, false if it was updated
  *
  * @throws PersistenceException If saving operation fails writing to the Ldap
  */
 public function save(Node $node)
 {
     $this->validateBinding();
     if (strlen(trim($node->getDn())) == 0) {
         throw new PersistenceException('Cannot save: dn missing for the entry');
     }
     if (!$node->isHydrated()) {
         try {
             $origin = $this->getNode($node->getDn());
             $node->rebaseDiff($origin);
         } catch (NodeNotFoundException $e) {
             $this->connection->addEntry($node->getDn(), $node->getRawAttributes());
             $node->snapshot();
             return true;
         }
     }
     if (count($data = $node->getDiffAdditions()) > 0) {
         $this->connection->addAttributeValues($node->getDn(), $data);
     }
     if (count($data = $node->getDiffDeletions()) > 0) {
         $this->connection->deleteAttributeValues($node->getDn(), $data);
     }
     if (count($data = $node->getDiffReplacements()) > 0) {
         $this->connection->replaceAttributeValues($node->getDn(), $data);
     }
     $node->snapshot();
     return false;
 }