Skip to content

Commit

Permalink
Context mapping error
Browse files Browse the repository at this point in the history
  • Loading branch information
WunderJacob committed Nov 20, 2024
1 parent 28fbee1 commit 7ef7c6d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 29 deletions.
12 changes: 5 additions & 7 deletions backup/moodle2/backup_adele_activity_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,17 @@ protected function define_my_steps() {
$this->add_step(new backup_adele_activity_structure_step('adele_structure', 'adele.xml'));
}

public function get_fileareas() {
return []; // Keine Dateien.
}

/**
* Encodes URLs to the activity instance for Moodle backup.
*
* @param string $content HTML content containing URLs to the activity instance.
* @return string Encoded content with URLs converted.
*/
public static function encode_content_links($content) {
global $CFG;

$base = preg_quote($CFG->wwwroot, '/');
$pattern = "/({$base}\/mod\/adele\/view\.php\?id=)([0-9]+)/";
$replacement = '$@ADELEVIEWBYID*$2@$';

return preg_replace($pattern, $replacement, $content);
return $content; // Keine Links zu encodieren.
}
}
9 changes: 8 additions & 1 deletion backup/moodle2/backup_adele_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,21 @@ class backup_adele_activity_structure_step extends backup_activity_structure_ste
* Backs up nested element.
*
* @return backup_nested_element
*
*/
protected function define_structure() {
// Define each element and its attributes.
$adele = new backup_nested_element('adele', ['id'], [
'course', 'name', 'learningpathid', 'view', 'userlist',
'participantslist', 'timecreated', 'timemodified', 'intro', 'introformat',
]);

// Define sources.
$adele->set_source_table('adele', ['id' => backup::VAR_ACTIVITYID]);

// Define file annotations (if there are files to back up).
$adele->annotate_files('mod_adele', 'intro', null);

// Return the root element (wrapped into the standard activity structure).
return $this->prepare_activity_structure($adele);
}
}
24 changes: 6 additions & 18 deletions backup/moodle2/restore_adele_activity_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,19 @@ protected function define_my_steps() {
}

/**
* Determines if this task uses the Moodle file API.
*
* @return array
* Defines steps for the restore process.
*/
public function get_fileareas() {
return ['intro'];
return null; // Keine Dateien.
}

/**
* Processes links encoded by the backup process.
* Decodes content links during restore.
*
* @param string $content Encoded content with placeholders for URLs.
* @return string Decoded content with URLs restored.
* @param string $content The content containing encoded links.
* @return string The content with links decoded.
*/
public static function decode_content_links($content) {
$pattern = '/\$@ADELEVIEWBYID\*([0-9]+)@\$/';
$replacement = '$@PLUGINFILE$/mod/adele/view.php?id=$1';

return preg_replace($pattern, $replacement, $content);
}

/**
* Returns the activity module's format version.
*/
public function after_restore() {
// Any additional processing after restoring can be added here.
return $content; // No specific decoding needed for this activity.
}
}
8 changes: 6 additions & 2 deletions backup/moodle2/restore_adele_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class restore_adele_activity_structure_step extends restore_activity_structure_s
protected function define_structure() {
$paths = [];
$paths[] = new restore_path_element('adele', '/activity/adele');

return $paths;
}

Expand All @@ -52,6 +51,11 @@ protected function process_adele($data) {

$data = (object)$data;
$data->course = $this->get_courseid();
$DB->insert_record('adele', $data);
$newitemid = $DB->insert_record('adele', $data);
$this->set_mapping('adele', $data->id, $newitemid);
}

protected function after_execute() {
// Keine weiteren Schritte erforderlich.
}
}
2 changes: 2 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ function adele_supports($feature) {
switch ($feature) {
case FEATURE_MOD_INTRO:
return true;
case FEATURE_BACKUP_MOODLE2:
return true;
default:
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

$plugin->component = 'mod_adele';
$plugin->release = '0.1.0';
$plugin->version = 2024101400;
$plugin->version = 2024101402;
$plugin->requires = 2022112800;
$plugin->maturity = MATURITY_ALPHA;
$plugin->dependencies = [
Expand Down

0 comments on commit 7ef7c6d

Please sign in to comment.