Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
namespace mod_bigbluebuttonbn\task;
18
 
19
use core\task\adhoc_task;
20
use mod_bigbluebuttonbn\recording;
21
 
22
/**
23
 * Class containing the scheduled task for converting recordings for the BigBlueButton version 2.5 in Moodle 4.0.
24
 *
25
 * @package   mod_bigbluebuttonbn
26
 * @copyright 2021 Jesus Federico, Blindside Networks Inc <jesus at blindsidenetworks dot com>
27
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
 */
29
class reset_recordings extends adhoc_task {
30
 
31
    /** @var int Chunk size to use when resetting recordings */
32
    protected static $chunksize = 100;
33
 
34
    /**
35
     * Run the migration task.
36
     */
37
    public function execute() {
38
        if ($this->process_reset_recordings()) {
39
            \core\task\manager::queue_adhoc_task(new static());
40
        }
41
    }
42
 
43
    /**
44
     * Process all bigbluebuttonbn_recordings looking for entries which should be reset to be fetched again.
45
     *
46
     * @return bool Whether any more recodgins are waiting to be processed
47
     */
48
    protected function process_reset_recordings(): bool {
49
        global $DB;
50
 
51
        $classname = static::class;
52
 
53
        mtrace("Executing {$classname}...");
54
 
55
        // Read a block of recordings to be updated.
56
        $recs = $this->get_recordngs_to_reset();
57
 
58
        if (empty($recs)) {
59
            mtrace("No recordings were found for reset...");
60
            // No more logs. Stop queueing.
61
            return false;
62
        }
63
 
64
        // Reset status of {chunksize} recordings.
65
        mtrace("Reset status of " . self::$chunksize . " recordings...");
66
        $sql = "UPDATE {bigbluebuttonbn_recordings}
67
                SET status = :status_reset
68
                WHERE id = " . implode(' OR id = ', array_keys($recs));
69
        $DB->execute($sql,
70
            ['status_reset' => recording::RECORDING_STATUS_RESET]
71
        );
72
 
73
        return true;
74
    }
75
 
76
    /**
77
     * Get the list of recordings to be reset.
78
     *
79
     * @return array
80
     */
81
    protected function get_recordngs_to_reset(): array {
82
        global $DB;
83
 
84
        return $DB->get_records_sql(
85
            'SELECT * FROM {bigbluebuttonbn_recordings}
86
             WHERE status = :status_processed OR status = :status_notified
87
             ORDER BY timecreated DESC', [
88
                'status_processed' => recording::RECORDING_STATUS_PROCESSED,
89
                'status_notified' => recording::RECORDING_STATUS_NOTIFIED
90
            ],
91
            0,
92
            self::$chunksize
93
        );
94
    }
95
 
96
}