Skip to content

Commit 6515d03

Browse files
committed
MOBILE-4239 core: Enable DB logging when needed
1 parent 5f9b4c5 commit 6515d03

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

local_moodleappbehat/tests/behat/behat_app.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');
2020
require_once(__DIR__ . '/behat_app_helper.php');
2121

22+
use Behat\Behat\Hook\Scope\ScenarioScope;
2223
use Behat\Gherkin\Node\TableNode;
2324
use Behat\Mink\Exception\DriverException;
2425
use Behat\Mink\Exception\ExpectationException;
@@ -45,6 +46,27 @@ class behat_app extends behat_app_helper {
4546

4647
protected $windowsize = '360x720';
4748

49+
/**
50+
* @BeforeScenario
51+
*/
52+
public function before_scenario(ScenarioScope $scope) {
53+
if (!$scope->getFeature()->hasTag('app')) {
54+
return;
55+
}
56+
57+
global $CFG;
58+
59+
$performanceLogs = $CFG->behat_profiles['default']['capabilities']['extra_capabilities']['goog:loggingPrefs']['performance'] ?? null;
60+
61+
if ($performanceLogs !== 'ALL') {
62+
return;
63+
}
64+
65+
// Enable DB Logging only for app tests with performance logs activated.
66+
$this->getSession()->visit($this->get_app_url() . '/assets/env.json');
67+
$this->execute_script("document.cookie = 'MoodleAppDBLoggingEnabled=true;path=/';");
68+
}
69+
4870
/**
4971
* Opens the Moodle App in the browser and optionally logs in.
5072
*

src/core/services/db.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { SQLiteDB } from '@classes/sqlitedb';
1818
import { SQLiteDBMock } from '@features/emulator/classes/sqlitedb';
1919
import { CoreBrowser } from '@singletons/browser';
2020
import { makeSingleton, SQLite } from '@singletons';
21-
import { CoreAppProvider } from './app';
2221
import { CorePlatform } from '@services/platform';
2322

2423
const tableNameRegex = new RegExp([
@@ -47,7 +46,7 @@ export class CoreDbProvider {
4746
* @returns Whether queries should be logged.
4847
*/
4948
loggingEnabled(): boolean {
50-
return CoreBrowser.hasDevelopmentSetting('DBLoggingEnabled') || CoreAppProvider.isAutomated();
49+
return CoreBrowser.hasDevelopmentSetting('DBLoggingEnabled');
5150
}
5251

5352
/**

0 commit comments

Comments
 (0)