54 ApiBase $module, array $allModules = [], array $generatedModules = []
56 $this->source = get_class( $module );
59 $this->generatedModules = $generatedModules
60 ? array_combine( $generatedModules, $generatedModules )
64 $continue = $request->getVal(
'continue',
'' );
65 if ( $continue !==
'' ) {
66 $continue = explode(
'||', $continue );
67 if ( count( $continue ) !== 2 ) {
68 throw ApiUsageException::newWithMessage( $module->
getMain(),
'apierror-badcontinue' );
70 $this->generatorDone = ( $continue[0] ===
'-' );
71 $skip = explode(
'|', $continue[1] );
72 if ( !$this->generatorDone ) {
73 $params = explode(
'|', $continue[0] );
74 $this->generatorParams = array_intersect_key(
75 $request->getValues(),
76 array_fill_keys( $params,
true )
81 $skip += $this->generatedModules;
85 foreach ( $allModules as $module ) {
87 if ( in_array( $name, $skip,
true ) ) {
88 $this->allModules[$name] =
false;
92 $this->allModules[$name] = $module;
129 if ( !isset( $this->allModules[$name] ) ) {
130 throw new UnexpectedValueException(
131 "Module '$name' called " . __METHOD__ .
132 ' but was not passed to ' . __CLASS__ .
'::__construct'
135 if ( !$this->allModules[$name] ) {
136 throw new UnexpectedValueException(
137 "Module '$name' was not supposed to have been executed, but " .
138 'it was executed anyway'
142 if ( is_array( $paramValue ) ) {
143 $paramValue = implode(
'|', $paramValue );
145 $this->continuationData[$name][$paramName] = $paramValue;
206 $batchcomplete =
false;
208 $finishedModules = array_diff(
209 array_keys( $this->allModules ),
210 array_keys( $this->continuationData )
214 $continuationData = array_diff_key( $this->continuationData, $this->generatedModules );
215 foreach ( $continuationData as $kvp ) {
220 $continuationData = array_intersect_key( $this->continuationData, $this->generatedModules );
221 if ( $continuationData ) {
224 foreach ( $continuationData as $kvp ) {
227 $generatorParams = [];
228 foreach ( $this->generatorNonContinuationData as $kvp ) {
229 $generatorParams += $kvp;
231 $generatorParams += $this->generatorParams;
233 $data += $generatorParams;
234 $generatorKeys = implode(
'|', array_keys( $generatorParams ) );
235 } elseif ( $this->generatorContinuationData ) {
239 $generatorParams = [];
240 foreach ( $this->generatorContinuationData as $kvp ) {
241 $generatorParams += $kvp;
243 $data += $generatorParams;
244 $finishedModules = array_diff( $finishedModules, $this->generatedModules );
245 $generatorKeys = implode(
'|', array_keys( $generatorParams ) );
246 $batchcomplete =
true;
249 $generatorKeys =
'-';
250 $batchcomplete =
true;
255 if ( $data || $generatorKeys !==
'-' ) {
256 $data[
'continue'] = $generatorKeys .
'||' . implode(
'|', $finishedModules );
259 return [ $data, $batchcomplete ];