Mwjames has uploaded a new change for review.
https://gerrit.wikimedia.org/r/86892
Change subject: StoreUpdater to implement ContextAware
......................................................................
StoreUpdater to implement ContextAware
The context is derived from UpdateObserver together with the object graph
which is now generated from the context rather than assuming a valid
object contract(see line 127).
Definition of the PropertyChangeNotifier class has been moved into the DIC
for proper dependency handling.
Change-Id: I98b95b00f57e123923441c447f7b55e71f55f0a2
---
M includes/StoreUpdater.php
M includes/UpdateObserver.php
M includes/dic/SharedDependencyContainer.php
M tests/phpunit/includes/StoreUpdaterTest.php
M tests/phpunit/includes/dic/SharedDependencyContainerTest.php
5 files changed, 71 insertions(+), 30 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticMediaWiki
refs/changes/92/86892/1
diff --git a/includes/StoreUpdater.php b/includes/StoreUpdater.php
index de2fd49..68ae7a2 100644
--- a/includes/StoreUpdater.php
+++ b/includes/StoreUpdater.php
@@ -14,26 +14,33 @@
* @license GNU GPL v2+
* @author mwjames
*/
-class StoreUpdater {
-
- /** @var Store */
- protected $store;
+class StoreUpdater implements ContextAware {
/** @var SemanticData */
protected $semanticData;
- /** @var Settings */
- protected $settings;
+ /** @var ContextResource */
+ protected $context;
/** @var $updateJobs */
protected $updateJobs = null;
- public function __construct( Store $store, SemanticData $semanticData,
Settings $settings ) {
- $this->store = $store;
+ public function __construct( SemanticData $semanticData,
ContextResource $context ) {
$this->semanticData = $semanticData;
- $this->settings = $settings;
+ $this->context = $context;
- $this->setUpdateStatus( $settings->get( 'smwgEnableUpdateJobs'
) );
+ $this->setUpdateStatus( $this->context->getSettings()->get(
'smwgEnableUpdateJobs' ) );
+ }
+
+ /**
+ * @see ContextAware::withContext
+ *
+ * @since 1.9
+ *
+ * @return ContextResource
+ */
+ public function withContext() {
+ return $this->context;
}
/**
@@ -102,7 +109,10 @@
$user = User::newFromId( $revision->getUser() );
- $propertyAnnotator = new BasePropertyAnnotator(
$this->semanticData, $this->settings );
+ $propertyAnnotator =
$this->withContext()->getDependencyBuilder()->newObject(
'BasePropertyAnnotator', array(
+ 'SemanticData' => $this->semanticData
+ ) );
+
$propertyAnnotator->addSpecialProperties( $wikiPage,
$revision, $user );
} else {
@@ -113,15 +123,19 @@
// Comparison must happen *before* the storage update;
// even finding uses of a property fails after its type changed.
if ( $this->updateJobs ) {
- $changeNotifier = new PropertyChangeNotifier(
$this->store, $this->semanticData, $this->settings );
- $changeNotifier->setObservableDispatcher( new
ObservableSubjectDispatcher( new UpdateObserver() ) )->detectChanges();
+
+ $changeNotifier =
$this->withContext()->getDependencyBuilder()->newObject(
'PropertyChangeNotifier', array(
+ 'SemanticData' => $this->semanticData
+ ) );
+
+ $changeNotifier->detectChanges();
}
// Actually store semantic data, or at least clear it if needed
if ( $processSemantics ) {
- $this->store->updateData( $this->semanticData );
+ $this->withContext()->getStore()->updateData(
$this->semanticData );
} else {
- $this->store->clearData(
$this->semanticData->getSubject() );
+ $this->withContext()->getStore()->clearData(
$this->semanticData->getSubject() );
}
Profiler::Out( __METHOD__, true );
@@ -138,7 +152,7 @@
* @return boolean
*/
protected function isValid( Title $title ) {
- return NamespaceExaminer::newFromArray( $this->settings->get(
'smwgNamespacesWithSemanticLinks' ) )->isSemanticEnabled(
$title->getNamespace() );
+ return $this->withContext()->getDependencyBuilder()->newObject(
'NamespaceExaminer' )->isSemanticEnabled( $title->getNamespace() );
}
}
diff --git a/includes/UpdateObserver.php b/includes/UpdateObserver.php
index c75c510..a0e33fa 100644
--- a/includes/UpdateObserver.php
+++ b/includes/UpdateObserver.php
@@ -78,12 +78,7 @@
*/
public function runStoreUpdater( ParserData $subject ) {
- $updater = new StoreUpdater(
- $this->withContext()->getStore(),
- $subject->getData(),
- $this->withContext()->getSettings()
- );
-
+ $updater = new StoreUpdater( $subject->getData(),
$this->withContext() );
$updater->setUpdateStatus( $subject->getUpdateStatus()
)->doUpdate();
return true;
diff --git a/includes/dic/SharedDependencyContainer.php
b/includes/dic/SharedDependencyContainer.php
index 4003e21..970080c 100644
--- a/includes/dic/SharedDependencyContainer.php
+++ b/includes/dic/SharedDependencyContainer.php
@@ -235,6 +235,26 @@
$instance->setDependencyBuilder( $builder );
return $instance;
+ },
+
+ /**
+ * PropertyChangeNotifier object definition
+ *
+ * @since 1.9
+ *
+ * @return PropertyChangeNotifier
+ */
+ 'PropertyChangeNotifier' => function (
DependencyBuilder $builder ) {
+
+ $instance = new PropertyChangeNotifier(
+ $builder->newObject( 'Store' ),
+ $builder->getArgument( 'SemanticData' ),
+ $builder->newObject( 'Settings' )
+ );
+
+ $instance->setObservableDispatcher(
$builder->newObject( 'ObservableUpdateDispatcher' ) );
+
+ return $instance;
}
);
diff --git a/tests/phpunit/includes/StoreUpdaterTest.php
b/tests/phpunit/includes/StoreUpdaterTest.php
index 8f77ea0..71d6486 100644
--- a/tests/phpunit/includes/StoreUpdaterTest.php
+++ b/tests/phpunit/includes/StoreUpdaterTest.php
@@ -5,7 +5,9 @@
use SMW\StoreFactory;
use SMW\StoreUpdater;
use SMW\SemanticData;
+use SMW\BaseContext;
use SMW\DIWikiPage;
+
use Title;
/**
@@ -41,7 +43,7 @@
*
* @return StoreUpdater
*/
- private function newInstance( $store = null, $data = null, $settings =
null ) {
+ private function newInstance( $store = null, $data = null ) {
if ( $store === null ) {
$store = $this->newMockBuilder()->newObject( 'Store' );
@@ -51,14 +53,18 @@
$data = $this->newMockBuilder()->newObject(
'SemanticData' );
}
- if ( $settings === null ) {
- $settings = $this->getSettings( array(
- 'smwgEnableUpdateJobs' => false,
- 'smwgNamespacesWithSemanticLinks' => array(
NS_MAIN => true )
- ) );
- }
+ $settings = $this->getSettings( array(
+ 'smwgEnableUpdateJobs' => false,
+ 'smwgNamespacesWithSemanticLinks' => array( NS_MAIN =>
true )
+ ) );
- return new StoreUpdater( $store, $data, $settings );
+ $context = new BaseContext();
+
+ $container = $context->getDependencyBuilder()->getContainer();
+ $container->registerObject( 'Store', $store );
+ $container->registerObject( 'Settings', $settings );
+
+ return new StoreUpdater( $data, $context );
}
/**
diff --git a/tests/phpunit/includes/dic/SharedDependencyContainerTest.php
b/tests/phpunit/includes/dic/SharedDependencyContainerTest.php
index 6d177b6..357e22f 100644
--- a/tests/phpunit/includes/dic/SharedDependencyContainerTest.php
+++ b/tests/phpunit/includes/dic/SharedDependencyContainerTest.php
@@ -173,6 +173,12 @@
)
);
+ $provider[] = array( 'PropertyChangeNotifier', array(
'\SMW\PropertyChangeNotifier' => array(
+ 'SemanticData' =>
$this->newMockBuilder()->newObject( 'SemanticData' )
+ )
+ )
+ );
+
$provider[] = array( 'ParserData', array( '\SMW\ParserData' =>
array(
'Title' =>
$this->newMockBuilder()->newObject( 'Title' ),
'ParserOutput' =>
$this->newMockBuilder()->newObject( 'ParserOutput' )
--
To view, visit https://gerrit.wikimedia.org/r/86892
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I98b95b00f57e123923441c447f7b55e71f55f0a2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticMediaWiki
Gerrit-Branch: master
Gerrit-Owner: Mwjames <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits