Pergunta

i have a problem :) I want to use an own PHP file on my server which has the ability to change Options of Users registered in the MediaWiki Installation on same server. For this i have load the webstart and autoload includes. Now, i can read settings of the user logged in at this time without problems. But, if i want to save the edited setting (with setOption()), it appears the following notice:

Notice: Uncommitted DB writes (transaction from DatabaseBase::query (LCStoreDB::get)). in /var/www/wiki/includes/db/Database.php on line 4065 Notice: DB transaction callbacks still pending (from Title::invalidateCache). in /var/www/wiki/includes/db/Database.php on line 4073

and the Option isn't saved to the database :( Have anyone an idea, how to do my task, or how i can solve my problem?

Thanks!

Here is the code:

<?php
$IP = strval( getenv( 'MW_INSTALL_PATH' ) ) !== ''
    ? getenv( 'MW_INSTALL_PATH' )
    : realpath( __DIR__ . '/' );
require_once "$IP/includes/AutoLoader.php";
require_once( "$IP/includes/WebStart.php" );

$t = new User();
$user = $t->newFromSession();
if(!isset($wgCommandLineMode) && !isset($_COOKIE[session_name()])) {
    wfSetupSession();
}
if ($user->isLoggedIn()) {
    $user->setOption( 'skinname', 'vector' );
    $user->setCookies();
    $user->saveSettings();
}

?>

Foi útil?

Solução

You need to properly shut down the database connection when using automatic transactions (which is the default when $wgCommandLineMode is true). Add something like this at the end of your file:

$lb = wfGetLBFactory();
$lb->shutdown();

You'd also probably want to catch any exceptions that might be thrown and do a rollback on all open database connections. As for MediaWiki bug 56269, that's not your issue (although the lack of an ability to do a rollback on all open database connections is probably contributing to that bug).

Outras dicas

Try subclassing the Maintenance class in includes/Maintenance.php and implement the abstract execute function with the desired code. I encountered the same warnings/no saves as you did with uncommitted transactions. Following the example in createAndPromote.php, the database transactions were committed.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top