Esempio n. 1
0
 /**
  * Do update action.
  *
  * @param   mixed  $dataset     Data set contain data we want to update.
  * @param   array  $condFields  The where condition tell us record exists or not, if not set,
  *                              will use primary key instead.
  * @param   bool  $updateNulls  Update empty fields or not.
  *
  * @throws  \Exception
  * @return  mixed Updated data set.
  */
 protected function doUpdate($dataset, array $condFields, $updateNulls = false)
 {
     !$this->useTransaction ?: $this->db->transactionStart(true);
     try {
         foreach ($dataset as $k => $data) {
             if (!$data instanceof $this->dataClass) {
                 $data = $this->bindData($data);
             }
             $entity = new Entity($this->getFields($this->table), $data);
             $this->db->updateOne($this->table, $entity, $condFields, $updateNulls);
             $dataset[$k] = $data;
         }
     } catch (\Exception $e) {
         !$this->useTransaction ?: $this->db->transactionRollback(true);
         throw $e;
     }
     !$this->useTransaction ?: $this->db->transactionCommit(true);
     return $dataset;
 }