/public_html/admin/xmldb/actions/get_db_directories/get_db_directories.class.php

https://github.com/hatone/moodle · PHP · 95 lines · 30 code · 16 blank · 49 comment · 2 complexity · c1396358e61fa94ac6c6fb2cc98f9023 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 xmldb-editor
  18. * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  19. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  20. */
  21. /**
  22. * This class will will check all the db directories existing under the
  23. * current Moodle installation, sending them to the SESSION->dbdirs array
  24. *
  25. * @package xmldb-editor
  26. * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  27. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  28. */
  29. class get_db_directories extends XMLDBAction {
  30. /**
  31. * Init method, every subclass will have its own
  32. */
  33. function init() {
  34. parent::init();
  35. /// Set own core attributes
  36. $this->can_subaction = ACTION_NONE;
  37. //$this->can_subaction = ACTION_HAVE_SUBACTIONS;
  38. /// Set own custom attributes
  39. $this->sesskey_protected = false; // This action doesn't need sesskey protection
  40. /// Get needed strings
  41. $this->loadStrings(array(
  42. /// 'key' => 'module',
  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. function invoke() {
  51. parent::invoke();
  52. $result = true;
  53. /// Set own core attributes
  54. $this->does_generate = ACTION_NONE;
  55. //$this->does_generate = ACTION_GENERATE_HTML;
  56. /// These are always here
  57. global $CFG, $XMLDB;
  58. /// Do the job, setting $result as needed
  59. /// Lets go to add all the db directories available inside Moodle
  60. /// Create the array if it doesn't exists
  61. if (!isset($XMLDB->dbdirs)) {
  62. $XMLDB->dbdirs = array();
  63. }
  64. /// get list of all dirs and create objects with status
  65. $db_directories = get_db_directories();
  66. foreach ($db_directories as $path) {
  67. $dbdir = new stdClass;
  68. $dbdir->path = $path;
  69. if (!isset($XMLDB->dbdirs[$dbdir->path])) {
  70. $XMLDB->dbdirs[$dbdir->path] = $dbdir;
  71. }
  72. $XMLDB->dbdirs[$dbdir->path]->path_exists = file_exists($dbdir->path); //Update status
  73. }
  74. /// Sort by key
  75. ksort($XMLDB->dbdirs);
  76. /// Return ok if arrived here
  77. return true;
  78. }
  79. }