Skip to content

Commit

Permalink
Add ERROR_DB_REQUIREMENT_INCOMPATIBLE, refs 4438 (#4439)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwjames committed Jan 25, 2020
1 parent 343b0d9 commit 178dc77
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 4 deletions.
1 change: 1 addition & 0 deletions data/template/setupcheck/setupcheck.db.requirement.ms
@@ -0,0 +1 @@
<!--{{template}}--><h4>{{version-title}}</h4><p><div style="margin-left:10px;display: flex; width: 90%;"><div style="flex-basis:30%;">{{db-title}}:</div><div>{{db-type}}</div></div><!-- ROW --><div style="margin-top:10px;margin-left:10px;display: flex; width: 90%;"><div style="flex-basis:30%;">{{db-minimum-title}}:</div><div>{{db-minimum-version}}</div></div><!-- ROW --><div style="margin-left:10px;display: flex; width: 90%;"><div style="flex-basis:30%;">{{db-current-title}}:</div><div>{{db-current-version}}</div></div></p>
30 changes: 30 additions & 0 deletions data/template/setupcheck/setupcheck.json
Expand Up @@ -34,6 +34,36 @@
}
]
},
"ERROR_DB_REQUIREMENT_INCOMPATIBLE":{
"indicator_title":"smw-setupcheck-error",
"indicator_color":"#dd3d31",
"output_form":[
{
"type":"paragraph",
"text":"smw-setupcheck-requires-db-minimum-version"
},
{
"type":"db-requirement",
"text":"smw-setupcheck-db-requirement"
},
{
"type":"version",
"text":"smw-setupcheck-release"
},
{
"type":"section",
"text":"smw-setupcheck-how-to-fix-error"
},
{
"type":"paragraph",
"text":"smw-setupcheck-requires-software-update"
},
{
"type":"paragraph",
"text":"smw-setupcheck-temporarily-disable"
}
]
},
"ERROR_EXTENSION_INCOMPATIBLE":{
"indicator_title":"smw-setupcheck-dependency-error",
"indicator_color":"#dd3d31",
Expand Down
20 changes: 19 additions & 1 deletion i18n/local/setupcheck.i18n.json
Expand Up @@ -21,6 +21,18 @@
"smw-setupcheck-progress":{
"en": "Progress"
},
"smw-setupcheck-db-requirement":{
"en": "Requirement"
},
"smw-setupcheck-db-title":{
"en": "Database type"
},
"smw-setupcheck-db-current-title":{
"en": "Current version"
},
"smw-setupcheck-db-minimum-title":{
"en": "Minimum version"
},
"smw-setupcheck-stack-trace":{
"en": "Stack trace"
},
Expand All @@ -30,6 +42,12 @@
"smw-setupcheck-why-this-page": {
"en": "Why do I see this page?"
},
"smw-setupcheck-temporarily-disable": {
"en": "To temporarily disable this error output and return to a working MediaWiki (without Semantic MediaWiki), remove the <code>enableSemantics</code> from your <code>LocalSettings.php</code>."
},
"smw-setupcheck-requires-db-minimum-version": {
"en": "During the installation, the setup check found that the minimum requirement for the database environment defined by Semantic MediaWiki didn't match with the version available and is the reason why the installation of Semantic MediaWiki was aborted."
},
"smw-setupcheck-dependency-requires-semanticmediawiki":{
"en": "The reported extension requires Semantic MediaWiki to be enabled which is currently <b>not</b> the case thus adding <code>enableSemantics</code> to <code>LocalSettings.php</code> should resolve the dependency error."
},
Expand All @@ -40,7 +58,7 @@
"en": "It was reported that multiple extensions have failed their dependencies including:"
},
"smw-setupcheck-enablesemantics-assistance": {
"en": "Information about <a href='https://www.semantic-mediawiki.org/wiki/Help:EnableSemantics'>enableSemantics</a> is available on the correponding help page, you may also ask the <a href='https://www.semantic-mediawiki.org/wiki/Help:Getting_support'>project support</a> for assistance."
"en": "Information about <a href='https://www.semantic-mediawiki.org/wiki/Help:EnableSemantics'>enableSemantics</a> is available on the corresponding help page, you may also ask the <a href='https://www.semantic-mediawiki.org/wiki/Help:Getting_support'>project support</a> for assistance."
},
"smw-setupcheck-remove-wfloadextension": {
"en": "Removing <code>wfLoadExtension( 'SemanticMediaWiki' )</code> from <code>LocalSettings.php</code> is sufficient to avoid any conflicts with <code>enableSemantics</code> and ensures that required variables and parameters are setup correctly."
Expand Down
25 changes: 22 additions & 3 deletions src/SetupCheck.php
Expand Up @@ -49,6 +49,11 @@ class SetupCheck {
*/
const ERROR_EXTENSION_INCOMPATIBLE = 'ERROR_EXTENSION_INCOMPATIBLE';

/**
* Extension doesn't match the DB requirement for Semantic MediaWiki.
*/
const ERROR_DB_REQUIREMENT_INCOMPATIBLE = 'ERROR_DB_REQUIREMENT_INCOMPATIBLE';

/**
* The upgrade key has change causing the schema to be invalid
*/
Expand Down Expand Up @@ -251,6 +256,8 @@ public function hasError() {
$this->errorType = self::ERROR_EXTENSION_LOAD;
} elseif ( $this->setupFile->inMaintenanceMode() ) {
$this->errorType = self::MAINTENANCE_MODE;
} elseif ( $this->setupFile->hasDatabaseMinRequirement() === false ) {
$this->errorType = self::ERROR_DB_REQUIREMENT_INCOMPATIBLE;
} elseif ( $this->setupFile->isGoodSchema() === false ) {
$this->errorType = self::ERROR_SCHEMA_INVALID_KEY;
}
Expand Down Expand Up @@ -309,7 +316,8 @@ public function getError( $isCli = false ) {
'/setupcheck/setupcheck.section.ms' => 'section',
'/setupcheck/setupcheck.version.ms' => 'version',
'/setupcheck/setupcheck.paragraph.ms' => 'paragraph',
'/setupcheck/setupcheck.errorbox.ms' => 'errorbox'
'/setupcheck/setupcheck.errorbox.ms' => 'errorbox',
'/setupcheck/setupcheck.db.requirement.ms' => 'db-requirement',
]
);

Expand Down Expand Up @@ -452,8 +460,19 @@ private function createContent( $value, $type ) {
$args['code-type'] = $type;
}

// The type is exepcted to match a defined target and in an event those
// don't match an exception will be raised.
if ( $value['type'] === 'db-requirement' ) {
$requirements = $this->setupFile->get( SetupFile::DB_REQUIREMENTS );
$args['version-title'] = $text;
$args['db-title'] = $this->createCopy( 'smw-setupcheck-db-title' );
$args['db-type'] = $requirements['type'];
$args['db-current-title'] = $this->createCopy( 'smw-setupcheck-db-current-title' );
$args['db-minimum-title'] = $this->createCopy( 'smw-setupcheck-db-minimum-title' );
$args['db-current-version'] = $requirements['latest_version'];
$args['db-minimum-version'] = $requirements['minimum_version'];
}

// The type is expected to match a defined target and in an event
// that those don't match an exception will be raised.
$this->templateEngine->compile(
$value['type'],
$args
Expand Down
30 changes: 30 additions & 0 deletions src/SetupFile.php
Expand Up @@ -26,6 +26,11 @@ class SetupFile {
*/
const UPGRADE_KEY = 'upgrade_key';

/**
* Describes the database requirements
*/
const DB_REQUIREMENTS = 'db_requirements';

/**
* Describes the file name
*/
Expand Down Expand Up @@ -246,6 +251,31 @@ public function removeIncompleteTask( string $key ) {
$this->set( [ self::INCOMPLETE_TASKS => $incomplete_tasks ] );
}

/**
* @since 3.2
*
* @param array $vars
*
* @return boolean
*/
public function hasDatabaseMinRequirement( array $vars = [] ) : bool {

if ( $vars === [] ) {
$vars = $GLOBALS;
}

$id = Site::id();

// No record means, no issues!
if ( !isset( $vars['smw.json'][$id][self::DB_REQUIREMENTS] ) ) {
return true;
}

$requirements = $vars['smw.json'][$id][self::DB_REQUIREMENTS];

return version_compare( $requirements['latest_version'], $requirements['minimum_version'], 'ge' );
}

/**
* @since 3.1
*
Expand Down
40 changes: 40 additions & 0 deletions tests/phpunit/Unit/SetupFileTest.php
Expand Up @@ -360,4 +360,44 @@ public function testSetLatestVersion() {
);
}

public function testHasDatabaseMinRequirement() {

$id = \SMW\Site::id();

$file = $this->getMockBuilder( '\SMW\Utils\File' )
->disableOriginalConstructor()
->getMock();

$instance = new SetupFile(
$file
);

$vars = [
'smw.json' => [ $id => [ 'Foo' => 42 ] ]
];

// No requirement entry
$this->assertTrue(
$instance->hasDatabaseMinRequirement( $vars )
);

// Doesn't match the the `minimum_version`
$vars = [
'smw.json' => [ $id => [ SetupFile::DB_REQUIREMENTS => [ 'latest_version' => '2', 'minimum_version' => '3' ] ] ]
];

$this->assertFalse(
$instance->hasDatabaseMinRequirement( $vars )
);

$vars = [
'smw.json' => [ $id => [ SetupFile::DB_REQUIREMENTS => [ 'latest_version' => '3.1', 'minimum_version' => '3' ] ] ]
];

// Does match the the `minimum_version`
$this->assertTrue(
$instance->hasDatabaseMinRequirement( $vars )
);
}

}

0 comments on commit 178dc77

Please sign in to comment.