6
6
7
7
use Exception ;
8
8
use Office365 \PHP \Client \Runtime \ClientAction ;
9
+ use Office365 \PHP \Client \Runtime \ClientRequestStatus ;
9
10
use Office365 \PHP \Client \Runtime \ClientResult ;
10
11
use Office365 \PHP \Client \Runtime \IEntityType ;
11
12
use Office365 \PHP \Client \Runtime \InvokeMethodQuery ;
17
18
use Office365 \PHP \Client \SharePoint \ChangeLogItemQuery ;
18
19
19
20
21
+
20
22
/**
21
23
* Client Request for OData provider.
22
24
*/
23
25
class ODataRequest extends ClientRequest
24
26
{
25
27
26
-
27
28
public function __construct (ClientRuntimeContext $ context )
28
29
{
29
30
parent ::__construct ($ context );
@@ -35,19 +36,25 @@ public function __construct(ClientRuntimeContext $context)
35
36
*/
36
37
public function executeQuery ()
37
38
{
38
- $ request = $ this ->buildRequest ();
39
- if (is_callable ($ this ->eventsList ["BeforeExecuteQuery " ])) {
40
- call_user_func_array ($ this ->eventsList ["BeforeExecuteQuery " ], array (
41
- $ request ,
42
- $ this ->getCurrentAction ()
43
- ));
39
+ try {
40
+ $ request = $ this ->buildRequest ();
41
+ if (is_callable ($ this ->eventsList ["BeforeExecuteQuery " ])) {
42
+ call_user_func_array ($ this ->eventsList ["BeforeExecuteQuery " ], array (
43
+ $ request ,
44
+ $ this ->getCurrentAction ()
45
+ ));
46
+ }
47
+ $ responseInfo = array ();
48
+ $ response = $ this ->executeQueryDirect ($ request , $ responseInfo );
49
+ if (!empty ($ response )) {
50
+ $ this ->processResponse ($ response );
51
+ }
52
+ $ this ->requestStatus = ClientRequestStatus::CompletedSuccess;
44
53
}
45
- $ responseInfo = array ();
46
- $ response = $ this ->executeQueryDirect ($ request , $ responseInfo );
47
- if (!empty ($ response )) {
48
- $ this ->processResponse ($ response );
54
+ catch (Exception $ e ){
55
+ $ this ->requestStatus = ClientRequestStatus::CompletedException;
56
+ throw $ e ;
49
57
}
50
- array_shift ($ this ->queries );
51
58
}
52
59
53
60
@@ -57,12 +64,11 @@ public function executeQuery()
57
64
*/
58
65
public function processResponse ($ response )
59
66
{
60
-
61
67
if (!array_key_exists ($ this ->getCurrentAction ()->getId (), $ this ->resultObjects )) {
62
68
return ;
63
69
}
64
-
65
70
$ resultObject = $ this ->resultObjects [$ this ->getCurrentAction ()->getId ()];
71
+
66
72
if ($ this ->getCurrentAction () instanceof InvokePostMethodQuery && $ this ->getCurrentAction ()->MethodBody instanceof ChangeLogItemQuery) {
67
73
$ payload = $ this ->parseXmlResponse ($ response );
68
74
} else {
@@ -78,7 +84,6 @@ public function processResponse($response)
78
84
$ this ->getSerializationContext ()->map ($ payload ,$ resultObject );
79
85
$ this ->getCurrentAction ()->getResourcePath ()->ServerObjectIsNull = false ;
80
86
}
81
- unset($ this ->resultObjects [$ this ->getCurrentAction ()->getId ()]);
82
87
}
83
88
84
89
@@ -191,7 +196,19 @@ protected function getSerializationContext()
191
196
* @return ClientAction|InvokePostMethodQuery
192
197
*/
193
198
protected function getCurrentAction (){
194
- return current ($ this ->getActions () );
199
+ return current ($ this ->queries );
195
200
}
196
201
202
+
203
+ public function getNextRequest ()
204
+ {
205
+ $ request = new ODataRequest ($ this ->context );
206
+ if (count ($ this ->queries ) > 1 ) {
207
+ $ request ->queries = array_slice ($ this ->queries , 1 , count ($ this ->queries )-1 , true );
208
+ $ request ->resultObjects = $ this ->resultObjects ;
209
+ }
210
+ return $ request ;
211
+ }
212
+
213
+
197
214
}
0 commit comments