diff --git a/public_html/quickstatements.js b/public_html/quickstatements.js --- a/public_html/quickstatements.js +++ b/public_html/quickstatements.js @@ -398,7 +398,7 @@ last_item : me.run_state.last_item } , function ( d ) { me.data.commands[cmdnum] = d.command ; - if ( typeof d.command.item != 'undefined' ) me.run_state.last_item = d.command.item ; + if ( typeof d.last_item != 'undefined' ) me.run_state.last_item = d.last_item ; me.run_state.commands.pending-- ; if ( d.status == 'OK' ) { me.run_state.commands.done++ ; diff --git a/public_html/quickstatements.php b/public_html/quickstatements.php --- a/public_html/quickstatements.php +++ b/public_html/quickstatements.php @@ -255,9 +255,6 @@ else $cmd->summary .= '; ' . $summary ; $this->use_oauth = false ; $this->runSingleCommand ( $cmd ) ; - if ( isset($cmd->new_item) ) { - $this->last_item = $cmd->new_item ; - } // Update batch status $db = $this->getDB() ; @@ -451,7 +448,11 @@ 'data' => $data , 'summary' => '' ) , $command ) ; - if ( $command->status != 'done' ) return $command ; + if ( $command->status != 'done' ) { + $this->last_item = '' ; // Ensure subsequent commands will fail + return $command ; + } + $this->last_item = $command->item ; if ( !$this->isBatchRun() ) $this->wd->updateItem ( $command->item ) ; return $command ; } @@ -684,9 +685,8 @@ $command->run = $params ; // DEBUGGING INFO if ( $status ) { $command->status = 'done' ; - $new = 'new' ; - if ( $params->action == 'wbeditentity' and isset($params->$new) ) { - $command->new_item = $command->item = $result->entity->id ; // "Last item" + if ( $params->action == 'wbeditentity' and isset($params->new) ) { + $command->item = $result->entity->id ; // "Last item" } } else { $command->status = 'error' ; @@ -741,14 +741,6 @@ // Paranoia if ( isset($statement_id) ) return $this->commandDone ( $command , "Statement already exists as $statement_id" ) ; - // Set statement value to last item ID - if ( $command->datavalue->type === 'wikibase-entityid' && $command->datavalue->value->id === 'LAST') { - if (!$this->last_item) { - return $this->commandError( $command, "No last item available" ); - } - $command->datavalue->value->id = $this->last_item; - } - // Execute! $action = array ( 'action' => 'wbcreateclaim' , @@ -932,7 +924,6 @@ foreach ( $commands AS $command_original ) { $command = $this->array2object ( $command_original ) ; $command = $this->runSingleCommand ( $command ) ; - if ( isset($command->item) ) $this->last_item = $command->item ; if ( $command->status != 'done' ) { print "
" ; print_r ( $command ) ; print "" ; } @@ -978,6 +969,10 @@ if ( $command->what == 'description' ) return $this->commandSetDescription ( $command , $i ) ; if ( $command->what == 'sitelink' ) return $this->commandSetSitelink ( $command , $i ) ; + if ( ! $this->propagateLastItem ( $command ) ) { + return $this->commandError( $command, "No last item available" ); + } + $statement_id = $this->getStatementID ( $command ) ; if ( $command->what == 'statement' ) return $this->commandAddStatement ( $command , $i , $statement_id ) ; @@ -999,9 +994,31 @@ } } - $command->status = 'error' ; - $command->message = 'Incomplete or unknown command' ; - return $command ; + return $this->commandError( $command, "Incomplete or unknown command" ); + } + + + protected function propagateLastItem ( $command ) { + $values = [ $command->datavalue ]; + if ( isset($command->qualifier->value) ) { + $values[] = $command->qualifier->value ; + } + if ( isset($command->sources) ) { + foreach ( $command->sources as $source ) { + $values[] = $source->value; + } + } + + foreach ( $values as $value ) { + if ( isset ( $value->type ) && $value->type === 'wikibase-entityid' && strtoupper( $value->value->id ) === 'LAST') { + if ( !$this->last_item ) { + return false ; + } + $value->value->id = $this->last_item ; + } + } + + return true ; } diff --git a/public_html/vue_components/batch.html b/public_html/vue_components/batch.html --- a/public_html/vue_components/batch.html +++ b/public_html/vue_components/batch.html @@ -343,7 +343,7 @@ d.command.summary = original_summary ; // To remove the temporary_batch Vue.set( me.meta.batch.data.commands, cmdnum, d.command ) ; // console.log(JSON.parse(JSON.stringify(d))); - if ( typeof d.command.item != 'undefined' ) me.run.last_item = d.command.item ; + if ( typeof d.last_item != 'undefined' ) me.run.last_item = d.last_item ; me.meta.commands.RUN-- ; if ( d.command.status == 'done' ) { me.meta.batch.data.commands[cmdnum].meta.status = 'DONE' ;