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
/**
18
 * this file contains the task to suspend users from the upload folder.
19
 *
20
 * File         fromfolder.php
21
 * Encoding     UTF-8
22
 * @copyright   Sebsoft.nl
23
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
namespace tool_usersuspension\task\unsuspend;
27
 
28
defined('MOODLE_INTERNAL') || die;
29
use tool_usersuspension\config;
30
use tool_usersuspension\processor\csv as csvprocessor;
31
 
32
require_once($CFG->libdir . '/csvlib.class.php');
33
 
34
/**
35
 * Description of fromfolder
36
 *
37
 * @package     tool_usersuspension
38
 *
39
 * @copyright   Sebsoft.nl
40
 * @author      R.J. van Dongen <rogier@sebsoft.nl>
41
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
42
 */
43
class fromfolder extends \core\task\scheduled_task {
44
 
45
    /**
46
     * Return the localised name for this task
47
     *
48
     * @return string task name
49
     */
50
    public function get_name() {
51
        return get_string('task:unsuspendfromfolder', 'tool_usersuspension');
52
    }
53
 
54
    /**
55
     * Executes the task
56
     *
57
     * @return void
58
     */
59
    public function execute() {
60
        if (!(bool)config::get('enabled')) {
61
            mtrace(get_string('config:tool:disabled', 'tool_usersuspension'));
62
            return;
63
        }
64
        if (!(bool)config::get('enableunsuspendfromfolder')) {
65
            mtrace(get_string('config:unsuspendfromfolder:disabled', 'tool_usersuspension'));
66
            return;
67
        }
68
        $uploadedfile = config::get('uploadfolder') . '/' . config::get('unsuspenduploadfilename');
69
        if (!file_exists($uploadedfile) || is_dir($uploadedfile)) {
70
            mtrace('CSV File "'.$uploadedfile.'" does not exist: break');
71
            return;
72
        }
73
 
74
        if (!is_readable($uploadedfile)) {
75
            mtrace(get_string('msg:file-not-readable', 'tool_usersuspension', $uploadedfile));
76
            return;
77
        }
78
 
79
        $choices = \csv_import_reader::get_delimiter_list();
80
 
81
        // Process uploaded file.
82
        $proc = new csvprocessor();
83
        $proc->set_file($uploadedfile);
84
        $proc->set_delimiter($choices[config::get('csvdelimiter')]);
85
        $proc->set_enclosure('"');
86
        $proc->set_notifycallback('mtrace');
87
        $proc->set_mode(csvprocessor::MODE_UNSUSPEND);
88
        $proc->process();
89
        // Delete uploaded file.
90
        if (is_writable($uploadedfile)) {
91
            unlink($uploadedfile);
92
        } else {
93
            mtrace(get_string('msg:file-not-writeable', 'tool_usersuspension', $uploadedfile));
94
        }
95
    }
96
 
97
}