Commit eded804f authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1995527: Need to check module is installed before deleting content



When deleting a page or collection

Which can happen when deleting
- a group
- a user

etc

Change-Id: I25889d71295bd3741c8479beb69c4746541a8dfd
Signed-off-by: default avatarRobert Lyon <robertl@catalyst.net.nz>
parent 9e89a57c
Loading
Loading
Loading
Loading
+12 −9
Original line number Diff line number Diff line
@@ -317,21 +317,24 @@ class Collection {
        }
        delete_records('collection_view','collection', $this->id);
        delete_records('tag', 'resourcetype', 'collection', 'resourceid', $this->id);
        if (is_plugin_active('lti', 'module')) {
        if (is_plugin_installed('lti', 'module')) {
            delete_records('lti_assessment_submission', 'collectionid', $this->id);
        }
        delete_records('existingcopy', 'collection', $this->id);
        delete_records('collection_template', 'collection', $this->id);
        delete_records('view_copy_queue', 'collection', $this->id);
        delete_records('collection', 'id', $this->id);
        if (is_plugin_installed('assessmentreport', 'module')) {
            // Delete any submission history
            delete_records('module_assessmentreport_history', 'event', 'collection', 'itemid', $this->id);
        }
        if (is_plugin_installed('submissions', 'module')) {
            $submissionids = get_column('module_submissions', 'id', 'portfolioelementtype', 'collection', 'portfolioelementid', $this->id);
            if ($submissionids) {
                execute_sql("DELETE FROM {module_submissions_evaluation} WHERE submissionid IN (" . join(',', $submissionids) . ")");
                execute_sql("DELETE FROM {module_submissions} WHERE id IN (" . join(',', $submissionids) . ")");
            }

        }
        delete_records('collection', 'id', $this->id);
        // Secret url records belong to the collection, so remove them from the view.
        // @todo: add user message to whatever calls this.
        if ($viewids) {
+12 −0
Original line number Diff line number Diff line
@@ -1808,6 +1808,18 @@ function safe_require_plugin($plugintype, $pluginname, $filename='lib.php', $fun
    }
}

/**
 * Check to see if a particular plugin is installed by plugin name
 *
 * @param   string $pluginname Name of plugin
 * @param   string $type       Name of plugin type
 * @return  bool
 */
function is_plugin_installed($pluginname, $type) {
    $plugins_by_type = plugins_installed($type, true);
    return isset($plugins_by_type[$pluginname]);
}

/**
 * Check to see if a particular plugin is installed and is active by plugin name
 *
+10 −6
Original line number Diff line number Diff line
@@ -1085,13 +1085,17 @@ class View {
            }
        }
        // Delete any submission related history
        if (is_plugin_installed('assessmentreport', 'module')) {
            delete_records('module_assessmentreport_history', 'event', 'view', 'itemid', $this->id);
        }
        if (is_plugin_installed('submissions', 'module')) {
            $submissionids = get_column('module_submissions', 'id', 'portfolioelementtype', 'view', 'portfolioelementid', $this->id);
            if ($submissionids) {
                execute_sql("DELETE FROM {module_submissions_evaluation} WHERE submissionid IN (" . join(',', $submissionids) . ")");
                execute_sql("DELETE FROM {module_submissions} WHERE id IN (" . join(',', $submissionids) . ")");
            }
        if (is_plugin_active('lti', 'module')) {
        }
        if (is_plugin_installed('lti', 'module')) {
            delete_records('lti_assessment_submission', 'viewid', $this->id);
        }