Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.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   * This file contains all the portfolio exception classes.
  19   *
  20   * @package core_portfolio
  21   * @copyright 2008 Penny Leach <penny@catalyst.net.nz>,  Martin Dougiamas
  22   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  /**
  28   * Top level portfolio exception.
  29   *
  30   * Sometimes caught and re-thrown as portfolio_export_exception
  31   * @see portfolio_export_exception
  32   *
  33   * @package core_portfolio
  34   * @category portfolio
  35   * @copyright 2008 Penny Leach <penny@catalyst.net.nz>
  36   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class portfolio_exception extends moodle_exception {}
  39  
  40  /**
  41   * Exception to throw during an export - will clean up session and tempdata
  42   *
  43   * @package core_portfolio
  44   * @category portfolio
  45   * @copyright 2008 Penny Leach <penny@catalyst.net.nz>
  46   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  47   */
  48  class portfolio_export_exception extends portfolio_exception {
  49  
  50      /**
  51       * Constructor.
  52       *
  53       * @param portfolio_exporter $exporter instance of portfolio_exporter (will handle null case)
  54       * @param string $errorcode language string key
  55       * @param string $module language string module (optional, defaults to moodle)
  56       * @param string $continue url to continue to (optional, defaults to wwwroot)
  57       * @param object $a language string data (optional, defaults to  null)
  58       */
  59      public function __construct($exporter, $errorcode, $module=null, $continue=null, $a=null) {
  60          global $CFG;
  61          // This static variable is necessary because sometimes the code below
  62          // which tries to obtain a continue link can cause one of these
  63          // exceptions to be thrown. This would create an infinite loop (until
  64          // PHP hits its stack limit). Using this static lets us make the
  65          // nested constructor finish immediately without attempting to call
  66          // methods that might fail.
  67          static $inconstructor = false;
  68  
  69          if (!$inconstructor && !empty($exporter) &&
  70                  $exporter instanceof portfolio_exporter) {
  71              $inconstructor = true;
  72              try {
  73                  if (empty($continue)) {
  74                      $caller = $exporter->get('caller');
  75                      if (!empty($caller) && $caller instanceof portfolio_caller_base) {
  76                          $continue = $exporter->get('caller')->get_return_url();
  77                      }
  78                  }
  79                  // this was previously only called if we were in cron,
  80                  // but I think if there's always an exception, we should clean up
  81                  // rather than force the user to resolve the export later.
  82                  $exporter->process_stage_cleanup();
  83              } catch(Exception $e) {
  84                  // Ooops, we had an exception trying to get caller
  85                  // information. Ignore it.
  86              }
  87              $inconstructor = false;
  88          }
  89          parent::__construct($errorcode, $module, $continue, $a);
  90      }
  91  }
  92  
  93  /**
  94   * Exception for callers to throw when they have a problem.
  95   *
  96   * Usually caught and rethrown as portfolio_export_exception
  97   * @see portfolio_export_exception
  98   *
  99   * @package core_portfolio
 100   * @category portfolio
 101   * @copyright 2008 Penny Leach <penny@catalyst.net.nz>
 102   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 103   */
 104  class portfolio_caller_exception extends portfolio_exception {}
 105  
 106  /**
 107   * Exception for portfolio plugins to throw when they have a problem.
 108   *
 109   * Usually caught and rethrown as portfolio_export_exception
 110   * @see portfolio_export_exception
 111   *
 112   * @package core_portfolio
 113   * @category portfolio
 114   * @copyright 2008 Penny Leach <penny@catalyst.net.nz>
 115   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 116   */
 117  class portfolio_plugin_exception extends portfolio_exception {}
 118  
 119  /**
 120   * Exception for interacting with the button class
 121   *
 122   * @package core_portfolio
 123   * @category portfolio
 124   * @copyright 2008 Penny Leach <penny@catalyst.net.nz>
 125   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 126   */
 127  class portfolio_button_exception extends portfolio_exception {}
 128  
 129  /**
 130   * Leap2a exception - for invalid api calls
 131   *
 132   * @package core_portfolio
 133   * @category portfolio
 134   * @copyright 2008 Penny Leach <penny@catalyst.net.nz>
 135   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 136   */
 137  class portfolio_format_leap2a_exception extends portfolio_exception {}