/admin/tool/xmldb/actions/revert_changes/revert_changes.class.php

https://github.com/Matthew1/moodle · PHP · 120 lines · 56 code · 17 blank · 47 comment · 9 complexity · bdcc3b59234f69a9c89bab02701fcb4d MD5 · raw file

  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. * @package tool
  18. * @subpackage 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. * This class will revert changes (delete the editeddb)
  24. *
  25. * @package tool
  26. * @subpackage 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 revert_changes extends XMLDBAction {
  31. /**
  32. * Init method, every subclass will have its own
  33. */
  34. function init() {
  35. parent::init();
  36. // Set own custom attributes
  37. // Get needed strings
  38. $this->loadStrings(array(
  39. 'confirmrevertchanges' => 'tool_xmldb',
  40. 'yes' => '',
  41. 'no' => ''
  42. ));
  43. }
  44. /**
  45. * Invoke method, every class will have its own
  46. * returns true/false on completion, setting both
  47. * errormsg and output as necessary
  48. */
  49. function invoke() {
  50. parent::invoke();
  51. $result = true;
  52. // Set own core attributes
  53. $this->does_generate = ACTION_GENERATE_HTML;
  54. // These are always here
  55. global $CFG, $XMLDB;
  56. // Do the job, setting result as needed
  57. // Get the dir containing the file
  58. $dirpath = required_param('dir', PARAM_PATH);
  59. $dirpath = $CFG->dirroot . $dirpath;
  60. $confirmed = optional_param('confirmed', false, PARAM_BOOL);
  61. // If not confirmed, show confirmation box
  62. if (!$confirmed) {
  63. $o = '<table width="60" class="generalbox boxaligncenter" border="0" cellpadding="5" cellspacing="0" id="notice">';
  64. $o.= ' <tr><td class="generalboxcontent">';
  65. $o.= ' <p class="centerpara">' . $this->str['confirmrevertchanges'] . '<br /><br />' . $dirpath . '</p>';
  66. $o.= ' <table class="boxaligncenter" cellpadding="20"><tr><td>';
  67. $o.= ' <div class="singlebutton">';
  68. $o.= ' <form action="index.php?action=revert_changes&amp;sesskey=' . sesskey() . '&amp;confirmed=yes&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;postaction=main_view#lastused" method="post"><fieldset class="invisiblefieldset">';
  69. $o.= ' <input type="submit" value="'. $this->str['yes'] .'" /></fieldset></form></div>';
  70. $o.= ' </td><td>';
  71. $o.= ' <div class="singlebutton">';
  72. $o.= ' <form action="index.php?action=main_view#lastused" method="post"><fieldset class="invisiblefieldset">';
  73. $o.= ' <input type="submit" value="'. $this->str['no'] .'" /></fieldset></form></div>';
  74. $o.= ' </td></tr>';
  75. $o.= ' </table>';
  76. $o.= ' </td></tr>';
  77. $o.= '</table>';
  78. $this->output = $o;
  79. } else {
  80. // Get the original dir and delete some elements
  81. if (!empty($XMLDB->dbdirs)) {
  82. if (isset($XMLDB->dbdirs[$dirpath])) {
  83. $dbdir =& $XMLDB->dbdirs[$dirpath];
  84. if ($dbdir) {
  85. unset($dbdir->xml_changed);
  86. }
  87. }
  88. }
  89. // Get the edited dir and delete it completely
  90. if (!empty($XMLDB->editeddirs)) {
  91. if (isset($XMLDB->editeddirs[$dirpath])) {
  92. unset($XMLDB->editeddirs[$dirpath]);
  93. }
  94. }
  95. }
  96. // Launch postaction if exists (leave this here!)
  97. if ($this->getPostAction() && $result) {
  98. return $this->launch($this->getPostAction());
  99. }
  100. // Return ok if arrived here
  101. return $result;
  102. }
  103. }