1 <?php 2 // This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>. 16 17 /** 18 * List all the files needing reconcile because the definitions don't match the XML contents. 19 * 20 * @package tool_xmldb 21 * @copyright 2022 onwards Eloy Lafuente (stronk7) {@link https://stronk7.com} 22 * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 class reconcile_files extends XMLDBAction { 25 26 /** 27 * Init method, every subclass will have its own 28 */ 29 public function init() { 30 parent::init(); 31 32 // Set own custom attributes. 33 $this->sesskey_protected = false; // This action doesn't need sesskey protection. 34 35 // Get needed strings. 36 $this->loadStrings([ 37 'backtomainview' => 'tool_xmldb', 38 'reconcile_files_intro' => 'tool_xmldb', 39 'reconcile_files_no' => 'tool_xmldb', 40 'reconcile_files_yes' => 'tool_xmldb', 41 'searchresults' => 'tool_xmldb', 42 ]); 43 } 44 45 /** 46 * Invoke method, every class will have its own 47 * returns true/false on completion, setting both 48 * errormsg and output as necessary 49 */ 50 public function invoke() { 51 parent::invoke(); 52 53 $result = true; 54 55 // Set own core attributes. 56 $this->does_generate = ACTION_GENERATE_HTML; 57 58 // These are always here. 59 global $CFG, $XMLDB; 60 61 // Do the job, setting $result as needed. 62 63 // Add link back to home. 64 $b = ' <p class="centerpara">'; 65 $b .= ' <a href="index.php?action=main_view#lastused">[' . $this->str['backtomainview'] . ']</a>'; 66 $b .= '</p>'; 67 $this->output .= $b; 68 69 $c = '<p class="centerpara">'; 70 $c .= $this->str['reconcile_files_intro']; 71 $c .= '</p>'; 72 $this->output .= $c; 73 74 // Get the list of DB directories. 75 $result = $this->launch('get_db_directories'); 76 if ($result && !empty($XMLDB->dbdirs)) { 77 $needfix = []; 78 foreach ($XMLDB->dbdirs as $key => $dbdir) { 79 // Verify it exists. 80 if (!file_exists($key . '/install.xml') && !is_readable($key . '/install.xml')) { 81 continue; 82 } 83 84 // Read the raw contents of the file. 85 $rawcontents = file_get_contents($key . '/install.xml'); 86 87 // Load the XMLDB file and its structure. 88 $xmldb = new xmldb_file($key . '/install.xml'); 89 $xmldb->loadXMLStructure(); 90 91 // Generate the XML contents from the loaded structure. 92 $xmlcontents = $xmldb->getStructure()->xmlOutput(); 93 94 if ($rawcontents != $xmlcontents) { 95 $relpath = str_replace($CFG->dirroot . '/', '', $key) . '/install.xml'; 96 $needfix[] = $relpath; 97 // Left here on purpose, as a quick way to fix problems. To be 98 // enabled and run by developers only, uncomment the next line: 99 // file_put_contents($key . '/install.xml', $xmlcontents); 100 // (this script won't ever do that officially). 101 } 102 } 103 } 104 105 $r = '<h3 class="main">' . $this->str['searchresults'] . '</h3>'; 106 if ($needfix) { 107 $r .= '<h4 class="main">' . $this->str['reconcile_files_yes'] . count($needfix) . '</h4>'; 108 $r .= '<ul><li>' . implode('</li><li>', $needfix) . '</li></ul>'; 109 110 } else { 111 $r .= '<h4 class="main">' . $this->str['reconcile_files_no'] . '</h4>'; 112 } 113 114 // Set the output. 115 $this->output .= $r; 116 117 // Launch postaction if exists (leave this unmodified). 118 if ($this->getPostAction() && $result) { 119 return $this->launch($this->getPostAction()); 120 } 121 122 return $result; 123 } 124 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body