Changeset 56e582
- Timestamp:
- 05/09/15 22:15:55 (4 years ago)
- Branches:
- master
- Children:
- f0dadb
- Parents:
- 2b0b08
- git-author:
- pierre-alain <pierre-alain@…> (05/09/15 22:15:55)
- git-committer:
- pierre-alain <pierre-alain@…> (05/09/15 22:15:55)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
OWR/DAO.php
rd8fab2 r56e582 264 264 $checkUnique = $insert = $update = false; 265 265 266 if(isset($this->_fields['uid'])) 267 $this->uid = $this->uid ?: User::iGet()->getUid(); 268 266 269 if($this->_idField) 267 270 { … … 274 277 $wheres[] = $this->_idField; 275 278 if(isset($this->_fields['uid'])) 276 {277 $this->uid = $this->uid ?: User::iGet()->getUid();278 279 empty($wheres) || ($wheres[] = 'uid'); 279 }280 280 } 281 281 else … … 329 329 } 330 330 331 if( $whereFields)331 if(!empty($whereFields) && ($this->_idField || isset($this->_fields['uid']))) 332 332 { 333 333 $chkUniQuery = ' … … 335 335 FROM '.$this->_name.' 336 336 WHERE '; 337 $chkUniQuery .= '('.join('=? OR ', $whereFields).'=?)'; 338 339 if(isset($this->_fields['uid'])) 340 { 341 $this->uid = $this->uid ?: User::iGet()->getUid(); 342 $chkUniQuery .= ' AND uid='.$this->uid; 343 } 344 345 if($this->_idField && isset($this->{$this->_idField}) && $this->{$this->_idField} > 0) 346 $chkUniQuery .= ' AND '.$this->_idField.'!='.self::$_db->quote($this->{$this->_idField}); 347 348 $exists = self::$_db->executeP($chkUniQuery, new DBRequest(Object::toArray($this), $whereFieldsDecl, true)); 349 350 if($exists->next() && $exists->nb > 0) 351 { 352 throw new Exception('Some values are not uniques', 409); 353 } 354 unset($exists); 337 338 if($this->_idField) 339 { 340 $chkUniQuery .= '('.join('=? OR ', $whereFields).'=?)'; 341 342 if(isset($this->{$this->_idField}) && $this->{$this->_idField} > 0) 343 $chkUniQuery .= ' AND '.$this->_idField.'!='.self::$_db->quote($this->{$this->_idField}); 344 345 if(isset($this->_fields['uid'])) 346 $chkUniQuery .= ' AND uid='.$this->uid; 347 } 348 else 349 { 350 // there is no key id field 351 // and $this->_fields['uid'] is set so we assume we are checking for relations between object and user 352 $tmpChkUniQuery = array(); 353 foreach($whereFields as $field) 354 { 355 foreach($this->_relations as $krel => $vrel) 356 { 357 if(isset($vrel[$field])) 358 { 359 unset($whereFieldsDecl[$field]); 360 continue 2; // it's an id relation field 361 } 362 } 363 foreach($this->_userRelations as $krel => $vrel) 364 { 365 if(isset($vrel[$field])) 366 { 367 unset($whereFieldsDecl[$field]); 368 continue 2; // it's an id relation field 369 } 370 } 371 $tmpChkUniQuery[] = '(' . $field . '=? AND uid=' . $this->uid . ')'; 372 } 373 if(empty($tmpChkUniQuery)) $skip = 1; 374 $chkUniQuery .= '(' . join(') OR (', $tmpChkUniQuery) . ')'; 375 } 376 377 if(!isset($skip)) 378 { 379 $exists = self::$_db->executeP($chkUniQuery, new DBRequest(Object::toArray($this), $whereFieldsDecl, true)); 380 381 if($exists->next() && $exists->nb > 0) 382 throw new Exception('Some values are not uniques ' . $chkUniQuery . ' / ' . $query, 409); 383 384 unset($exists); 385 } 355 386 } 356 387 … … 378 409 if($decl['required']) 379 410 { 380 if('uid' === $field) 381 { 382 $this->uid = $this->uid ?: User::iGet()->getUid(); 383 } 384 else 385 { 386 if(!isset($this->$field)) 387 throw new Exception(sprintf(Utilities::iGet()->_('Missing value for required parameter "%s"'), $field), Exception::E_OWR_BAD_REQUEST); 388 389 switch($decl['type']) 390 { 391 case DBRequest::PARAM_PASSWD: 392 if(!empty($this->{$this->_idField})) 393 break; 394 395 case DBRequest::PARAM_RIGHTS: 396 case DBRequest::PARAM_LOGIN: 397 case DBRequest::PARAM_LANG: 398 case DBRequest::PARAM_EMAIL: 399 case DBRequest::PARAM_URL: 400 case DBRequest::PARAM_TIMEZONE: 401 case DBRequest::PARAM_HASH: 402 case DBRequest::PARAM_IP: 403 case \PDO::PARAM_STR: 404 if(empty($this->$field)) 405 throw new Exception(sprintf(Utilities::iGet()->_('Missing value for required parameter "%s"'), $field), Exception::E_OWR_BAD_REQUEST); 406 407 default: 411 if(!isset($this->$field)) 412 throw new Exception(sprintf(Utilities::iGet()->_('Missing value for required parameter "%s"'), $field), Exception::E_OWR_BAD_REQUEST); 413 414 switch($decl['type']) 415 { 416 case DBRequest::PARAM_PASSWD: 417 if(!empty($this->{$this->_idField})) 408 418 break; 409 } 419 420 case DBRequest::PARAM_RIGHTS: 421 case DBRequest::PARAM_LOGIN: 422 case DBRequest::PARAM_LANG: 423 case DBRequest::PARAM_EMAIL: 424 case DBRequest::PARAM_URL: 425 case DBRequest::PARAM_TIMEZONE: 426 case DBRequest::PARAM_HASH: 427 case DBRequest::PARAM_IP: 428 case \PDO::PARAM_STR: 429 if(empty($this->$field)) 430 throw new Exception(sprintf(Utilities::iGet()->_('Missing value for required parameter "%s"'), $field), Exception::E_OWR_BAD_REQUEST); 431 432 default: 433 break; 410 434 } 411 435 }
Note: See TracChangeset
for help on using the changeset viewer.