@@ -36,6 +36,10 @@ function warning($msg)
3636
3737foreach ($ feed_json as $ row ) {
3838 $ endpoint = $ row ['type ' ];
39+ if ($ endpoint === 'contest ' ) {
40+ // New feed format uses singular for contest
41+ $ endpoint = 'contests ' ;
42+ }
3943 $ id = isset ($ row ['data ' ]['id ' ]) ? $ row ['data ' ]['id ' ] : '_single_ ' ;
4044 $ feed_data [$ endpoint ][$ id ][] = $ row ;
4145}
@@ -62,30 +66,39 @@ function array_diff_keys($a, $b)
6266 error ("'state' cannot have ID ' $ id' set. " );
6367 }
6468 for ($ i =0 ; $ i <count ($ rows ); $ i ++) {
65- if ($ rows [$ i ]['op ' ]!=='update ' ) {
69+ if (isset ( $ rows [ $ i ][ ' op ' ]) && $ rows [$ i ]['op ' ]!=='update ' ) {
6670 error ("'state' operation ' $ rows [$ i ][op]' not allowed. " );
71+ } elseif (!isset ($ rows [$ i ]['data ' ])) { // isset also checks for null
72+ error ("'state' can not be deleted. " );
6773 }
6874 }
6975 }
7076 } else {
7177 foreach ($ elements as $ id => $ rows ) {
72- if ($ rows [0 ]['op ' ]!=='create ' ) {
78+ if (isset ( $ rows [ 0 ][ ' op ' ]) && $ rows [0 ]['op ' ]!=='create ' ) {
7379 error ("' $ endpoint/ $ id' not created first. " );
7480 }
7581 for ($ i =1 ; $ i <count ($ rows ); $ i ++) {
76- switch ($ rows [$ i ]['op ' ]) {
77- case 'create ' :
78- warning ("' $ endpoint/ $ id' created again. " );
79- break ;
80- case 'update ' :
81- break ;
82- case 'delete ' :
82+ if (isset ($ rows [$ i ]['op ' ])) {
83+ switch ($ rows [$ i ]['op ' ]) {
84+ case 'create ' :
85+ warning ("' $ endpoint/ $ id' created again. " );
86+ break ;
87+ case 'update ' :
88+ break ;
89+ case 'delete ' :
90+ if ($ i <count ($ rows )-1 ) {
91+ error ("' $ endpoint/ $ id' deleted before last change. " );
92+ }
93+ break ;
94+ default :
95+ error ("' $ endpoint/ $ id' unknown operation ' $ rows [$ i ][op]'. " );
96+ }
97+ } elseif (!isset ($ rows [$ i ]['data ' ]) && $ i <count ($ rows )-1 ) {
8398 if ($ i <count ($ rows )-1 ) {
8499 error ("' $ endpoint/ $ id' deleted before last change. " );
85100 }
86101 break ;
87- default :
88- error ("' $ endpoint/ $ id' unknown operation ' $ rows [$ i ][op]'. " );
89102 }
90103 }
91104 }
@@ -111,7 +124,7 @@ function array_diff_keys($a, $b)
111124foreach ($ feed_data as $ endpoint => $ elements ) {
112125 foreach ($ elements as $ id => $ rows ) {
113126 $ last = end ($ rows );
114- if ($ last ['op ' ]!=='delete ' ) {
127+ if (( isset ( $ last ['op ' ]) && $ last [ ' op ' ] !=='delete ' ) || (! isset ( $ last [ ' op ' ]) && isset ( $ last [ ' data ' ])) ) {
115128 if (!isset ($ endpoint_data [$ endpoint ][$ id ])) {
116129 error ("' $ endpoint " .($ id ==='_single_ ' ? '' : "/ $ id " )."' not found in REST endpoint. " );
117130 } elseif ($ last ['data ' ]!==$ endpoint_data [$ endpoint ][$ id ]) {
0 commit comments