Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is 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   * Testable content plugin class.
  19   *
  20   * @package    core_contentbank
  21   * @category   test
  22   * @copyright  2020 Amaia Anabitarte <amaia@moodle.com>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  namespace contenttype_testable;
  27  
  28  use file_exception;
  29  use stored_file;
  30  
  31  /**
  32   * Testable content plugin class.
  33   *
  34   * @package    core_contentbank
  35   * @copyright  2020 Amaia Anabitarte <amaia@moodle.com>
  36   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class content extends \core_contentbank\content {
  39  
  40      /**
  41       * Import a file as a valid content.
  42       *
  43       * This method will thow an error if the filename is "error.*"
  44       *
  45       * @param stored_file $file File to store in the content file area.
  46       * @return stored_file|null the stored content file or null if the file is discarted.
  47       * @throws file_exception if the filename contains the word "error"
  48       */
  49      public function import_file(stored_file $file): ?stored_file {
  50          $filename = $file->get_filename();
  51          if (strrpos($filename, 'error') !== false) {
  52              throw new file_exception('yourerrorthanks', 'contenttype_test');
  53          }
  54          return parent::import_file($file);
  55      }
  56  }