@@ -305,7 +305,7 @@ function post() {
305
305
$ this ->badRequest ();
306
306
}
307
307
} else {
308
- $ this ->badRequest ();
308
+ $ this ->internalServerError ();
309
309
}
310
310
} else {
311
311
$ this ->badRequest ();
@@ -347,7 +347,7 @@ function post() {
347
347
$ this ->badRequest ();
348
348
}
349
349
} else {
350
- $ this ->badRequest ();
350
+ $ this ->internalServerError ();
351
351
}
352
352
} else {
353
353
$ this ->lengthRequired ();
@@ -370,14 +370,29 @@ function put() {
370
370
$ values = join ('", " ' , $ this ->uid ).'", " ' .join ('", " ' , $ pairs );
371
371
$ names = join ('`, ` ' , $ primary ).'`, ` ' .join ('`, ` ' , array_keys ($ pairs ));
372
372
$ resource = $ this ->db ->insertRow ($ this ->table , $ names , $ values );
373
- if ($ resource ) {
374
- if ($ this ->db ->numAffected () > 0 ) {
375
- $ this ->created ();
373
+ if ($ resource && $ this ->db ->numAffected () > 0 ) {
374
+ $ this ->created ();
375
+ } else {
376
+ $ values = '' ;
377
+ foreach ($ pairs as $ column => $ data ) {
378
+ $ values .= '` ' .$ column .'` = " ' .$ this ->db ->escape ($ data ).'", ' ;
379
+ }
380
+ $ values = substr ($ values , 0 , -2 );
381
+ $ where = '' ;
382
+ foreach ($ primary as $ key => $ pri ) {
383
+ $ where .= $ pri .' = ' .$ this ->uid [$ key ].' AND ' ;
384
+ }
385
+ $ where = substr ($ where , 0 , -5 );
386
+ $ resource = $ this ->db ->updateRow ($ this ->table , $ values , $ where );
387
+ if ($ resource ) {
388
+ if ($ this ->db ->numAffected () > 0 ) {
389
+ $ this ->noContent ();
390
+ } else {
391
+ $ this ->badRequest ();
392
+ }
376
393
} else {
377
- $ this ->methodNotAllowed ( ' GET, HEAD, DELETE, POST ' );
394
+ $ this ->internalServerError ( );
378
395
}
379
- } else {
380
- $ this ->methodNotAllowed ('GET, HEAD, DELETE, POST ' );
381
396
}
382
397
} else {
383
398
$ this ->badRequest ();
@@ -539,6 +554,13 @@ function lengthRequired() {
539
554
header ('HTTP/1.0 411 Length Required ' );
540
555
}
541
556
557
+ /**
558
+ * Send a HTTP 500 response header.
559
+ */
560
+ function internalServerError () {
561
+ header ('HTTP/1.0 500 Internal Server Error ' );
562
+ }
563
+
542
564
}
543
565
544
566
?>
0 commit comments