MDL-37429 zipping improvements
[moodle.git] / lib / filestorage / file_exceptions.php
CommitLineData
33488ad6 1<?php
33488ad6 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 *
d2b7803e
DC
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
33488ad6 23 */
172dd12c 24
64f93798
PS
25defined('MOODLE_INTERNAL') || die();
26
172dd12c 27/**
01b4040a 28 * Basic file related exception class.
64f93798 29 *
d2b7803e
DC
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
172dd12c 34 */
35class file_exception extends moodle_exception {
d2b7803e
DC
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 */
64f93798 43 function __construct($errorcode, $a=NULL, $debuginfo = NULL) {
172dd12c 44 parent::__construct($errorcode, '', '', $a, $debuginfo);
45 }
46}
47
48/**
01b4040a 49 * Can not create file exception.
64f93798 50 *
d2b7803e
DC
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
172dd12c 55 */
56class stored_file_creation_exception extends file_exception {
d2b7803e 57 /**
01b4040a 58 * Constructor.
4ab641ee 59 *
d2b7803e
DC
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 */
67233725 68 function __construct($contextid, $component, $filearea, $itemid, $filepath, $filename, $debuginfo = null) {
ac6f1a82 69 $a = new stdClass();
172dd12c 70 $a->contextid = $contextid;
64f93798 71 $a->component = $component;
172dd12c 72 $a->filearea = $filearea;
73 $a->itemid = $itemid;
74 $a->filepath = $filepath;
75 $a->filename = $filename;
145a0a31 76 parent::__construct('storedfilenotcreated', $a, $debuginfo);
172dd12c 77 }
78}
79
80/**
4c8725be 81 * No file access exception.
64f93798 82 *
d2b7803e
DC
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
172dd12c 87 */
88class file_access_exception extends file_exception {
d2b7803e 89 /**
01b4040a 90 * Constructor.
d2b7803e
DC
91 *
92 * @param string $debuginfo extra debug info
93 */
67233725
DC
94 public function __construct($debuginfo = null) {
95 parent::__construct('nopermissions', null, $debuginfo);
172dd12c 96 }
97}
98
99/**
33488ad6 100 * Hash file content problem exception.
64f93798 101 *
d2b7803e
DC
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
172dd12c 106 */
107class file_pool_content_exception extends file_exception {
d2b7803e 108 /**
01b4040a 109 * Constructor.
d2b7803e
DC
110 *
111 * @param string $contenthash content hash
112 * @param string $debuginfo extra debug info
113 */
67233725 114 public function __construct($contenthash, $debuginfo = null) {
172dd12c 115 parent::__construct('hashpoolproblem', $contenthash, $debuginfo);
116 }
117}
67233725 118
e28fbdba 119
67233725 120/**
01b4040a 121 * Problem with records in the {files_reference} table.
67233725
DC
122 *
123 * @package core_files
e28fbdba
DM
124 * @catehory files
125 * @copyright 2012 David Mudrak <david@moodle.com>
67233725
DC
126 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
127 */
e28fbdba 128class file_reference_exception extends file_exception {
67233725 129 /**
01b4040a 130 * Constructor.
67233725 131 *
e28fbdba
DM
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
67233725 137 */
e28fbdba
DM
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);
67233725
DC
145 }
146}