Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-27636 restore - add support for after_restore() to plugins. Credi…

…t goes to Mark Nielsen. Thanks!
  • Loading branch information...
commit c44299c172cc15c54bfe129d2edfd4724bc89314 1 parent 16b5541
Eloy Lafuente (stronk7) stronk7 authored
17 backup/moodle2/restore_plugin.class.php
@@ -81,6 +81,23 @@ public function launch_after_execute_methods() {
81 81 }
82 82
83 83 /**
  84 + * after_restore dispatcher for any restore_plugin class
  85 + *
  86 + * This method will dispatch execution to the corresponding
  87 + * after_restore_xxx() method when available, with xxx
  88 + * being the connection point of the instance, so plugin
  89 + * classes with multiple connection points will support
  90 + * multiple after_restore methods, one for each connection point
  91 + */
  92 + public function launch_after_restore_methods() {
  93 + // Check if the after_restore method exists and launch it
  94 + $afterrestore = 'after_restore_' . basename($this->connectionpoint->get_path());
  95 + if (method_exists($this, $afterrestore)) {
  96 + $this->$afterrestore();
  97 + }
  98 + }
  99 +
  100 + /**
84 101 * Returns one array with all the decode contents
85 102 * to be processed by the links decoder
86 103 *
37 backup/util/plan/restore_structure_step.class.php
@@ -361,6 +361,43 @@ protected function launch_after_execute_methods() {
361 361 }
362 362
363 363 /**
  364 + * Launch all the after_restore methods present in all the processing objects
  365 + *
  366 + * This method will launch all the after_restore methods that can be defined
  367 + * both in restore_plugin class
  368 + *
  369 + * For restore_plugin classes the name of the method to be executed will be
  370 + * "after_restore_" + connection point (as far as can be multiple connection
  371 + * points in the same class)
  372 + */
  373 + public function launch_after_restore_methods() {
  374 + $alreadylaunched = array(); // To avoid multiple executions
  375 + foreach ($this->pathelements as $pathelement) {
  376 + // Get the processing object
  377 + $pobject = $pathelement->get_processing_object();
  378 + // Skip null processors (child of grouped ones for sure)
  379 + if (is_null($pobject)) {
  380 + continue;
  381 + }
  382 + // Skip restore structure step processors (this)
  383 + if ($pobject instanceof restore_structure_step) {
  384 + continue;
  385 + }
  386 + // Skip already launched processing objects
  387 + if (in_array($pobject, $alreadylaunched, true)) {
  388 + continue;
  389 + }
  390 + // Add processing object to array of launched ones
  391 + $alreadylaunched[] = $pobject;
  392 + // If the processing object has support for
  393 + // launching after_restore methods, use it
  394 + if (method_exists($pobject, 'launch_after_restore_methods')) {
  395 + $pobject->launch_after_restore_methods();
  396 + }
  397 + }
  398 + }
  399 +
  400 + /**
364 401 * This method will be executed after the whole structure step have been processed
365 402 *
366 403 * After execution method for code needed to be executed after the whole structure
7 backup/util/plan/restore_task.class.php
@@ -100,6 +100,13 @@ public function get_old_system_contextid() {
100 100 * method if available
101 101 */
102 102 public function execute_after_restore() {
  103 + if ($this->executed) {
  104 + foreach ($this->steps as $step) {
  105 + if (method_exists($step, 'launch_after_restore_methods')) {
  106 + $step->launch_after_restore_methods();
  107 + }
  108 + }
  109 + }
103 110 if ($this->executed && method_exists($this, 'after_restore')) {
104 111 $this->after_restore();
105 112 }

0 comments on commit c44299c

Please sign in to comment.
Something went wrong with that request. Please try again.