[ContributionTracking] default DB settings differs when using extension registration
Closed, ResolvedPublic1 Story Points

Description

Previously we loaded the extension by including ContributionTracking.php which points the database to the master:

$wgContributionTrackingDBserver = $wgDBserver;
$wgContributionTrackingDBname = $wgDBname;
$wgContributionTrackingDBuser = $wgDBuser;
$wgContributionTrackingDBpassword = $wgDBpassword;

With extension registration (wfLoadExtension( 'ContributionTracking' ) from T87903) the PHP file is not processed and the four variables are NULL.

The LoadExtensionSchemaUpdates hook eventually invokes:

ContributionTracking.processor.php
static function contributionTrackingConnection() { 
    global $wgContributionTrackingDBserver, $wgContributionTrackingDBname;
    global $wgContributionTrackingDBuser, $wgContributionTrackingDBpassword;
    global $wgDBserver, $wgDBname;

    static $db;

    if ( !$db ) { 
        if ( $wgContributionTrackingDBserver === $wgDBserver &&
            $wgContributionTrackingDBname === $wgDBname
        ) { 
            $db = wfGetDB( DB_MASTER );
        } else { 
            $params = [ 
                'host' => $wgContributionTrackingDBserver,
                'user' => $wgContributionTrackingDBuser,
                'password' => $wgContributionTrackingDBpassword,
                'dbname' => $wgContributionTrackingDBname
            ];
            $db = Database::factory( 'mysql', $params );
        } 
    } 

    return $db;
}

Since $wgContributionTrackingDBserver and $wgContributionTrackingDBname are NULL, the DB_MASTER is not retrieved. The code then attempts to create a MySQL database using NULL host/user/password/dbname:

Creating tables for enabled extensions
$wgContributionTrackingDBserver = NULL
$wgContributionTrackingDBname = NULL
[no req] InvalidArgumentException from line 374 of includes/libs/rdbms/database/Database.php: No database user provided.
Backtrace:
#0 includes/libs/rdbms/database/Database.php(350): Wikimedia\Rdbms\Database->doInitConnection()
#1 includes/libs/rdbms/database/Database.php(463): Wikimedia\Rdbms\Database->initConnection()
#2 extensions/ContributionTracking/ContributionTracking.processor.php(44): Wikimedia\Rdbms\Database::factory(string, array)
#3 extensions/ContributionTracking/ContributionTracking.hooks.php(57): ContributionTrackingProcessor::contributionTrackingConnection()
#4 includes/Hooks.php(174): ContributionTrackingHooks::onLoadExtensionSchemaUpdates(SqliteUpdater)
#5 includes/Hooks.php(202): Hooks::callHook(string, array, array, NULL)
#6 includes/installer/DatabaseUpdater.php(127): Hooks::run(string, array)
#7 includes/installer/DatabaseUpdater.php(192): DatabaseUpdater->__construct(Wikimedia\Rdbms\DatabaseSqlite, boolean, NULL)
#8 includes/installer/DatabaseInstaller.php(312): DatabaseUpdater::newForDB(Wikimedia\Rdbms\DatabaseSqlite)
#9 includes/installer/Installer.php(1567): DatabaseInstaller->createExtensionTables(SqliteInstaller)
#10 includes/installer/CliInstaller.php(138): Installer->performInstallation(array, array)
#11 maintenance/install.php(125): CliInstaller->execute()
#12 maintenance/doMaintenance.php(94): CommandLineInstaller->execute()
#13 maintenance/install.php(175): require_once(string)
#14 {main}
hashar created this task.May 29 2018, 8:36 AM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptMay 29 2018, 8:36 AM
hashar updated the task description. (Show Details)

I have tried using a the extension registration callback hook to set default values but it is apparently not run before the LoadExtensionSchemaUpdate hook.

Vvjjkkii renamed this task from [ContributionTracking] default DB settings differs when using extension registration to 13baaaaaaa.Sun, Jul 1, 1:07 AM
Vvjjkkii triaged this task as High priority.
Vvjjkkii updated the task description. (Show Details)
Vvjjkkii removed a subscriber: Aklapper.
CommunityTechBot raised the priority of this task from High to Needs Triage.
CommunityTechBot renamed this task from 13baaaaaaa to [ContributionTracking] default DB settings differs when using extension registration.
CommunityTechBot added a subscriber: Aklapper.

Change 445456 had a related patch set uploaded (by Ejegg; owner: Ejegg):
[mediawiki/extensions/ContributionTracking@master] DB settings default to null

https://gerrit.wikimedia.org/r/445456

Ejegg triaged this task as Normal priority.
Ejegg claimed this task.
Ejegg set the point value for this task to 1.

Change 445456 merged by jenkins-bot:
[mediawiki/extensions/ContributionTracking@master] DB settings default to null

https://gerrit.wikimedia.org/r/445456

Change 446184 had a related patch set uploaded (by Hashar; owner: Hashar):
[integration/config@master] Migrate ContributionTracking to Quibble

https://gerrit.wikimedia.org/r/446184

hashar closed this task as Resolved.Mon, Jul 16, 8:46 PM

Thank you!!!

Change 446184 merged by jenkins-bot:
[integration/config@master] Migrate ContributionTracking to Quibble

https://gerrit.wikimedia.org/r/446184