Exemplo n.º 1
0
 public function testSetInsertId()
 {
     $somePage = $this->createPage();
     $iId = time();
     $o = new Db_Object('Page');
     $o->setInsertId($iId);
     $userId = User::getInstance()->id;
     $this->assertEquals($iId, $o->getInssertId());
     $o->setValues(array('code' => $iId, 'is_fixed' => 1, 'html_title' => 'Index', 'menu_title' => 'Index', 'page_title' => 'Index', 'meta_keywords' => '', 'meta_description' => '', 'parent_id' => null, 'text' => '[Index page content]', 'func_code' => '', 'order_no' => 1, 'show_blocks' => true, 'published' => true, 'published_version' => 0, 'editor_id' => $userId, 'date_created' => date('Y-m-d H:i:s'), 'date_updated' => date('Y-m-d H:i:s'), 'author_id' => $userId, 'blocks' => '', 'theme' => 'default', 'date_published' => date('Y-m-d H:i:s'), 'in_site_map' => true, 'default_blocks' => true));
     $this->assertTrue((bool) $o->save());
     $this->assertTrue(Db_Object::objectExists('Page', $iId));
     $this->assertEquals($iId, $o->getId());
 }
Exemplo n.º 2
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;
 }