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 | * @package tool_xmldb |
---|
19 | * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} |
---|
20 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
---|
21 | */ |
---|
22 | |
---|
23 | /** |
---|
24 | * This class will load every XML file to memory if necessary |
---|
25 | * |
---|
26 | * @package tool_xmldb |
---|
27 | * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} |
---|
28 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
---|
29 | */ |
---|
30 | class load_xml_files extends XMLDBAction { |
---|
31 | |
---|
32 | /** |
---|
33 | * Init method, every subclass will have its own |
---|
34 | */ |
---|
35 | function init() { |
---|
36 | parent::init(); |
---|
37 | // Set own core attributes |
---|
38 | $this->can_subaction = ACTION_NONE; |
---|
39 | //$this->can_subaction = ACTION_HAVE_SUBACTIONS; |
---|
40 | |
---|
41 | // Set own custom attributes |
---|
42 | |
---|
43 | // Get needed strings |
---|
44 | $this->loadStrings(array( |
---|
45 | // 'key' => 'module', |
---|
46 | )); |
---|
47 | } |
---|
48 | |
---|
49 | /** |
---|
50 | * Invoke method, every class will have its own |
---|
51 | * returns true/false on completion, setting both |
---|
52 | * errormsg and output as necessary |
---|
53 | */ |
---|
54 | function invoke() { |
---|
55 | parent::invoke(); |
---|
56 | |
---|
57 | $result = true; |
---|
58 | |
---|
59 | // Set own core attributes |
---|
60 | $this->does_generate = ACTION_NONE; |
---|
61 | //$this->does_generate = ACTION_GENERATE_HTML; |
---|
62 | |
---|
63 | // These are always here |
---|
64 | global $CFG, $XMLDB; |
---|
65 | |
---|
66 | // Do the job, setting $result as needed |
---|
67 | |
---|
68 | // Iterate over $XMLDB->dbdirs, loading their XML data to memory |
---|
69 | if ($XMLDB->dbdirs) { |
---|
70 | $dbdirs = $XMLDB->dbdirs; |
---|
71 | foreach ($dbdirs as $dbdir) { |
---|
72 | // Set some defaults |
---|
73 | $dbdir->xml_exists = false; |
---|
74 | $dbdir->xml_writeable = false; |
---|
75 | $dbdir->xml_loaded = false; |
---|
76 | // Only if the directory exists |
---|
77 | if (!$dbdir->path_exists) { |
---|
78 | continue; |
---|
79 | } |
---|
80 | $xmldb_file = new xmldb_file($dbdir->path . '/install.xml'); |
---|
81 | // Set dbdir as necessary |
---|
82 | if ($xmldb_file->fileExists()) { |
---|
83 | $dbdir->xml_exists = true; |
---|
84 | } |
---|
85 | if ($xmldb_file->fileWriteable()) { |
---|
86 | $dbdir->xml_writeable = true; |
---|
87 | } |
---|
88 | // Load the XML contents to structure |
---|
89 | $loaded = $xmldb_file->loadXMLStructure(); |
---|
90 | if ($loaded && $xmldb_file->isLoaded()) { |
---|
91 | $dbdir->xml_loaded = true; |
---|
92 | } |
---|
93 | $dbdir->xml_file = $xmldb_file; |
---|
94 | } |
---|
95 | } |
---|
96 | return $result; |
---|
97 | } |
---|
98 | } |
---|
99 | |
---|