Commit 2822ce02 authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1689931: Updating the artefact_annotation mapping



When copying a page with an annotation artefact on it

behatnotneeded

Change-Id: Ib40e6c4fdf2c31830c3855dcd5b5eedbcebce875
Signed-off-by: default avatarRobert Lyon <robertl@catalyst.net.nz>
parent 65d77bc0
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -274,6 +274,23 @@ class ArtefactTypeAnnotation extends ArtefactType {
        return $url;
    }

    public function update_artefact_references(&$view, &$template, &$artefactcopies, $oldid) {
        parent::update_artefact_references($view, $template, $artefactcopies, $oldid);
        // If we have some artefact mapping data
        if (isset($artefactcopies[$oldid]->newid)) {
            if ($viewid = get_field('view_artefact', 'view', 'artefact', $artefactcopies[$oldid]->newid, 'view', $view->get('id'))) {
                // And the mapping data relates to this particular view (useful if in collection)
                // Attach copies of the annotation artefact to correct view in artefact_annotation table.
                $data = (object)array(
                    'annotation'    => $artefactcopies[$oldid]->newid,
                    'view'          => $view->get('id'),
                    'artefact'      => $this->get('artefact'),
                );
                update_record('artefact_annotation', $data, 'annotation');
            }
        }
    }

    public function commit() {
        if (empty($this->dirty)) {
            return;
+16 −0
Original line number Diff line number Diff line
@@ -4959,5 +4959,21 @@ function xmldb_core_upgrade($oldversion=0) {
        clear_menu_cache();
    }

    if ($oldversion < 2017031607) {
        if ($records = get_records_sql_assoc("SELECT aa.annotation, va.view
                                              FROM {artefact_annotation} aa
                                              JOIN {view_artefact} va ON va.artefact = aa.annotation
                                              WHERE aa.view != va.view", array())) {
            log_debug('Fix artefact_annotation table data for copied collections');
            foreach ($records as $record) {
                $data = (object)array(
                    'annotation'    => $record->annotation,
                    'view'          => $record->view,
                );
                update_record('artefact_annotation', $data, 'annotation');
            }
        }
    }

    return $status;
}
+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/wiki/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one.  On master, use the date.

$config->version = 2017031606;
$config->version = 2017031607;
$config->series = '17.04';
$config->release = '17.04.1testing';
$config->minupgradefrom = 2012080604;