objectcache: Use DBO_DEBUG when DebugDumpSql setting is set to true

This is to be consistent with the DBO_* constants in IDatabaseFlags.php
not use the setting value directly.

This worked in the past because it evaluates to true or false based on
$sqlDump, which means instead of setting flags to DBO_DEBUG (int), it was
setting it to bool(true).

This worked by accident because:
* when we perform -, +, | or & math on a value, it is casted to an integer,
* and intval(true) === 1,
* and DBO_DEBUG is the first constant in DatabaseFlagsHolder, which we gave
  the number 1.

It is only the combination of all three of these facts that made it work by
accident.

Follow-up: I4ce691b77f775c20bcf4e8deb2ec1aae1b4674d8
Bug: T318272
Change-Id: I8ba1d35f0e36ae259830fc1f65fcb4e4dc92a8ec
This commit is contained in:
Derick Alangi 2023-09-05 16:41:25 +01:00
parent 0856b5c93a
commit 5f37db6744
No known key found for this signature in database
GPG key ID: 01D205B3F82BADDA

View file

@ -1678,6 +1678,11 @@ class SqlBagOStuff extends MediumSpecificBagOStuff {
$services = MediaWikiServices::getInstance();
$dbFactory = $services->getDatabaseFactory();
$sqlDump = $services->getMainConfig()->get( MainConfigNames::DebugDumpSql );
$server['flags'] ??= 0;
if ( $sqlDump ) {
$server['flags'] |= DBO_DEBUG;
}
/** @var IMaintainableDatabase $conn Auto-commit connection to the server */
$conn = $dbFactory->create(
$server['type'],
@ -1685,7 +1690,7 @@ class SqlBagOStuff extends MediumSpecificBagOStuff {
$server,
[
// Make sure the handle uses autocommit mode
'flags' => ( $server['flags'] ?? $sqlDump ) & ~IDatabase::DBO_TRX,
'flags' => ( $server['flags'] ) & ~IDatabase::DBO_TRX,
'logger' => $this->logger,
]
)