• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ProjektAdLer / MoodlePluginLocalLogging / 11539711634

27 Oct 2024 10:26AM UTC coverage: 90.323% (+3.8%) from 86.486%
11539711634

push

github

Glutamat42
fix copy paste errors

56 of 62 relevant lines covered (90.32%)

3.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.89
/classes/task/log_rotation_task.php
1
<?php
2
namespace local_logging\task;
3

4
use coding_exception;
5
use core\di;
6
use core\task\scheduled_task;
7
use dml_exception;
8
use lang_string;
9
use local_logging\local\db\log_repository;
10

11
defined('MOODLE_INTERNAL') || die();
×
12

13
class log_rotation_task extends scheduled_task {
14

15
    /**
16
     * @throws coding_exception
17
     */
18
    public function get_name(): lang_string|string {
19
        return get_string('logrotationtask', 'local_logging');
1✔
20
    }
21

22
    /**
23
     * @throws dml_exception
24
     */
25
    public function execute(): void {
26
        global $CFG;
27

28
        $maxLogs = $CFG->local_logging_maxlogs ?? 10000; // Default to 10,000 if not set
1✔
29
        $logCount = di::get(log_repository::class)->count();
1✔
30

31
        if ($logCount > $maxLogs) {
1✔
32
            $deleteCount = $logCount - $maxLogs;
1✔
33

34
            // Select the IDs of the records to delete
35
            $records_to_delete = di::get(log_repository::class)->get_records_range(0, $deleteCount, 'id ASC');
1✔
36

37
            // Delete the records
38
            foreach ($records_to_delete as $record) {
1✔
39
                di::get(log_repository::class)->delete($record->id);
1✔
40
            }
41
        }
42
    }
43
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc