Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MBS-8701: Fix version number in upgrade step #92

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions amd/src/placestore.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let placestore = {
version: 2023080201,
version: 2024012601,
id: 0,
places: [],
paths: [],
Expand Down Expand Up @@ -36,7 +36,7 @@ let placestore = {
// eslint-disable-next-line no-empty
} catch { }
// Update version (only relevant if learning map is saved)
this.version = 2023080201;
this.version = 2024012601;
},
/**
* Returns placestore as a JSON string ()
Expand Down
4 changes: 2 additions & 2 deletions backup/moodle2/restore_learningmap_activity_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ public function after_restore(): void {
$item->intro = str_replace('learningmap-svgmap-' . $oldmapid, 'learningmap-svgmap-' . $newmapid, $item->intro);
$placestore->mapid = $newmapid;

if (!isset($placestore->version) || $placestore->version < 2023080201) {
$placestore->version = 2023080201;
if (!isset($placestore->version) || $placestore->version < 2024012601) {
$placestore->version = 2024012601;
// Needs 1 as default value (otherwise all place strokes would be hidden).
if (!isset($placestore->strokeopacity)) {
$placestore->strokeopacity = 1;
Expand Down
6 changes: 3 additions & 3 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ function xmldb_learningmap_upgrade($oldversion) {
global $DB;
$dbman = $DB->get_manager();

if ($oldversion < 2023080201) {
if ($oldversion < 2024012601) {
$entries = $DB->get_records('learningmap', []);
if ($entries) {
foreach ($entries as $entry) {
$placestore = json_decode($entry->placestore, true);
$placestore['version'] = 2023080201;
$placestore['version'] = 2024012601;
// Needs 1 as default value (otherwise all place strokes would be hidden).
if (!isset($placestore['strokeopacity'])) {
$placestore['strokeopacity'] = 1;
Expand All @@ -64,7 +64,7 @@ function xmldb_learningmap_upgrade($oldversion) {
$dbman->add_index($table, $index);
}

upgrade_mod_savepoint(true, 2023080201, 'learningmap');
upgrade_mod_savepoint(true, 2024012601, 'learningmap');
}

return true;
Expand Down
79 changes: 41 additions & 38 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,52 +336,55 @@ function learningmap_before_http_headers() {
return '';
}

$cache = cache::make('mod_learningmap', 'backlinks');
$cachekey = $PAGE->cm->id;
$key = $cache->get($cachekey);
$modinfo = get_fast_modinfo($PAGE->course);

if (!$key) {
$instances = $modinfo->get_instances_of('learningmap');
if (count($instances) > 0) {
$backlinks = [];
foreach ($instances as $i) {
$record = $DB->get_record('learningmap', ['id' => $i->instance], 'name, placestore, backlink');
if ($record->backlink == 1) {
$placestore = json_decode($record->placestore);
$coursepageurl = course_get_format($PAGE->course->id)->get_view_url($i->sectionnum);
$coursepageurl->set_anchor('module-' . $i->id);
foreach ($placestore->places as $place) {
$url = !empty($i->showdescription) ?
$coursepageurl->out() :
new moodle_url('/mod/learningmap/view.php', ['id' => $i->id]);
$backlinks[$place->linkedActivity][$i->id] = ['url' => $url, 'name' => $record->name, 'cmid' => $i->id];
try {
$cache = cache::make('mod_learningmap', 'backlinks');
$cachekey = $PAGE->cm->id;
$key = $cache->get($cachekey);
$modinfo = get_fast_modinfo($PAGE->course);

if (!$key) {
$instances = $modinfo->get_instances_of('learningmap');
if (count($instances) > 0) {
$backlinks = [];
foreach ($instances as $i) {
$record = $DB->get_record('learningmap', ['id' => $i->instance], 'name, placestore, backlink');
if ($record->backlink == 1) {
$placestore = json_decode($record->placestore);
$coursepageurl = course_get_format($PAGE->course->id)->get_view_url($i->sectionnum);
$coursepageurl->set_anchor('module-' . $i->id);
foreach ($placestore->places as $place) {
$url = !empty($i->showdescription) ?
$coursepageurl->out() :
new moodle_url('/mod/learningmap/view.php', ['id' => $i->id]);
$backlinks[$place->linkedActivity][$i->id] = ['url' => $url, 'name' => $record->name, 'cmid' => $i->id];
}
}
}
}
foreach ($backlinks as $cmid => $backlink) {
$cache->set($cmid, $backlink);
foreach ($backlinks as $cmid => $backlink) {
$cache->set($cmid, $backlink);
}
} else {
$cache->set($cachekey, []);
}
} else {
$cache->set($cachekey, []);
$backlinks[$cachekey] = $key;
}
} else {
$backlinks[$cachekey] = $key;
}
$backlinktext = '';
$backlinktext = '';

if (!empty($backlinks[$PAGE->cm->id])) {
foreach ($backlinks[$PAGE->cm->id] as $backlink) {
$cminfo = $modinfo->get_cm($backlink['cmid']);
if ($cminfo->available != 0 && $cminfo->uservisible) {
$backlinktext .= $OUTPUT->render_from_template('learningmap/backtomap', $backlink);
if (!empty($backlinks[$PAGE->cm->id])) {
foreach ($backlinks[$PAGE->cm->id] as $backlink) {
$cminfo = $modinfo->get_cm($backlink['cmid']);
if ($cminfo->available != 0 && $cminfo->uservisible) {
$backlinktext .= $OUTPUT->render_from_template('learningmap/backtomap', $backlink);
}
}
}
if ($backlinktext) {
$description = format_module_intro($PAGE->activityname, $PAGE->activityrecord, $PAGE->cm->id);
$PAGE->activityheader->set_description($description . $backlinktext);
}
} catch (Exception $e) {
debugging($e->getMessage());
}
if ($backlinktext) {
$description = format_module_intro($PAGE->activityname, $PAGE->activityrecord, $PAGE->cm->id);
$PAGE->activityheader->set_description($description . $backlinktext);
}

return '';
}
2 changes: 1 addition & 1 deletion templates/cssskeleton.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"mapid": "63bee8a5f1a1e",
"usecheckmark": false,
"editmode": true,
"version": 2023080201,
"version": 2024012601,
"pulse": false,
"hover": false,
"showall": false,
Expand Down
2 changes: 1 addition & 1 deletion tests/generator/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
"mapid": "63bb1c8edb6af",
"usecheckmark": false,
"editmode": false,
"version": 2023080201,
"version": 2024012601,
"pulse": false,
"hover": false,
"showall": false,
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_learningmap';
$plugin->release = '0.9.6';
$plugin->version = 2023121101;
$plugin->version = 2024012601;
$plugin->requires = 2020061500;
$plugin->supported = [401, 404];
$plugin->maturity = MATURITY_STABLE;
Loading