Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TableChangeOp to record fixed property, refs 2135, 2388 #2483

Merged
merged 1 commit into from May 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 31 additions & 2 deletions maintenance/setupStore.php
Expand Up @@ -4,6 +4,8 @@

use SMW\Store;
use SMW\StoreFactory;
use Onoi\MessageReporter\MessageReporterFactory;
use SMW\SQLStore\Installer;

$basePath = getenv( 'MW_INSTALL_PATH' ) !== false ? getenv( 'MW_INSTALL_PATH' ) : __DIR__ . '/../../..';

Expand Down Expand Up @@ -74,6 +76,7 @@ public function __construct() {
* @since 2.0
*/
public function execute() {

// TODO It would be good if this script would work with SMW not being enable (yet).
// Then one could setup the store without first enabling SMW (which will break the wiki until the store is setup).
if ( !defined( 'SMW_VERSION' ) || !$GLOBALS['smwgSemanticsEnabled'] ) {
Expand All @@ -84,11 +87,28 @@ public function execute() {
$this->loadGlobalFunctions();

$store = $this->getStore();
$store->clear();

if ( $this->getOption( 'quiet' ) ) {
$messageReporter = MessageReporterFactory::getInstance()->newNullMessageReporter();
} else {
$messageReporter = MessageReporterFactory::getInstance()->newObservableMessageReporter();
$messageReporter->registerReporterCallback( array( $this, 'reportMessage' ) );
}

$store->getOptions()->set(
Installer::OPT_MESSAGEREPORTER,
$messageReporter
);

if ( method_exists( $store, 'getPropertyTableInfoFetcher' ) ) {
$store->getPropertyTableInfoFetcher()->clearCache();
}

if ( $this->hasOption( 'delete' ) ) {
$this->dropStore( $store );
} else {
Store::setupStore( !$this->isQuiet() );
$store->setup();
}
}

Expand All @@ -114,7 +134,7 @@ protected function getStore() {
$this->error( "\nError: There is no backend class \"$storeClass\". Aborting.", 1 );
}

return StoreFactory::getStore();
return StoreFactory::getStore( $storeClass );
}

protected function dropStore( Store $store ) {
Expand Down Expand Up @@ -163,6 +183,15 @@ protected function promptDeletionVerification( $storeName ) {
return true;
}

/**
* @since 3.0
*
* @param string $message
*/
public function reportMessage( $message ) {
$this->output( $message );
}

}

$maintClass = 'SMW\Maintenance\SetupStore';
Expand Down
1 change: 1 addition & 0 deletions src/Maintenance/DistinctEntityDataRebuilder.php
Expand Up @@ -155,6 +155,7 @@ public function doRebuild() {
private function doExecuteUpdateJobFor( $page ) {

$updatejob = new UpdateJob( $page, array(
UpdateJob::FORCED_UPDATE => true,
'pm' => $this->options->has( 'shallow-update' ) ? SMW_UJ_PM_CLASTMDATE : false
) );

Expand Down
2 changes: 2 additions & 0 deletions src/SQLStore/ChangeOp/TableChangeOp.php
Expand Up @@ -94,6 +94,8 @@ public function getFieldChangeOps( $opType = null ) {
$changeOps = $this->changeOps[$opType];
}

unset( $changeOps['property'] );

foreach ( $changeOps as $op ) {
$fieldOps[] = new FieldChangeOp( $op );
}
Expand Down
5 changes: 5 additions & 0 deletions src/SQLStore/CompositePropertyTableDiffIterator.php
Expand Up @@ -116,6 +116,11 @@ public function getDataChangeOps() {

foreach ( $this->data as $hash => $data ) {
foreach ( $data as $tableName => $d ) {

if ( isset( $this->fixedPropertyRecords[$tableName] ) ) {
$d['property'] = $this->fixedPropertyRecords[$tableName];
}

$dataChangeOps[] = new TableChangeOp( $tableName, $d );
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/SQLStore/PropertyTableRowDiffer.php
Expand Up @@ -109,6 +109,10 @@ public function computeTableRowDiffFor( $sid, SemanticData $semanticData ) {
}
}

if ( $fixedProperty ) {
$this->getCompositePropertyTableDiff()->addFixedPropertyRecord( $tableName, $fixedProperty );
}

if ( array_key_exists( $tableName, $newData ) ) {
// Note: the order within arrays should remain the same while page is not updated.
// Hence we do not sort before serializing. It is hoped that this assumption is valid.
Expand Down Expand Up @@ -139,10 +143,6 @@ public function computeTableRowDiffFor( $sid, SemanticData $semanticData ) {
$sid,
$propertyTable
);

if ( $fixedProperty ) {
$this->getCompositePropertyTableDiff()->addFixedPropertyRecord( $tableName, $fixedProperty );
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/SQLStore/QueryEngine/Fulltext/TextByChangeUpdater.php
Expand Up @@ -239,6 +239,10 @@ private function doCreateCompositeUpdate( TableChangeOp $dataChangeOp, &$updates

foreach ( $dataChangeOp->getFieldChangeOps() as $fieldChangeOp ) {

if ( $dataChangeOp->isFixedPropertyOp() ) {
$fieldChangeOp->set( 'p_id', $dataChangeOp->getFixedPropertyValueBy( 'p_id' ) );
}

// Exempted property -> out
if ( !$fieldChangeOp->has( 'p_id' ) || $searchTable->isExemptedPropertyById( $fieldChangeOp->get( 'p_id' ) ) ) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/SQLStore/SQLStoreFactory.php
Expand Up @@ -324,7 +324,7 @@ public function newRequestOptionsProcessor() {
*/
public function newPropertyTableInfoFetcher() {

$settings = $this->applicationFactory->getSettings();
$settings = ApplicationFactory::getInstance()->getSettings();

$propertyTableInfoFetcher = new PropertyTableInfoFetcher(
new PropertyTypeFinder( $this->store->getConnection( 'mw.db' ) )
Expand Down
Expand Up @@ -177,6 +177,7 @@ private function prepareTest( $jsonTestCaseFileHandler ) {
'smwgEnabledFulltextSearch',
'smwgFulltextDeferredUpdate',
'smwgFulltextSearchIndexableDataTypes',
'smwgFixedProperties',
'smwgPropertyZeroCountDisplay',
'smwgQueryResultCacheType',
'smwgLinksInValues',
Expand Down Expand Up @@ -206,28 +207,58 @@ private function prepareTest( $jsonTestCaseFileHandler ) {
);
}

$pageList = $jsonTestCaseFileHandler->getPageCreationSetupList();

// Special handling for fixed properties to fetch the correct type
// before being used as annotation
if ( $jsonTestCaseFileHandler->getSettingsFor( 'smwgFixedProperties' ) !== array() ) {
foreach ( $pageList as $page ) {
if ( isset( $page['namespace'] ) && $page['namespace'] === 'SMW_NS_PROPERTY' ) {
$this->doRunFixedPropertyTableCreation( $page );
}
}
}

$this->createPagesFrom(
$jsonTestCaseFileHandler->getPageCreationSetupList(),
$pageList,
NS_MAIN
);
}

private function doRunFixedPropertyTableCreation( $page ) {
// Create property to ...
$this->createPagesFrom( array( $page ) );

// Create table
$maintenanceRunner = $this->runnerFactory->newMaintenanceRunner( 'setupStore' );
$maintenanceRunner->setQuiet();
$maintenanceRunner->run();
}

private function doRunBeforeTest( $jsonTestCaseFileHandler ) {

foreach ( $jsonTestCaseFileHandler->findTaskBeforeTestExecutionByType( 'maintenance-run' ) as $runner => $options ) {

$maintenanceRunner = $this->runnerFactory->newMaintenanceRunner( $runner );
$maintenanceRunner->setQuiet();

$maintenanceRunner->setOptions(
(array)$options
);

$maintenanceRunner->setQuiet()->run();
$maintenanceRunner->run();

if ( isset( $options['quiet'] ) && $options['quiet'] === false ) {
print_r( $maintenanceRunner->getOutput() );
}
}

foreach ( $jsonTestCaseFileHandler->findTaskBeforeTestExecutionByType( 'job-run' ) as $jobType ) {
$jobQueueRunner = $this->runnerFactory->newJobQueueRunner( $jobType );
$jobQueueRunner->run();
}

$this->testEnvironment->executePendingDeferredUpdates();
}

private function doRunParserTests( $jsonTestCaseFileHandler ) {
Expand Down
94 changes: 94 additions & 0 deletions tests/phpunit/Integration/JSONScript/TestCases/q-0106.json
@@ -0,0 +1,94 @@
{
"description": "Test `_txt`/`~` with enabled full-text search support on fixed user property (only enabled for MySQL, SQLite, `smwgFixedProperties`)",
"setup": [
{
"namespace": "SMW_NS_PROPERTY",
"page": "Has fixed text",
"contents": "[[Has type::Text]]"
},
{
"namespace": "SMW_NS_PROPERTY",
"page": "Has fixed page",
"contents": "[[Has type::Page]]"
},
{
"page": "Example/Q0106/1",
"contents": "{{#subobject: |Has fixed text=MySQL vs MariaDB database}} {{#subobject: |Has fixed text=Oracle vs MariaDB database}} {{#subobject: |Has fixed text=PostgreSQL vs MariaDB database and more of}} {{#subobject: |Has fixed text=MariaDB overview}}"
},
{
"page": "Example/Q0106/2",
"contents": "{{#subobject: |Has fixed page=Elastic search}} {{#subobject: |Has fixed page=Sphinx search}}"
}
],
"beforeTest": {
"maintenance-run": {
"rebuildData": {
"page": "Property:Has fixed text|Property:Has fixed page|Example/Q0106/1|Example/Q0106/2"
}
}
},
"tests": [
{
"type": "query",
"store": {
"clear-cache": true
},
"about": "#0 on fixed blob user property",
"condition": "[[Has fixed text::~+MariaDB -database]]",
"printouts": [],
"parameters": {
"limit": "10"
},
"assert-queryresult": {
"count": 1,
"results": [
"Example/Q0106/1#0##_29f6aa337d1dc1e2f79376c7940aeab3"
]
}
},
{
"type": "query",
"store": {
"clear-cache": true
},
"about": "#1 on fixed page user property",
"condition": "[[Has fixed page::~*search*]]",
"printouts": [],
"parameters": {
"limit": "10"
},
"assert-queryresult": {
"count": 2,
"results": [
"Example/Q0106/2#0##_39c07b506d692088c97dc0d1cbfd67e6",
"Example/Q0106/2#0##_89e5e037d244e08b050101bb8ddb7768"
]
}
}
],
"settings": {
"smwgEnabledFulltextSearch": true,
"smwgFulltextDeferredUpdate": false,
"smwgFulltextSearchIndexableDataTypes": [
"SMW_FT_BLOB",
"SMW_FT_URI",
"SMW_FT_WIKIPAGE"
],
"smwgFixedProperties": [
"Has_fixed_text",
"Has fixed page"
]
},
"meta": {
"skip-on": {
"postgres": "Not supported by PostgreSQL.",
"sesame": "Not supported by SPARQLStore (Sesame).",
"virtuoso": "Not supported by SPARQLStore (Virtuoso).",
"fuseki": "Not supported by SPARQLStore (Fuskei).",
"blazegraph": "Not supported by SPARQLStore (Blazegraph)."
},
"version": "2",
"is-incomplete": false,
"debug": false
}
}
Expand Up @@ -68,6 +68,8 @@ protected function setUp() {
'LinksUpdateConstructed',
$this->mwHooksHandler->getHookRegistry()->getHandlerFor( 'LinksUpdateConstructed' )
);

$this->getStore()->setup( false );
}

protected function tearDown() {
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/Unit/SQLStore/ChangeOp/TableChangeOpTest.php
Expand Up @@ -146,7 +146,7 @@ public function testGetFieldChangeOpsNoType() {
);

$this->assertCount(
3,
2,
$instance->getFieldChangeOps()
);
}
Expand Down
9 changes: 7 additions & 2 deletions tests/phpunit/Utils/Runners/MaintenanceRunner.php
Expand Up @@ -55,7 +55,7 @@ public function setOptions( array $options ) {
* @return MaintenanceRunner
*/
public function setQuiet() {
$this->quiet = true;
$this->options['quiet'] = true;
return $this;
}

Expand All @@ -80,9 +80,14 @@ public function run() {
throw new DomainException( "Expected a Maintenance instance" );
}

// isset/ null
if ( isset( $this->options['quiet'] ) && $this->options['quiet'] === false ) {
unset( $this->options['quiet'] );
}

$maintenance->loadParamsAndArgs(
$this->maintenanceClass,
array_merge( $this->options, array( 'quiet' => $this->quiet ) )
$this->options
);

ob_start();
Expand Down
3 changes: 3 additions & 0 deletions tests/phpunit/Utils/Runners/RunnerFactory.php
Expand Up @@ -48,6 +48,9 @@ public function newMaintenanceRunner( $maintenanceClass ) {
case 'rebuildConceptCache';
$maintenanceClass = 'SMW\Maintenance\RebuildConceptCache';
break;
case 'setupStore';
$maintenanceClass = 'SMW\Maintenance\SetupStore';
break;
}

return new MaintenanceRunner( $maintenanceClass );
Expand Down