Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
   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   * File handling related exceptions.
  19   *
  20   * @package   core_files
  21   * @copyright 2008 Petr Skoda (http://skodak.org)
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  /**
  28   * Basic file related exception class.
  29   *
  30   * @package   core_files
  31   * @category  files
  32   * @copyright 2008 Petr Skoda (http://skodak.org)
  33   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  34   */
  35  class file_exception extends moodle_exception {
  36      /**
  37       * Constructor
  38       *
  39       * @param string $errorcode error code
  40       * @param stdClass $a Extra words and phrases that might be required in the error string
  41       * @param string $debuginfo optional debugging information
  42       */
  43      function __construct($errorcode, $a=NULL, $debuginfo = NULL) {
  44          parent::__construct($errorcode, '', '', $a, $debuginfo);
  45      }
  46  }
  47  
  48  /**
  49   * Cannot create file exception.
  50   *
  51   * @package   core_files
  52   * @category  files
  53   * @copyright 2008 Petr Skoda (http://skodak.org)
  54   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  55   */
  56  class stored_file_creation_exception extends file_exception {
  57      /**
  58       * Constructor.
  59       *
  60       * @param int $contextid context ID
  61       * @param string $component component
  62       * @param string $filearea file area
  63       * @param int $itemid item ID
  64       * @param string $filepath file path
  65       * @param string $filename file name
  66       * @param string $debuginfo extra debug info
  67       */
  68      function __construct($contextid, $component, $filearea, $itemid, $filepath, $filename, $debuginfo = null) {
  69          $a = new stdClass();
  70          $a->contextid = $contextid;
  71          $a->component = $component;
  72          $a->filearea  = $filearea;
  73          $a->itemid    = $itemid;
  74          $a->filepath  = $filepath;
  75          $a->filename  = $filename;
  76          parent::__construct('storedfilenotcreated', $a, $debuginfo);
  77      }
  78  }
  79  
  80  /**
  81   * No file access exception.
  82   *
  83   * @package   core_files
  84   * @category  files
  85   * @copyright 2008 Petr Skoda (http://skodak.org)
  86   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  87   */
  88  class file_access_exception extends file_exception {
  89      /**
  90       * Constructor.
  91       *
  92       * @param string $debuginfo extra debug info
  93       */
  94      public function __construct($debuginfo = null) {
  95          parent::__construct('nopermissions', null, $debuginfo);
  96      }
  97  }
  98  
  99  /**
 100   * Hash file content problem exception.
 101   *
 102   * @package   core_files
 103   * @category  files
 104   * @copyright 2008 Petr Skoda (http://skodak.org)
 105   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 106   */
 107  class file_pool_content_exception extends file_exception {
 108      /**
 109       * Constructor.
 110       *
 111       * @param string $contenthash content hash
 112       * @param string $debuginfo extra debug info
 113       */
 114      public function __construct($contenthash, $debuginfo = null) {
 115          parent::__construct('hashpoolproblem', $contenthash, $debuginfo);
 116      }
 117  }
 118  
 119  
 120  /**
 121   * Problem with records in the {files_reference} table.
 122   *
 123   * @package   core_files
 124   * @category  files
 125   * @copyright 2012 David Mudrak <david@moodle.com>
 126   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 127   */
 128  class file_reference_exception extends file_exception {
 129      /**
 130       * Constructor.
 131       *
 132       * @param int $repositoryid the id of the repository that provides the referenced file
 133       * @param string $reference the information for the repository to locate the file
 134       * @param int|null $referencefileid the id of the record in {files_reference} if known
 135       * @param int|null $fileid the id of the referrer's record in {files} if known
 136       * @param string|null $debuginfo extra debug info
 137       */
 138      function __construct($repositoryid, $reference, $referencefileid=null, $fileid=null, $debuginfo=null) {
 139          $a = new stdClass();
 140          $a->repositoryid = $repositoryid;
 141          $a->reference = $reference;
 142          $a->referencefileid = $referencefileid;
 143          $a->fileid = $fileid;
 144          parent::__construct('filereferenceproblem', $a, $debuginfo);
 145      }
 146  }