mirror of
https://github.com/Universal-Omega/DynamicPageList3
synced 2024-09-23 10:22:39 +00:00
Use database update maintenance script for creating VIEW (#165)
This commit is contained in:
parent
7ad00427e6
commit
c4bff23bf6
|
@ -32,7 +32,8 @@
|
|||
"DynamicPageList3Magic": "DynamicPageList3Magic.php"
|
||||
},
|
||||
"AutoloadClasses": {
|
||||
"MediaWiki\\Extension\\DynamicPageList3\\Maintenance\\CreateTemplate": "maintenance/createTemplate.php"
|
||||
"MediaWiki\\Extension\\DynamicPageList3\\Maintenance\\CreateTemplate": "maintenance/createTemplate.php",
|
||||
"MediaWiki\\Extension\\DynamicPageList3\\Maintenance\\CreateView": "maintenance/createView.php"
|
||||
},
|
||||
"AutoloadNamespaces": {
|
||||
"MediaWiki\\Extension\\DynamicPageList3\\": "includes/"
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace MediaWiki\Extension\DynamicPageList3;
|
|||
|
||||
use DatabaseUpdater;
|
||||
use MediaWiki\Extension\DynamicPageList3\Maintenance\CreateTemplate;
|
||||
use MediaWiki\Extension\DynamicPageList3\Maintenance\CreateView;
|
||||
use Parser;
|
||||
use PPFrame;
|
||||
|
||||
|
@ -626,12 +627,6 @@ class Hooks {
|
|||
*/
|
||||
public static function onLoadExtensionSchemaUpdates( DatabaseUpdater $updater ) {
|
||||
$updater->addPostDatabaseUpdateMaintenance( CreateTemplate::class );
|
||||
|
||||
$db = $updater->getDB();
|
||||
if ( !$db->tableExists( 'dpl_clview' ) ) {
|
||||
// PostgreSQL doesn't have IFNULL, so use COALESCE instead
|
||||
$sqlNullMethod = ( $db->getType() === 'postgres' ? 'COALESCE' : 'IFNULL' );
|
||||
$db->query( "CREATE VIEW {$db->tablePrefix()}dpl_clview AS SELECT $sqlNullMethod(cl_from, page_id) AS cl_from, $sqlNullMethod(cl_to, '') AS cl_to, cl_sortkey FROM {$db->tablePrefix()}page LEFT OUTER JOIN {$db->tablePrefix()}categorylinks ON {$db->tablePrefix()}page.page_id=cl_from;" );
|
||||
}
|
||||
$updater->addPostDatabaseUpdateMaintenance( CreateView::class );
|
||||
}
|
||||
}
|
||||
|
|
58
maintenance/createView.php
Normal file
58
maintenance/createView.php
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\DynamicPageList3\Maintenance;
|
||||
|
||||
use LoggedUpdateMaintenance;
|
||||
|
||||
$IP = getenv( 'MW_INSTALL_PATH' );
|
||||
if ( $IP === false ) {
|
||||
$IP = __DIR__ . '/../../..';
|
||||
}
|
||||
|
||||
require_once "$IP/maintenance/Maintenance.php";
|
||||
|
||||
class CreateView extends LoggedUpdateMaintenance {
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
$this->addDescription( 'Handle creating DPL3\'s dpl_clview VIEW.' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the unique update key for this logged update.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getUpdateKey() {
|
||||
return 'dynamic-page-list-3-create-view';
|
||||
}
|
||||
|
||||
/**
|
||||
* Message to show that the update was done already and was just skipped
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function updateSkippedMessage() {
|
||||
return 'VIEW already created.';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle creating DPL3's dpl_clview VIEW.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function doDBUpdates() {
|
||||
$dbw = $this->getDB( DB_PRIMARY );
|
||||
if ( !$dbw->tableExists( 'dpl_clview' ) ) {
|
||||
// PostgreSQL doesn't have IFNULL, so use COALESCE instead
|
||||
$sqlNullMethod = ( $dbw->getType() === 'postgres' ? 'COALESCE' : 'IFNULL' );
|
||||
$dbw->query( "CREATE VIEW {$dbw->tablePrefix()}dpl_clview AS SELECT $sqlNullMethod(cl_from, page_id) AS cl_from, $sqlNullMethod(cl_to, '') AS cl_to, cl_sortkey FROM {$dbw->tablePrefix()}page LEFT OUTER JOIN {$dbw->tablePrefix()}categorylinks ON {$dbw->tablePrefix()}page.page_id=cl_from;" );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$maintClass = CreateView::class;
|
||||
require_once RUN_MAINTENANCE_IF_MAIN;
|
Loading…
Reference in a new issue