Esempio n. 1
0
 /**
  * Save in db
  *
  * @return false|integer
  */
 public function commit()
 {
     $context = ['table' => $this->table->getDbTable(), 'fields' => $this->fields];
     foreach ($this->fields as $field) {
         if ($field instanceof LazyValue) {
             $this->log('db.unitofwork.entity_add')->error('Find lazy value', $context);
             $this->entity->addError(false, $this->trans('db.unitofwork.find_lazy_value'));
             return false;
         }
     }
     $id = $this->db()->add($this->table->getDbTable(), $this->fields);
     if ($id > 0) {
         $this->id = $id;
         $this->fields[$this->table->getPkColumn()] = $id;
         if (!$this->repo->setLazy($this->entity, $id)) {
             return false;
         }
         return $id;
     } else {
         $error = print_r($this->db()->adaptor()->pdo()->errorInfo(), 1);
         $this->log('db.unitofwork.entity_add')->error('Error inset row. Error:' . $error);
         $this->entity->addError(false, $this->trans('db.unitofwork.add_unknow_error'));
         return false;
     }
 }
Esempio n. 2
0
 function it_commit(\BX\DB\UnitOfWork\Repository $repo)
 {
     $repo->setLazy($this->entity, Argument::any())->willReturn(true);
     $this->setRepository($repo);
     $this->validate()->shouldBe(true);
     $this->commit()->shouldBe('2');
     $return = ['ID' => '2', 'TEST' => 'TEST'];
     $this->db()->query('SELECT * FROM tbl_test WHERE ID = 2')->fetch()->shouldBe($return);
 }