diff --git a/.gitmodules b/.gitmodules index 6dc6368..11adbc9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,21 +1,24 @@ [submodule "includes/boz-mw"] path = includes/boz-mw url = https://github.com/valerio-bozzolan/boz-mw.git [submodule "2018-06-wikidata-volleyball-players/includes/boz-mw"] path = 2018-06-wikidata-volleyball-players/includes/boz-mw url = https://github.com/valerio-bozzolan/boz-mw [submodule "2018-06-wikidata-soccer-serie-a/includes/boz-mw"] path = 2018-06-wikidata-soccer-serie-a/includes/boz-mw url = https://github.com/valerio-bozzolan/boz-mw.git [submodule "2018-02-italian-parks/includes/boz-mw"] path = 2018-02-italian-parks/includes/boz-mw url = https://github.com/valerio-bozzolan/boz-mw.git [submodule "2018-07-wikipedia-citation-language-migration/includes/boz-mw"] path = 2018-07-wikipedia-citation-language-migration/includes/boz-mw url = https://github.com/valerio-bozzolan/boz-mw [submodule "2017-11-wikidata-volleyball-players/includes/boz-mw"] path = 2017-11-wikidata-volleyball-players/includes/boz-mw url = https://github.com/valerio-bozzolan/boz-mw [submodule "2018-08-wiki-loves-monuments-switzerland/boz-mw"] path = 2018-08-wiki-loves-monuments-switzerland/includes/boz-mw url = git@github.com:valerio-bozzolan/boz-mw.git +[submodule "2018-09-mibact-fixer/boz-mw"] + path = 2018-09-mibact-fixer/boz-mw + url = https://github.com/valerio-bozzolan/boz-mw.git diff --git a/2018-09-mibact-fixer/bot.php b/2018-09-mibact-fixer/bot.php new file mode 100755 index 0000000..45ee677 --- /dev/null +++ b/2018-09-mibact-fixer/bot.php @@ -0,0 +1,54 @@ +#!/usr/bin/php +login(); + +foreach( wm\Wikidata::querySPARQL( file_get_contents( 'query.sparql' ) ) as $result ) { + + $code = $result->catv->value; + $item_id = $result->id ->value; + $item_id = str_replace( 'http://www.wikidata.org/entity/', '', $item_id ); + $code = str_replace( 'DBUnico.', '', $code ); + + // pull existing data + $item = wm\Wikidata::getInstance() + ->fetchSingleEntity( $item_id, [ 'props' => 'claims' ] ); + + // data to be pushed + $data = $item->cloneEmpty(); + + // push the MiBACT ID if not exists + if( ! $item->hasClaimsInProperty( MIBACT_ID ) ) { + $data->addClaim( new wb\StatementExternalID( MIBACT_ID, $code ) ); + } + + // push for removal of any catalog code and described at URL claims + foreach( [ CATALOG_CODE, DESCRIBED_AT_URL ] as $property ) { + foreach( $item->getClaimsInProperty( $property ) as $claim ) { + $data->addClaim( $claim->cloneForRemoval() ); + } + } + if( $data->countClaims() ) { + $data->printChanges(); + if( 'y' === cli\Input::yesNoQuestion( 'save?' ) ) { + $data->editEntity( [ + 'bot' => 1, + 'summary.pre' => 'Bot: [[Wikidata:Property proposal/DBUnico ID|migrate to new DBUnico ID]]: ' + ] ); + } + } +} diff --git a/2018-09-mibact-fixer/boz-mw b/2018-09-mibact-fixer/boz-mw new file mode 160000 index 0000000..b06bd87 --- /dev/null +++ b/2018-09-mibact-fixer/boz-mw @@ -0,0 +1 @@ +Subproject commit b06bd87b776ca242e1ff568f38ad64f56cd3c268 diff --git a/2018-09-mibact-fixer/query.sparql b/2018-09-mibact-fixer/query.sparql new file mode 100644 index 0000000..c2be1aa --- /dev/null +++ b/2018-09-mibact-fixer/query.sparql @@ -0,0 +1,7 @@ +SELECT ?id ?catv ?url WHERE { + ?id p:P528 ?cat. + ?cat ps:P528 ?catv. + ?cat pq:P972 wd:Q52896862. + ?cat pq:P2699 ?url. + FILTER CONTAINS( STR( ?url ), "mibact/luoghi" ) +}