@@ -548,27 +548,30 @@ protected function isProperty ( $p ) {
548548 protected function getStatementID ( $ command ) {
549549 if ( !$ this ->isProperty ( $ command ->property ) ) return ;
550550 if ( !isset ($ command ->datavalue ) ) return ;
551+ if ( isset ($ command ->new_statement ) and $ command ->new_statement ) return ;
551552 $ q = $ command ->item ;
552553
553554 $ this ->wd ->loadItem ( $ q ) ;
554555 if ( !$ this ->wd ->hasItem ($ q ) ) return ;
555556 $ i = $ this ->wd ->getItem ( $ q ) ;
556557 $ claims = $ i ->getClaims ( $ command ->property ) ;
558+ $ last_claim_id = null ;
557559 foreach ( $ claims AS $ c ) {
558560 // when snaktype is somevalue/novalue, $c->mainsnak->datavalue doesn't exist (since the value is unknown or not existing)
559561 if ( $ c ->mainsnak ->snaktype === "somevalue " || $ c ->mainsnak ->snaktype === "novalue " ) {
560562
561563 $ lackingValueType = $ c ->mainsnak ->snaktype ;
562- if ( $ lackingValueType === $ command ->datavalue ->type ) return $ c ->id ;
564+ if ( $ lackingValueType === $ command ->datavalue ->type ) $ last_claim_id = $ c -> id ; // return $c->id ;
563565
564566 } else {
565567
566568 if ( !isset ($ c ->mainsnak ) or !isset ($ c ->mainsnak ->datavalue ) ) continue ;
567569 if ( !isset ($ command ->datavalue ) ) continue ;
568- if ( $ this ->compareDatavalue ( $ c ->mainsnak ->datavalue , $ command ->datavalue ) ) return $ c ->id ;
570+ if ( $ this ->compareDatavalue ( $ c ->mainsnak ->datavalue , $ command ->datavalue ) ) $ last_claim_id = $ c -> id ; // return $c->id ;
569571
570572 }
571573 }
574+ return $ last_claim_id ;
572575 }
573576
574577 // Return true if both datavalues are the same (for any given value of same...), or false otherwise
@@ -632,7 +635,8 @@ public function compressCommands ( $commands ) {
632635 'mainsnak ' => array (
633636 'snaktype ' => 'value ' ,
634637 'property ' => $ commands [$ pos ]['property ' ] ,
635- 'datavalue ' => $ commands [$ pos ]['datavalue ' ]
638+ 'datavalue ' => $ commands [$ pos ]['datavalue ' ],
639+ 'new_statement ' => $ commands [$ pos ]['new_statement ' ]
636640 ) ,
637641 'type ' => 'statement ' ,
638642 'rank ' => 'normal '
@@ -1227,9 +1231,14 @@ protected function importDataFromV1 ( $data , &$ret ) {
12271231 $ cols [0 ] = $ m [1 ] ;
12281232 }
12291233 $ first = strtoupper (trim ($ cols [0 ])) ;
1230- if ( count ( $ cols ) >= 3 and ( $ this ->isValidItemIdentifier ($ first ) or $ first == 'LAST ' ) and $ this ->isValidItemIdentifier ($ cols [1 ]) ) {
1231- $ prop = strtoupper (trim ($ cols [1 ])) ;
1232- $ cmd = array ( 'action ' =>$ action , 'item ' =>$ first , 'property ' =>$ prop , 'what ' =>'statement ' ) ;
1234+ if ( count ( $ cols ) >= 3 and ( $ this ->isValidItemIdentifier ($ first ) or $ first == 'LAST ' ) and ( $ this ->isValidItemIdentifier ($ cols [1 ]) or preg_match ( '/^(!P)(\d+)$/i ' , $ cols [1 ] ) ) ) {
1235+ $ prop = strtoupper (trim ($ cols [1 ])) ;
1236+ $ is_new_statement = 0 ;
1237+ if ( $ prop [0 ] == '! ' ) {
1238+ $ is_new_statement = 1 ;
1239+ $ prop = substr ($ prop , 1 ) ;
1240+ }
1241+ $ cmd = array ( 'action ' =>$ action , 'item ' =>$ first , 'property ' =>$ prop , 'what ' =>'statement ' , 'new_statement ' =>$ is_new_statement ) ;
12331242 if ( $ comment != '' ) $ cmd ['summary ' ] = $ comment ;
12341243 $ this ->parseValueV1 ( $ cols [2 ] , $ cmd ) ;
12351244
0 commit comments