[MediaWiki-commits] [Gerrit] Ensure populate sites works for updating existing sites - change (mediawiki...Wikibase)

2013-09-20 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Ensure populate sites works for updating existing sites
..


Ensure populate sites works for updating existing sites

also:

* add 'en' as language code for special sites,
parts of wikibase depend on there being a language
for all sites.
* improve site matrix parser test

Change-Id: I2f50f40d0a796f03ef78c524bca63018595207e5
---
M lib/includes/sites/SiteMatrixParser.php
M lib/includes/sites/SitesBuilder.php
M lib/maintenance/populateSitesTable.php
M lib/tests/phpunit/sites/SiteMatrixParserTest.php
M lib/tests/phpunit/sites/SitesBuilderTest.php
5 files changed, 86 insertions(+), 59 deletions(-)

Approvals:
  Daniel Kinzler: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/includes/sites/SiteMatrixParser.php 
b/lib/includes/sites/SiteMatrixParser.php
index df3020b..ffdc559 100644
--- a/lib/includes/sites/SiteMatrixParser.php
+++ b/lib/includes/sites/SiteMatrixParser.php
@@ -94,8 +94,12 @@
 
foreach( $specialSites as $specialSite ) {
$site = $this-getSiteFromSiteData( $specialSite );
-   $siteId= $site-getGlobalId();
-   $sites[$siteId] = $this-getSiteFromSiteData( 
$specialSite );
+   $siteId = $site-getGlobalId();
+
+   // todo: get this from $wgConf
+   $site-setLanguageCode( 'en' );
+
+   $sites[$siteId] = $site;
}
 
return $sites;
@@ -138,13 +142,13 @@
 
// @note: expandGroup is specific to wikimedia site matrix 
sources
$siteGroup = ( $this-expandGroup  $siteData['code'] === 
'wiki' )
-? 'wikipedia' : $siteData['code'];
+   ? 'wikipedia' : $siteData['code'];
 
$site-setGroup( $siteGroup );
 
$url = $siteData['url'];
 
-   if ( $this-stripProtocol === 'stripProtocol' ) {
+   if ( $this-stripProtocol ) {
$url = preg_replace( '@^https?:@', '', $url );
}
 
diff --git a/lib/includes/sites/SitesBuilder.php 
b/lib/includes/sites/SitesBuilder.php
index 4857e50..50e0455 100644
--- a/lib/includes/sites/SitesBuilder.php
+++ b/lib/includes/sites/SitesBuilder.php
@@ -29,7 +29,17 @@
public function buildStore( array $sites, $siteGroup, $wikiId ) {
$sites = $this-addInterwikiIdsToGroup( $sites, $siteGroup, 
$wikiId );
 
-   $this-store-getSites( nocache );
+   $existingSites = $this-store-getSites( nocache );
+
+   foreach( $sites as $site ) {
+   $siteId = $site-getGlobalId();
+
+   if ( $existingSites-hasSite( $siteId ) ) {
+   $existingSite = $existingSites-getSite( 
$siteId );
+   $site-setInternalId( 
$existingSite-getInternalId() );
+   }
+   }
+
$this-store-saveSites( $sites );
}
 
diff --git a/lib/maintenance/populateSitesTable.php 
b/lib/maintenance/populateSitesTable.php
index 080bb82..cb48a36 100644
--- a/lib/maintenance/populateSitesTable.php
+++ b/lib/maintenance/populateSitesTable.php
@@ -37,7 +37,7 @@
}
 
public function execute() {
-   $stripProtocols = $this-getOption( 'strip-protocols' ) ? 
stripProtocol : false;
+   $stripProtocols = $this-getOption( 'strip-protocols', false );
$url = $this-getOption( 'load-from', 
'https://meta.wikimedia.org/w/api.php' );
$scriptPath = $this-getOption( 'script-path', '/w/$1' );
$articlePath = $this-getOption( 'article-path', '/wiki/$1' );
@@ -78,7 +78,7 @@
$json = Http::get( $url, 'default', array( 'raiseException' = 
true ) );
 
if ( !$json ) {
-   throw new MWException( Got no data from $url );
+   throw new MWException( Got no data from $url\n );
}
 
return $json;
diff --git a/lib/tests/phpunit/sites/SiteMatrixParserTest.php 
b/lib/tests/phpunit/sites/SiteMatrixParserTest.php
index 3483efa..a1ef2bb 100644
--- a/lib/tests/phpunit/sites/SiteMatrixParserTest.php
+++ b/lib/tests/phpunit/sites/SiteMatrixParserTest.php
@@ -3,7 +3,7 @@
 /**
  * @covers SiteMatrixParser
  *
- * @since 0.1
+ * @since 0.5
  *
  * @group Wikibase
  *
@@ -15,20 +15,31 @@
/**
 * @dataProvider sitesFromJsonProvider
 */
-   public function testSitesFromJson( $json, $expected ) {
-   $siteMatrixParser = new SiteMatrixParser( '/w/$1', '/wiki/$1', 
false );
+   public function testSitesFromJson( $scriptPath, $articlePath, $expected 
) {
+   $json = $this-getSiteMatrixJson();
+
+   $siteMatrixParser = new SiteMatrixParser( 

[MediaWiki-commits] [Gerrit] Ensure populate sites works for updating existing sites - change (mediawiki...Wikibase)

2013-09-20 Thread Aude (Code Review)
Aude has submitted this change and it was merged.

Change subject: Ensure populate sites works for updating existing sites
..


Ensure populate sites works for updating existing sites

also:

* add 'en' as language code for special sites,
parts of wikibase depend on there being a language
for all sites.
* improve site matrix parser test

Change-Id: I2f50f40d0a796f03ef78c524bca63018595207e5
(cherry picked from commit e731705a7489a227c43c97282ca51afd2526862e)
---
M lib/includes/sites/SiteMatrixParser.php
M lib/includes/sites/SitesBuilder.php
M lib/maintenance/populateSitesTable.php
M lib/tests/phpunit/sites/SiteMatrixParserTest.php
M lib/tests/phpunit/sites/SitesBuilderTest.php
5 files changed, 86 insertions(+), 59 deletions(-)

Approvals:
  Aude: Verified; Looks good to me, approved



diff --git a/lib/includes/sites/SiteMatrixParser.php 
b/lib/includes/sites/SiteMatrixParser.php
index df3020b..ffdc559 100644
--- a/lib/includes/sites/SiteMatrixParser.php
+++ b/lib/includes/sites/SiteMatrixParser.php
@@ -94,8 +94,12 @@
 
foreach( $specialSites as $specialSite ) {
$site = $this-getSiteFromSiteData( $specialSite );
-   $siteId= $site-getGlobalId();
-   $sites[$siteId] = $this-getSiteFromSiteData( 
$specialSite );
+   $siteId = $site-getGlobalId();
+
+   // todo: get this from $wgConf
+   $site-setLanguageCode( 'en' );
+
+   $sites[$siteId] = $site;
}
 
return $sites;
@@ -138,13 +142,13 @@
 
// @note: expandGroup is specific to wikimedia site matrix 
sources
$siteGroup = ( $this-expandGroup  $siteData['code'] === 
'wiki' )
-? 'wikipedia' : $siteData['code'];
+   ? 'wikipedia' : $siteData['code'];
 
$site-setGroup( $siteGroup );
 
$url = $siteData['url'];
 
-   if ( $this-stripProtocol === 'stripProtocol' ) {
+   if ( $this-stripProtocol ) {
$url = preg_replace( '@^https?:@', '', $url );
}
 
diff --git a/lib/includes/sites/SitesBuilder.php 
b/lib/includes/sites/SitesBuilder.php
index 4857e50..50e0455 100644
--- a/lib/includes/sites/SitesBuilder.php
+++ b/lib/includes/sites/SitesBuilder.php
@@ -29,7 +29,17 @@
public function buildStore( array $sites, $siteGroup, $wikiId ) {
$sites = $this-addInterwikiIdsToGroup( $sites, $siteGroup, 
$wikiId );
 
-   $this-store-getSites( nocache );
+   $existingSites = $this-store-getSites( nocache );
+
+   foreach( $sites as $site ) {
+   $siteId = $site-getGlobalId();
+
+   if ( $existingSites-hasSite( $siteId ) ) {
+   $existingSite = $existingSites-getSite( 
$siteId );
+   $site-setInternalId( 
$existingSite-getInternalId() );
+   }
+   }
+
$this-store-saveSites( $sites );
}
 
diff --git a/lib/maintenance/populateSitesTable.php 
b/lib/maintenance/populateSitesTable.php
index 080bb82..cb48a36 100644
--- a/lib/maintenance/populateSitesTable.php
+++ b/lib/maintenance/populateSitesTable.php
@@ -37,7 +37,7 @@
}
 
public function execute() {
-   $stripProtocols = $this-getOption( 'strip-protocols' ) ? 
stripProtocol : false;
+   $stripProtocols = $this-getOption( 'strip-protocols', false );
$url = $this-getOption( 'load-from', 
'https://meta.wikimedia.org/w/api.php' );
$scriptPath = $this-getOption( 'script-path', '/w/$1' );
$articlePath = $this-getOption( 'article-path', '/wiki/$1' );
@@ -78,7 +78,7 @@
$json = Http::get( $url, 'default', array( 'raiseException' = 
true ) );
 
if ( !$json ) {
-   throw new MWException( Got no data from $url );
+   throw new MWException( Got no data from $url\n );
}
 
return $json;
diff --git a/lib/tests/phpunit/sites/SiteMatrixParserTest.php 
b/lib/tests/phpunit/sites/SiteMatrixParserTest.php
index 3483efa..a1ef2bb 100644
--- a/lib/tests/phpunit/sites/SiteMatrixParserTest.php
+++ b/lib/tests/phpunit/sites/SiteMatrixParserTest.php
@@ -3,7 +3,7 @@
 /**
  * @covers SiteMatrixParser
  *
- * @since 0.1
+ * @since 0.5
  *
  * @group Wikibase
  *
@@ -15,20 +15,31 @@
/**
 * @dataProvider sitesFromJsonProvider
 */
-   public function testSitesFromJson( $json, $expected ) {
-   $siteMatrixParser = new SiteMatrixParser( '/w/$1', '/wiki/$1', 
false );
+   public function testSitesFromJson( $scriptPath, $articlePath, $expected 
) {
+   $json = $this-getSiteMatrixJson();
+
+   

[MediaWiki-commits] [Gerrit] Ensure populate sites works for updating existing sites - change (mediawiki...Wikibase)

2013-09-18 Thread Aude (Code Review)
Aude has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/84857


Change subject: Ensure populate sites works for updating existing sites
..

Ensure populate sites works for updating existing sites

plus improve site matrix parser test

Change-Id: I2f50f40d0a796f03ef78c524bca63018595207e5
---
M lib/includes/sites/SiteMatrixParser.php
M lib/includes/sites/SitesBuilder.php
M lib/maintenance/populateSitesTable.php
M lib/tests/phpunit/sites/SiteMatrixParserTest.php
4 files changed, 79 insertions(+), 53 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/57/84857/1

diff --git a/lib/includes/sites/SiteMatrixParser.php 
b/lib/includes/sites/SiteMatrixParser.php
index df3020b..9c32f19 100644
--- a/lib/includes/sites/SiteMatrixParser.php
+++ b/lib/includes/sites/SiteMatrixParser.php
@@ -94,8 +94,8 @@
 
foreach( $specialSites as $specialSite ) {
$site = $this-getSiteFromSiteData( $specialSite );
-   $siteId= $site-getGlobalId();
-   $sites[$siteId] = $this-getSiteFromSiteData( 
$specialSite );
+   $siteId = $site-getGlobalId();
+   $sites[$siteId] = $site;
}
 
return $sites;
@@ -144,7 +144,7 @@
 
$url = $siteData['url'];
 
-   if ( $this-stripProtocol === 'stripProtocol' ) {
+   if ( $this-stripProtocol ) {
$url = preg_replace( '@^https?:@', '', $url );
}
 
diff --git a/lib/includes/sites/SitesBuilder.php 
b/lib/includes/sites/SitesBuilder.php
index 4857e50..f1d245b 100644
--- a/lib/includes/sites/SitesBuilder.php
+++ b/lib/includes/sites/SitesBuilder.php
@@ -30,6 +30,17 @@
$sites = $this-addInterwikiIdsToGroup( $sites, $siteGroup, 
$wikiId );
 
$this-store-getSites( nocache );
+
+   foreach( $sites as $site ) {
+   $siteId = $site-getGlobalId();
+   $existingSites = $this-store-getSites( false );
+
+   if ( $existingSites-hasSite( $siteId ) ) {
+   $existingSite = $existingSites-getSite( 
$siteId );
+   $site-setInternalId( 
$existingSite-getInternalId() );
+   }
+   }
+
$this-store-saveSites( $sites );
}
 
diff --git a/lib/maintenance/populateSitesTable.php 
b/lib/maintenance/populateSitesTable.php
index 080bb82..7d8 100644
--- a/lib/maintenance/populateSitesTable.php
+++ b/lib/maintenance/populateSitesTable.php
@@ -37,7 +37,7 @@
}
 
public function execute() {
-   $stripProtocols = $this-getOption( 'strip-protocols' ) ? 
stripProtocol : false;
+   $stripProtocols = $this-getOption( 'strip-protocols' ) ? true 
: false;
$url = $this-getOption( 'load-from', 
'https://meta.wikimedia.org/w/api.php' );
$scriptPath = $this-getOption( 'script-path', '/w/$1' );
$articlePath = $this-getOption( 'article-path', '/wiki/$1' );
diff --git a/lib/tests/phpunit/sites/SiteMatrixParserTest.php 
b/lib/tests/phpunit/sites/SiteMatrixParserTest.php
index 3483efa..227edff 100644
--- a/lib/tests/phpunit/sites/SiteMatrixParserTest.php
+++ b/lib/tests/phpunit/sites/SiteMatrixParserTest.php
@@ -15,20 +15,31 @@
/**
 * @dataProvider sitesFromJsonProvider
 */
-   public function testSitesFromJson( $json, $expected ) {
-   $siteMatrixParser = new SiteMatrixParser( '/w/$1', '/wiki/$1', 
false );
+   public function testSitesFromJson( $scriptPath, $articlePath, $expected 
) {
+   $json = $this-getSiteMatrixJson();
+
+   $siteMatrixParser = new SiteMatrixParser( $scriptPath, 
$articlePath, true );
+
$sites = $siteMatrixParser-sitesFromJson( $json );
-   $this-assertEquals( ksort( $expected ), ksort( $sites ) );
+
+   ksort( $expected );
+   ksort( $sites );
+
+   $this-assertEquals( $expected, $sites );
}
 
public function sitesFromJsonProvider() {
-   $json = $this-getSiteMatrixJson();
-   $sitesData = $this-getSitesData();
-   $sites = $this-getSites( $sitesData );
+   $siteData = $this-getSiteData();
 
-   return array(
-   array( $json, $sites )
+   $data = array();
+
+   $data[] = array(
+   '/w/$1',
+   '/wiki/$1',
+   $this-getSites( $siteData, '/w/$1', '/wiki/$1' )
);
+
+   return $data;
}
 
protected function getSiteMatrixJson() {
@@ -108,81 +119,85 @@
return json_encode( $data );
}
 
-