示例#1
0
 /**
  * @param       $table
  * @param array $data
  *
  * @return bool|null
  * @throws Exception
  */
 public function updateOrInsert($table, array $data = [])
 {
     $primaryKeys = $this->repository->getCache()->getTablePrimaryKeys($table);
     /**
      * @T00D00 - bug for translations, permissions ...!
      */
     if (!$primaryKeys) {
         return;
     }
     foreach ($primaryKeys as $primaryKey) {
         if (!isset($data[$primaryKey])) {
             return;
         }
     }
     $this->entity->setTable($table);
     foreach ($primaryKeys as $primaryKey) {
         $this->entity->where($primaryKey, $data[$primaryKey]);
     }
     $this->entity->getQuery()->select(['`' . $table . '`.*']);
     $record = $this->entity->one();
     if ($record) {
         return $this->update($table, $data);
     }
     return (new InsertRecord($this->record, $this->entity, $this->repository))->setTables($table)->execute();
 }