Skip to content

Commit

Permalink
Merge pull request #21 from wunderio/feature/disable_reporting
Browse files Browse the repository at this point in the history
Add setting to "disable" reporting
  • Loading branch information
Juhani-moilanen authored Mar 16, 2023
2 parents d74ee42 + 556daf9 commit f73151b
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 14 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ It is detected by using first non-empty item:
- Settings `simple_environment_indicator` + color removal
- `"unknown"`

## Settings

You can add `$settings['updates_log_disabled'] = TRUE;` in your `settings.php` to stop updates_log from reporting.

This is useful for sites that want to report updates in only one environment.

## Development of `updates_log`

- Clone [drupal-project](https://github.com/wunderio/drupal-project) as a base
Expand Down
4 changes: 3 additions & 1 deletion src/UpdatesLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ public function __construct(
* The top-level logic of the module.
*/
public function run(): void {

if (Settings::get('updates_log_disabled', FALSE)) {
return;
}
$now = time();
$last = $this->getLastRan();
if (!$this->shouldUpdate($now, $last)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Kernel/GetEnvTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace tests\src\Kernel;
namespace Drupal\Tests\updates_log\Kernel;

use Drupal\Core\Site\Settings;
use Drupal\KernelTests\KernelTestBase;
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Kernel/GetSiteTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace tests\src\Kernel;
namespace Drupal\Tests\updates_log\Kernel;

use Drupal\Core\Site\Settings;
use Drupal\KernelTests\KernelTestBase;
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Kernel/GetVersionTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace tests\src\Kernel;
namespace Drupal\Tests\updates_log\Kernel;

use Drupal\KernelTests\KernelTestBase;
use Drupal\updates_log\UpdatesLog;
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Kernel/HookTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace tests\src\Kernel;
namespace Drupal\Tests\updates_log\Kernel;

use Drupal\KernelTests\KernelTestBase;
use Drupal\updates_log\UpdatesLog;
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Kernel/LogTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace tests\src\Kernel;
namespace Drupal\Tests\updates_log\Kernel;

use Drupal\Core\Database\Connection;
use Drupal\KernelTests\KernelTestBase;
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Kernel/LogUnknownTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace tests\src\Kernel;
namespace Drupal\Tests\updates_log\Kernel;

use Drupal\Core\Database\Connection;
use Drupal\KernelTests\KernelTestBase;
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Kernel/RunDiffTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace tests\src\Kernel;
namespace Drupal\Tests\updates_log\Kernel;

use Drupal\KernelTests\KernelTestBase;
use Drupal\updates_log\UpdatesLog;
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Kernel/RunStatisticsTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace tests\src\Kernel;
namespace Drupal\Tests\updates_log\Kernel;

use Drupal\KernelTests\KernelTestBase;
use Drupal\updates_log\UpdatesLog;
Expand Down
73 changes: 73 additions & 0 deletions tests/src/Kernel/UpdatesLogDisabledTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace Drupal\Tests\updates_log\Kernel;

use Drupal\Core\Site\Settings;
use Drupal\Core\Database\Connection;
use Drupal\KernelTests\KernelTestBase;
use Drupal\updates_log\UpdatesLog;

/**
* Tests that "updates_log_disabled" setting works as expected.
*
* @group updates_log
*/
class UpdatesLogDisabledTest extends KernelTestBase {

/**
* The UpdatesLog service.
*
* @var \Drupal\updates_log\UpdatesLog
*/
private UpdatesLog $updatesLogService;

/**
* The Database Connection.
*
* @var \Drupal\Core\Database\Connection
*/
private Connection $db;

/**
* The modules to load to run the test.
*
* @var array
*/
protected static $modules = [
'update',
'updates_log',
'dblog',
];

/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->installConfig(['updates_log']);
$this->installSchema('dblog', ['watchdog']);
$this->updatesLogService = \Drupal::service('updates_log.updates_logger');
$this->db = \Drupal::database();
}

/**
* Test that there is no output when disabled = TRUE.
*/
public function testDisabledDoesNotRun(): void {
new Settings(['updates_log_disabled' => TRUE]);
$this->updatesLogService->run();
$query = $this->db->query("select * from {watchdog}");
$result = $query->fetchAll();
$this->assertEmpty($result);
}

/**
* If UpdatesLogRunTest::testCrash is good then we know this works.
*
* @depends Drupal\Tests\updates_log\Kernel\UpdatesLogRunTest::testCrash
*/
public function testNotDisabledRuns(): void {
$this->assertTrue(TRUE);
}

}
2 changes: 1 addition & 1 deletion tests/src/Kernel/UpdatesLogRunTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace tests\src\Kernel;
namespace Drupal\Tests\updates_log\Kernel;

use Drupal\KernelTests\KernelTestBase;
use Drupal\updates_log\UpdatesLog;
Expand Down
4 changes: 1 addition & 3 deletions tests/src/Unit/GenerateStatisticsTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php

namespace tests\src\Unit;

use Drupal\Tests\updates_log\Unit\UpdatesLogTestBase;
namespace Drupal\Tests\updates_log\Unit;

/**
* @coversDefaultClass \Drupal\updates_log\UpdatesLog
Expand Down
2 changes: 1 addition & 1 deletion updates_log.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ description: "Log module update info"
core: 8.x
core_version_requirement: ^8 || ^9 || ^10
package: Development
version: 2.1.1
version: 2.2.1
dependencies:
- drupal:update

0 comments on commit f73151b

Please sign in to comment.