$this->sites = null;
}
+ /**
+ * Clears the list of sites stored in the database.
+ *
+ * @see SiteStore::clear()
+ *
+ * @return bool success
+ */
+ public function clear() {
+ $dbw = $this->sitesTable->getWriteDbConnection();
+
+ $trx = $dbw->trxLevel();
+
+ if ( $trx == 0 ) {
+ $dbw->begin( __METHOD__ );
+ }
+
+ $ok = $dbw->delete( 'sites', '*', __METHOD__ );
+ $ok = $dbw->delete( 'site_identifiers', '*', __METHOD__ ) && $ok;
+
+ if ( $trx == 0 ) {
+ $dbw->commit( __METHOD__ );
+ }
+
+ $this->reset();
+
+ return $ok;
+ }
+
/**
* @since 1.21
*
*/
public function getSites( $source = 'cache' );
-}
\ No newline at end of file
+ /**
+ * Deletes all sites from the database. After calling clear(), getSites() will return an empty
+ * list and getSite() will return null until saveSite() or saveSites() is called.
+ */
+ public function clear();
+}
}
public function testReset() {
- $store = SiteSQLStore::newInstance();
+ $store1 = SiteSQLStore::newInstance();
+ $store2 = SiteSQLStore::newInstance();
// initialize internal cache
- $this->assertGreaterThan( 0, $store->getSites()->count() );
+ $this->assertGreaterThan( 0, $store1->getSites()->count() );
+ $this->assertGreaterThan( 0, $store2->getSites()->count() );
- // Clear actual data. Will not purge the internal cache in store2.
- $dbw = wfGetDB( DB_MASTER );
- $dbw->delete( 'sites', '*', __METHOD__ );
- $dbw->delete( 'site_identifiers', '*', __METHOD__ );
+ // Clear actual data. Will purge the external cache and reset the internal
+ // cache in $store1, but not the internal cache in store2.
+ $this->assertTrue( $store1->clear() );
// sanity check: $store2 should have a stale cache now
- $this->assertNotNull( $store->getSite( 'enwiki' ) );
+ $this->assertNotNull( $store2->getSite( 'enwiki' ) );
// purge cache
- $store->reset();
+ $store2->reset();
// ...now the internal cache of $store2 should be updated and thus empty.
+ $site = $store2->getSite( 'enwiki' );
+ $this->assertNull( $site );
+ }
+
+ public function testClear() {
+ $store = SiteSQLStore::newInstance();
+ $this->assertTrue( $store->clear() );
+
$site = $store->getSite( 'enwiki' );
$this->assertNull( $site );
+
+ $sites = $store->getSites();
+ $this->assertEquals( 0, $sites->count() );
}
}
* @since 0.1
*/
public static function insertIntoDb() {
- $dbw = wfGetDB( DB_MASTER );
-
- $trx = $dbw->trxLevel();
-
- if ( $trx == 0 ) {
- $dbw->begin( __METHOD__ );
- }
-
- $dbw->delete( 'sites', '*', __METHOD__ );
- $dbw->delete( 'site_identifiers', '*', __METHOD__ );
-
$sitesTable = SiteSQLStore::newInstance();
+ $sitesTable->clear();
$sitesTable->saveSites( TestSites::getSites() );
-
- if ( $trx == 0 ) {
- $dbw->commit( __METHOD__ );
- }
}
}
\ No newline at end of file