Commit 23a8f8bf authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1895594: Update/Remove external userid value when copying page



On the course completion block.

Otherwise the copier sees the content for the person they copied the
page from rather than their own content (or no content if they don't
have an external userid)

Change-Id: I2433df88b2462171b4644d9841e1bb2baa27509a
Signed-off-by: default avatarRobert Lyon <robertl@catalyst.net.nz>
parent 4617dd51
Loading
Loading
Loading
Loading
+32 −9
Original line number Diff line number Diff line
@@ -195,6 +195,12 @@ class PluginBlocktypeCourseinfo extends MaharaCoreBlocktype {
    public static function instance_config_save($values, BlockInstance $instance) {
        $ownerid = $instance->get_view()->get('owner');
        if ($ownerid) {
            $values['userid'] = self::fetch_external_userid($ownerid);
        }
        return $values;
    }

    public static function fetch_external_userid($ownerid) {
        $username = get_field_sql("SELECT email FROM {artefact_internal_profile_email} WHERE owner = ? AND principal = ?", array($ownerid, 1)); // Check on primary email address
        $owner = new stdClass();
        $owner->id = $ownerid;
@@ -202,11 +208,12 @@ class PluginBlocktypeCourseinfo extends MaharaCoreBlocktype {
        if ($connections = Plugin::get_webservice_connections($owner, 'fetch_userid')) {
            foreach ($connections as $connection) {
                $result = call_static_method($connection->connection->class, 'fetch_userid', $connection, $owner, $configdata);
                    $values['userid'] = $result;
                if (!empty($result)) {
                    return $result;
                }
            }
        }
        return $values;
        return null;
    }

    public static function has_config_info() {
@@ -222,6 +229,22 @@ class PluginBlocktypeCourseinfo extends MaharaCoreBlocktype {
        return 'shallow';
    }

    public static function rewrite_blockinstance_config(View $view, $configdata) {
        if ($view->get('owner') !== null) {
            $externalid = self::fetch_external_userid($view->get('owner'));
            if ($externalid) {
                $configdata['userid'] = $externalid;
            }
            else {
                unset($configdata['userid']);
            }
        }
        else {
            unset($configdata['userid']);
        }
        return $configdata;
    }

    public static function get_data($configdata, $offset=0, $limit=10) {
        $owner = new stdClass();
        $owner->id = $configdata['ownerid'];