MDL-27376 MDL-27377 MDL-27378 Backup converters refactoring - still work in progress
[moodle.git] / backup / converter / moodle1 / lib.php
CommitLineData
1e2c7351
DM
1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * Provides classes used by the moodle1 converter
20 *
21 * @package backup-convert
22 * @subpackage moodle1
23 * @copyright 2011 Mark Nielsen <mark@moodlerooms.com>
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 */
26
27defined('MOODLE_INTERNAL') || die();
28
29require_once($CFG->dirroot . '/backup/converter/convertlib.php');
30require_once($CFG->dirroot . '/backup/util/xml/parser/progressive_parser.class.php');
31require_once($CFG->dirroot . '/backup/util/xml/parser/processors/grouped_parser_processor.class.php');
a5fe5912
DM
32require_once($CFG->dirroot . '/backup/util/dbops/backup_dbops.class.php');
33require_once($CFG->dirroot . '/backup/util/dbops/backup_controller_dbops.class.php');
34require_once($CFG->dirroot . '/backup/util/dbops/restore_dbops.class.php');
1e2c7351
DM
35require_once(dirname(__FILE__) . '/handlerlib.php');
36
37/**
38 * Converter of Moodle 1.9 backup into Moodle 2.x format
39 */
40class moodle1_converter extends base_converter {
41
42 /** @var progressive_parser moodle.xml file parser */
43 protected $xmlparser;
44
45 /** @var moodle1_parser_processor */
46 protected $xmlprocessor;
47
48 /** @var array of {@link convert_path} to process */
49 protected $pathelements = array();
50
51 /** @var string the current module being processed */
52 protected $currentmod = '';
53
54 /** @var string the current block being processed */
55 protected $currentblock = '';
56
57 /** @var string path currently locking processing of children */
58 protected $pathlock;
59
60 /**
61 * Instructs the dispatcher to ignore all children below path processor returning it
62 */
63 const SKIP_ALL_CHILDREN = -991399;
64
65 /**
66 * Detects the Moodle 1.9 format of the backup directory
67 *
68 * @param string $tempdir the name of the backup directory
69 * @return null|string backup::FORMAT_MOODLE1 if the Moodle 1.9 is detected, null otherwise
70 */
71 public static function detect_format($tempdir) {
72 global $CFG;
73
74 $filepath = $CFG->dataroot . '/temp/backup/' . $tempdir . '/moodle.xml';
75 if (file_exists($filepath)) {
76 // looks promising, lets load some information
77 $handle = fopen($filepath, 'r');
78 $first_chars = fread($handle, 200);
79 fclose($handle);
80
81 // check if it has the required strings
82 if (strpos($first_chars,'<?xml version="1.0" encoding="UTF-8"?>') !== false and
83 strpos($first_chars,'<MOODLE_BACKUP>') !== false and
84 strpos($first_chars,'<INFO>') !== false) {
85
86 return backup::FORMAT_MOODLE1;
87 }
88 }
89
90 return null;
91 }
92
93 /**
94 * Initialize the instance if needed, called by the constructor
95 *
96 * Here we create objects we need before the execution.
97 */
98 protected function init() {
99
100 // ask your mother first before going out playing with toys
101 parent::init();
102
103 // good boy, prepare XML parser and processor
104 $this->xmlparser = new progressive_parser();
105 $this->xmlparser->set_file($this->get_tempdir_path() . '/moodle.xml');
106 $this->xmlprocessor = new moodle1_parser_processor($this);
107 $this->xmlparser->set_processor($this->xmlprocessor);
108
109 // make sure that MOD and BLOCK paths are visited
110 $this->xmlprocessor->add_path('/MOODLE_BACKUP/COURSE/MODULES/MOD');
111 $this->xmlprocessor->add_path('/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK');
112
113 // register the conversion handlers
114 foreach (moodle1_handlers_factory::get_handlers($this) as $handler) {
1e2c7351
DM
115 $this->register_handler($handler, $handler->get_paths());
116 }
117 }
118
119 /**
120 * Converts the contents of the tempdir into the target format in the workdir
121 */
122 protected function execute() {
123 $this->xmlparser->process();
124 }
125
126 /**
127 * Register a handler for the given path elements
128 */
129 protected function register_handler(moodle1_handler $handler, array $elements) {
130
131 // first iteration, push them to new array, indexed by name
132 // to detect duplicates in names or paths
133 $names = array();
134 $paths = array();
135 foreach($elements as $element) {
136 if (!$element instanceof convert_path) {
137 throw new convert_exception('path_element_wrong_class', get_class($element));
138 }
139 if (array_key_exists($element->get_name(), $names)) {
140 throw new convert_exception('path_element_name_alreadyexists', $element->get_name());
141 }
142 if (array_key_exists($element->get_path(), $paths)) {
143 throw new convert_exception('path_element_path_alreadyexists', $element->get_path());
144 }
145 $names[$element->get_name()] = true;
146 $paths[$element->get_path()] = $element;
147 }
148
149 // now, for each element not having a processing object yet, assign the handler
150 // if the element is not a memeber of a group
151 foreach($paths as $key => $element) {
152 if (is_null($element->get_processing_object()) and !$this->grouped_parent_exists($element, $paths)) {
153 $paths[$key]->set_processing_object($handler);
154 }
155 // add the element path to the processor
156 $this->xmlprocessor->add_path($element->get_path(), $element->is_grouped());
157 }
158
159 // done, store the paths (duplicates by path are discarded)
160 $this->pathelements = array_merge($this->pathelements, $paths);
161
162 // remove the injected plugin name element from the MOD and BLOCK paths
163 // and register such collapsed path, too
164 foreach ($elements as $element) {
165 $path = $element->get_path();
166 $path = preg_replace('/^\/MOODLE_BACKUP\/COURSE\/MODULES\/MOD\/(\w+)\//', '/MOODLE_BACKUP/COURSE/MODULES/MOD/', $path);
167 $path = preg_replace('/^\/MOODLE_BACKUP\/COURSE\/BLOCKS\/BLOCK\/(\w+)\//', '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK/', $path);
168 if (!empty($path) and $path != $element->get_path()) {
169 $this->xmlprocessor->add_path($path, false);
170 }
171 }
172 }
173
174 /**
175 * Helper method used by {@link self::register_handler()}
176 *
177 * @param convert_path $pelement path element
178 * @param array of convert_path instances
179 * @return bool true if grouped parent was found, false otherwise
180 */
181 protected function grouped_parent_exists($pelement, $elements) {
182
183 foreach ($elements as $element) {
184 if ($pelement->get_path() == $element->get_path()) {
185 // don't compare against itself
186 continue;
187 }
188 // if the element is grouped and it is a parent of pelement, return true
189 if ($element->is_grouped() and strpos($pelement->get_path() . '/', $element->get_path()) === 0) {
190 return true;
191 }
192 }
193
194 // no grouped parent found
195 return false;
196 }
197
198 /**
199 * Process the data obtained from the XML parser processor
200 *
201 * This methods receives one chunk of information from the XML parser
202 * processor and dispatches it, following the naming rules.
203 * We are expanding the modules and blocks paths here to include the plugin's name.
204 *
205 * @param array $data
206 */
207 public function process_chunk($data) {
208
209 $path = $data['path'];
210
211 // expand the MOD paths so that they contain the module name
212 if ($path === '/MOODLE_BACKUP/COURSE/MODULES/MOD') {
213 $this->currentmod = strtoupper($data['tags']['MODTYPE']);
214 $path = '/MOODLE_BACKUP/COURSE/MODULES/MOD/' . $this->currentmod;
215
216 } else if (strpos($path, '/MOODLE_BACKUP/COURSE/MODULES/MOD') === 0) {
217 $path = str_replace('/MOODLE_BACKUP/COURSE/MODULES/MOD', '/MOODLE_BACKUP/COURSE/MODULES/MOD/' . $this->currentmod, $path);
218 }
219
220 // expand the BLOCK paths so that they contain the module name
221 if ($path === '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK') {
222 $this->currentblock = strtoupper($data['tags']['NAME']);
223 $path = '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK/' . $this->currentblock;
224
225 } else if (strpos($path, '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK') === 0) {
226 $path = str_replace('/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK', '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK/' . $this->currentmod, $path);
227 }
228
229 if ($path !== $data['path']) {
230 if (!array_key_exists($path, $this->pathelements)) {
231 // no handler registered for the transformed MOD or BLOCK path
232 // todo add this event to the convert log instead of debugging
233 //debugging('No handler registered for the path ' . $path);
234 return;
235
236 } else {
237 // pretend as if the original $data contained the tranformed path
238 $data['path'] = $path;
239 }
240 }
241
242 if (!array_key_exists($data['path'], $this->pathelements)) {
243 // path added to the processor without the handler
244 throw new convert_exception('missing_path_handler', $data['path']);
245 }
246
247 $element = $this->pathelements[$data['path']];
248 $object = $element->get_processing_object();
249 $method = $element->get_processing_method();
250 $rdata = null; // data returned by the processing method, if any
251
252 if (empty($object)) {
253 throw new convert_exception('missing_processing_object', $object);
254 }
255
256 // release the lock if we aren't anymore within children of it
257 if (!is_null($this->pathlock) and strpos($data['path'], $this->pathlock) === false) {
258 $this->pathlock = null;
259 }
260
261 // if the path is not locked, apply the element's recipes and dispatch
262 // the cooked tags to the processing method
263 if (is_null($this->pathlock)) {
a5fe5912
DM
264 $cooked = $element->apply_recipes($data['tags']);
265 $rdata = $object->$method($cooked, $data['tags']);
1e2c7351
DM
266 }
267
268 // if the dispatched method returned SKIP_ALL_CHILDREN, remember the current path
269 // and lock it so that its children are not dispatched
270 if ($rdata === self::SKIP_ALL_CHILDREN) {
271 // check we haven't any previous lock
272 if (!is_null($this->pathlock)) {
273 throw new convert_exception('already_locked_path', $data['path']);
274 }
275 // set the lock - nothing below the current path will be dispatched
276 $this->pathlock = $data['path'] . '/';
277
278 // if the method has returned any info, set element data to it
279 } else if (!is_null($rdata)) {
280 $element->set_data($rdata);
281
282 // use just the cooked parsed data otherwise
283 } else {
284 $element->set_data($data);
285 }
286 }
287
288 /**
289 * Executes operations required at the start of a watched path
290 *
291 * Note that this is called before the MOD and BLOCK paths are expanded
a5fe5912
DM
292 * so the current plugin is not known yet. Also note that this is
293 * triggered before the previous path is actually dispatched.
1e2c7351 294 *
1e2c7351
DM
295 * @param string $path in the original file
296 */
297 public function path_start_reached($path) {
a5fe5912
DM
298
299 if (empty($this->pathelements[$path])) {
300 return;
301 }
302
303 $element = $this->pathelements[$path];
304 $pobject = $element->get_processing_object();
305 $method = 'on_' . $element->get_name() . '_start';
306
307 if (method_exists($pobject, $method)) {
308 $pobject->$method();
309 }
1e2c7351
DM
310 }
311
312 /**
313 * Executes operations required at the end of a watched path
314 *
1e2c7351
DM
315 * @param string $path in the original file
316 */
317 public function path_end_reached($path) {
a5fe5912
DM
318
319 // expand the MOD paths so that they contain the current module name
320 if ($path === '/MOODLE_BACKUP/COURSE/MODULES/MOD') {
321 $path = '/MOODLE_BACKUP/COURSE/MODULES/MOD/' . $this->currentmod;
322
323 } else if (strpos($path, '/MOODLE_BACKUP/COURSE/MODULES/MOD') === 0) {
324 $path = str_replace('/MOODLE_BACKUP/COURSE/MODULES/MOD', '/MOODLE_BACKUP/COURSE/MODULES/MOD/' . $this->currentmod, $path);
325 }
326
327 // expand the BLOCK paths so that they contain the module name
328 if ($path === '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK') {
329 $path = '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK/' . $this->currentblock;
330
331 } else if (strpos($path, '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK') === 0) {
332 $path = str_replace('/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK', '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK/' . $this->currentmod, $path);
333 }
334
335 if (empty($this->pathelements[$path])) {
336 return;
337 }
338
339 $element = $this->pathelements[$path];
340 $pobject = $element->get_processing_object();
341 $method = 'on_' . $element->get_name() . '_end';
342
343 if (method_exists($pobject, $method)) {
344 $pobject->$method();
345 }
346 }
347
348 /**
349 * Creates the backup_ids_temp table
350 */
351 public function create_backup_ids_temp_table() {
352 backup_controller_dbops::create_backup_ids_temp_table($this->get_id());
353 }
354
355 /**
356 * Drops the backup_ids_temp table
357 */
358 public function drop_backup_ids_temp_table() {
359 backup_controller_dbops::drop_backup_ids_temp_table($this->get_id());
360 }
361
362 /**
363 * Stores a record in the temporary backup_ids table
364 *
365 * @param string $itemname
366 * @param int $itemid
367 * @param int $newitemid
368 * @param int $parentitemid
369 * @param mixed $info
370 * @return void
371 */
372 public function set_backup_ids_record($itemname, $itemid, $newitemid = 0, $parentitemid = null, $info = null) {
373 restore_dbops::set_backup_ids_record($this->get_id(), $itemname, $itemid, $newitemid, $parentitemid, $info);
374 }
375
376 /**
377 * Restores a previously saved record from backup_ids temporary table
378 *
379 * @param string $itemname
380 * @param int $itemid
381 * @return stdClass
382 */
383 public function get_backup_ids_record($itemname, $itemid) {
384 return restore_dbops::get_backup_ids_record($this->get_id(), $itemname, $itemid);
1e2c7351 385 }
a5fe5912 386
1e2c7351
DM
387}
388
389
390/**
391 * XML parser processor
392 */
393class moodle1_parser_processor extends grouped_parser_processor {
394
395 /** @var moodle1_converter */
396 protected $converter;
397
398 public function __construct(moodle1_converter $converter) {
399 $this->converter = $converter;
400 parent::__construct();
401 }
402
403 /**
404 * Provide NULL and legacy file.php uses decoding
405 */
406 public function process_cdata($cdata) {
407 global $CFG;
408
409 if ($cdata === '$@NULL@$') { // Some cases we know we can skip complete processing
410 return null;
411 } else if ($cdata === '') {
412 return '';
413 } else if (is_numeric($cdata)) {
414 return $cdata;
415 } else if (strlen($cdata) < 32) { // Impossible to have one link in 32cc
416 return $cdata; // (http://10.0.0.1/file.php/1/1.jpg, http://10.0.0.1/mod/url/view.php?id=)
417 } else if (strpos($cdata, '$@FILEPHP@$') === false) { // No $@FILEPHP@$, nothing to convert
418 return $cdata;
419 }
420 // Decode file.php calls
421 $search = array ("$@FILEPHP@$");
422 $replace = array(get_file_url($this->courseid));
423 $result = str_replace($search, $replace, $cdata);
424 // Now $@SLASH@$ and $@FORCEDOWNLOAD@$ MDL-18799
425 $search = array('$@SLASH@$', '$@FORCEDOWNLOAD@$');
426 if ($CFG->slasharguments) {
427 $replace = array('/', '?forcedownload=1');
428 } else {
429 $replace = array('%2F', '&amp;forcedownload=1');
430 }
431 return str_replace($search, $replace, $result);
432 }
433
434 /**
435 * Override this method so we'll be able to skip
436 * dispatching some well-known chunks, like the
437 * ones being 100% part of subplugins stuff. Useful
438 * for allowing development without having all the
439 * possible restore subplugins defined
440 */
441 protected function postprocess_chunk($data) {
442
443 // Iterate over all the data tags, if any of them is
444 // not 'subplugin_XXXX' or has value, then it's a valid chunk,
445 // pass it to standard (parent) processing of chunks.
446 foreach ($data['tags'] as $key => $value) {
447 if (trim($value) !== '' || strpos($key, 'subplugin_') !== 0) {
448 parent::postprocess_chunk($data);
449 return;
450 }
451 }
452 // Arrived here, all the tags correspond to sublplugins and are empty,
453 // skip the chunk, and debug_developer notice
454 $this->chunks--; // not counted
455 debugging('Missing support on restore for ' . clean_param($data['path'], PARAM_PATH) .
456 ' subplugin (' . implode(', ', array_keys($data['tags'])) .')', DEBUG_DEVELOPER);
457 }
458
459 /**
460 * Dispatches the data chunk to the converter class
461 *
462 * @param array $data the chunk of parsed data
463 */
464 protected function dispatch_chunk($data) {
465 $this->converter->process_chunk($data);
466 }
467
468 /**
469 * Informs the converter at the start of a watched path
470 *
471 * @param string $path
472 */
473 protected function notify_path_start($path) {
474 $this->converter->path_start_reached($path);
475 }
476
477 /**
478 * Informs the converter at the end of a watched path
479 *
480 * @param string $path
481 */
482 protected function notify_path_end($path) {
483 $this->converter->path_end_reached($path);
484 }
485}
486
487
488/**
489 * Class representing a path to be converted from XML file
490 *
491 * This was created as a copy of {@link restore_path_element} and should be refactored
492 * probably.
493 */
494class convert_path {
495
496 /** @var string name of the element */
497 protected $name;
498
499 /** @var string path within the XML file this element will handle */
500 protected $path;
501
502 /** @var bool flag to define if this element will get child ones grouped or no */
503 protected $grouped;
504
505 /** @var object object instance in charge of processing this element. */
506 protected $pobject = null;
507
508 /** @var string the name of the processing method */
509 protected $pmethod = null;
510
511 /** @var mixed last data read for this element or returned data by processing method */
512 protected $data = null;
513
a5fe5912
DM
514 /** @var array of deprecated fields that are dropped */
515 protected $dropfields = array();
1e2c7351
DM
516
517 /** @var array of fields renaming */
518 protected $renamefields = array();
519
520 /** @var array of new fields to add and their initial values */
521 protected $newfields = array();
522
523 /**
524 * Constructor
525 *
526 * @param string $name name of the element
527 * @param string $path path of the element
528 * @param array $recipe basic description of the structure conversion
529 * @param bool $grouped to gather information in grouped mode or no
530 */
531 public function __construct($name, $path, array $recipe = array(), $grouped = false) {
532
533 $this->validate_name($name);
534
535 $this->name = $name;
536 $this->path = $path;
537 $this->grouped = $grouped;
538
539 // set the default processing method name
540 $this->set_processing_method('process_' . $name);
541
a5fe5912
DM
542 if (isset($recipe['dropfields']) and is_array($recipe['dropfields'])) {
543 $this->set_dropped_fields($recipe['dropfields']);
1e2c7351
DM
544 }
545 if (isset($recipe['renamefields']) and is_array($recipe['renamefields'])) {
546 $this->set_renamed_fields($recipe['renamefields']);
547 }
548 if (isset($recipe['newfields']) and is_array($recipe['newfields'])) {
549 $this->set_new_fields($recipe['newfields']);
550 }
551 }
552
553 /**
554 * Validates and sets the given processing object
555 *
556 * @param object $pobject processing object, must provide a method to be called
557 */
558 public function set_processing_object($pobject) {
559 $this->validate_pobject($pobject);
560 $this->pobject = $pobject;
561 }
562
563 /**
564 * Sets the name of the processing method
565 *
566 * @param string $pmethod
567 */
568 public function set_processing_method($pmethod) {
569 $this->pmethod = $pmethod;
570 }
571
572 /**
573 * Sets the element data
574 *
575 * @param mixed
576 */
577 public function set_data($data) {
578 $this->data = $data;
579 }
580
581 /**
a5fe5912 582 * Sets the list of deprecated fields to drop
1e2c7351
DM
583 *
584 * @param array $fields
585 */
a5fe5912
DM
586 public function set_dropped_fields(array $fields) {
587 $this->dropfields = $fields;
1e2c7351
DM
588 }
589
590 /**
591 * Sets the required new names of the current fields
592 *
593 * @param array $fields (string)$currentname => (string)$newname
594 */
595 public function set_renamed_fields(array $fields) {
596 $this->renamefields = $fields;
597 }
598
599 /**
600 * Sets the new fields and their values
601 *
602 * @param array $fields (string)$field => (mixed)value
603 */
604 public function set_new_fields(array $fields) {
605 $this->newfields = $fields;
606 }
607
608 /**
609 * Cooks the parsed tags data by applying known recipes
610 *
611 * Recipes are used for common trivial operations like adding new fields
612 * or renaming fields. The handler's processing method receives cooked
613 * data.
614 *
615 * @param array $data the contents of the element
616 * @return array
617 */
618 public function apply_recipes(array $data) {
619
620 $cooked = array();
621
622 foreach ($data as $name => $value) {
623 // lower case rocks!
624 $name = strtolower($name);
625
a5fe5912
DM
626 // drop legacy fields
627 if (in_array($name, $this->dropfields)) {
628 continue;
629 }
630
1e2c7351
DM
631 // fields renaming
632 if (array_key_exists($name, $this->renamefields)) {
633 $name = $this->renamefields[$name];
634 }
635
636 $cooked[$name] = $value;
637 }
638
639 // adding new fields
640 foreach ($this->newfields as $name => $value) {
641 $cooked[$name] = $value;
642 }
643
644 return $cooked;
645 }
646
647 /**
648 * @return string the element given name
649 */
650 public function get_name() {
651 return $this->name;
652 }
653
654 /**
655 * @return string the path to the element
656 */
657 public function get_path() {
658 return $this->path;
659 }
660
661 /**
662 * @return bool flag to define if this element will get child ones grouped or no
663 */
664 public function is_grouped() {
665 return $this->grouped;
666 }
667
668 /**
669 * @return object the processing object providing the processing method
670 */
671 public function get_processing_object() {
672 return $this->pobject;
673 }
674
675 /**
676 * @return string the name of the method to call to process the element
677 */
678 public function get_processing_method() {
679 return $this->pmethod;
680 }
681
682 /**
683 * @return mixed the element data
684 */
685 public function get_data() {
686 return $this->data;
687 }
688
689
690 /// end of public API //////////////////////////////////////////////////////
691
692 /**
693 * Makes sure the given name is a valid element name
694 *
695 * Note it may look as if we used exceptions for code flow control here. That's not the case
696 * as we actually validate the code, not the user data. And the code is supposed to be
697 * correct.
698 *
699 * @param string @name the element given name
700 * @throws convert_path_exception
701 * @return void
702 */
703 protected function validate_name($name) {
704 // Validate various name constraints, throwing exception if needed
705 if (empty($name)) {
706 throw new convert_path_exception('convert_path_emptyname', $name);
707 }
708 if (preg_replace('/\s/', '', $name) != $name) {
709 throw new convert_path_exception('convert_path_whitespace', $name);
710 }
711 if (preg_replace('/[^\x30-\x39\x41-\x5a\x5f\x61-\x7a]/', '', $name) != $name) {
712 throw new convert_path_exception('convert_path_notasciiname', $name);
713 }
714 }
715
716 /**
717 * Makes sure that the given object is a valid processing object
718 *
719 * The processing object must be an object providing the element's processing method.
720 * Note it may look as if we used exceptions for code flow control here. That's not the case
721 * as we actually validate the code, not the user data. And the code is supposed to be
722 * correct.
723 *
724 * @param object $pobject
725 * @throws convert_path_exception
726 * @return void
727 */
728 protected function validate_pobject($pobject) {
729 if (!is_object($pobject)) {
730 throw new convert_path_exception('convert_path_no_object', $pobject);
731 }
732 if (!method_exists($pobject, $this->get_processing_method())) {
733 throw new convert_path_exception('convert_path_missingmethod', $this->get_processing_method());
734 }
735 }
736}
737
738
739/**
740 * Exception being thrown by {@link convert_path} methods
741 */
742class convert_path_exception extends moodle_exception {
743
744 /**
745 * Constructor
746 *
747 * @param string $errorcode key for the corresponding error string
748 * @param mixed $a extra words and phrases that might be required by the error string
749 * @param string $debuginfo optional debugging information
750 */
751 public function __construct($errorcode, $a = null, $debuginfo = null) {
752 parent::__construct($errorcode, '', '', $a, $debuginfo);
753 }
754}