Exemple #1
0
 protected function _insertOperation(Db_Object $object)
 {
     $insertId = $object->getInssertId();
     if ($insertId) {
         $updates = array_merge($object->getData(), $object->getUpdates());
         $updates[$object->getConfig()->getPrimaryKey()] = $insertId;
     } else {
         $updates = $object->getUpdates();
     }
     if ($object->getConfig()->hasEncrypted()) {
         $updates = $this->encryptData($object, $updates);
     }
     if (empty($updates)) {
         return false;
     }
     /*
      * Validate unique values
      */
     $values = $object->validateUniqueValues();
     if (!empty($values)) {
         if ($this->_log) {
             $errors = array();
             foreach ($values as $k => $v) {
                 $errors[] = $k . ':' . $v;
             }
             $this->_log->log($object->getName() . '::insert ' . implode(', ', $errors));
         }
         return false;
     }
     $db = $this->_getDbConnection($object);
     $objectTable = $object->getTable();
     if (!$db->insert($objectTable, $object->serializeLinks($updates))) {
         return false;
     }
     $id = $db->lastInsertId($objectTable, $object->getConfig()->getPrimaryKey());
     if (!$id) {
         return false;
     }
     $object->setId($id);
     if (!$this->_updateLinks($object)) {
         return false;
     }
     $object->commitChanges();
     $object->setId($id);
     return true;
 }