Commit 7adcfbfd authored by Scott Verbeek's avatar Scott Verbeek Committed by Robert Lyon
Browse files

Upgrade bug 1953086: Add text parameter to img src

behatnotneeded

Change-Id: I8fbce33853212ad24022a5e57a835ac4f9854472
parent cfc100f5
Loading
Loading
Loading
Loading
+60 −0
Original line number Diff line number Diff line
@@ -2266,5 +2266,65 @@ function xmldb_core_upgrade($oldversion=0) {
        }
    }

    if ($oldversion < 2021042712) {
        log_debug('Updating description text block image src attributes missing text parameter in url');
        require_once(get_config('docroot') . 'blocktype/lib.php');
        require_once(get_config('libroot') . 'embeddedimage.php');
        // Find block instances which might need updating.
        $sql = "SELECT b.id, b.configdata, v.group, v.owner
                  FROM {block_instance} b
            INNER JOIN {view} v on b.view = v.id
                 WHERE blocktype = ?
                   AND configdata LIKE CONCAT('%description=', b.view, '%')
                 ORDER BY b.id";
        // Find the total count of block instances (for logging purposes).
        $sqlcount = "SELECT COUNT(b.id)
                       FROM {block_instance} b
                 INNER JOIN {view} v on b.view = v.id
                      WHERE blocktype = ?
                        AND configdata LIKE CONCAT('%description=', b.view, '%')";

        $total = get_field_sql($sqlcount, array('text'));
        $changes = 0;
        $limit = 100;
        $offset = 0;
        while ($total > 0 && $records = get_records_sql_array($sql, array('text'), $offset, $limit)) {
            $offset += count($records);
            foreach($records as $record) {
                $configdata = unserialize($record->configdata);
                if (
                    isset($configdata['text']) &&
                    !empty($configdata['text']) &&
                    $configdata['text'] !== (
                        $newtext = EmbeddedImage::prepare_embedded_images(
                            $configdata['text'],
                            'text',
                            $record->id,
                            $record->group,
                            $record->owner
                        )
                    )
                ) {
                    // Update the text block_instance with the $newtext.
                    $bi = new BlockInstance($record->id);
                    $configdata['text'] = $newtext;
                    $bi->set('configdata', $configdata);
                    $bi->commit();
                    $changes++;
                }
            }

            log_debug("$offset/$total");
        }

        // If we haven't found any results notify.
        if ($total === 0) {
            log_debug('Found no related block instances');
        }
        else {
            log_debug("{$changes} of {$total} block_instances configdata text have been updated with a text parameter in src attribute");
        }
    }

    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 = 2021042711;
$config->version = 2021042712;
$config->series = '21.04';
$config->release = '21.04.3testing';
$config->minupgradefrom = 2017031605;
+40 −0
Original line number Diff line number Diff line
@@ -3297,6 +3297,29 @@ class View {
                        $bi->set('order', $blockinstance['order']);
                    }
                    $view->addblockinstance($bi);
                    // Need to rewrite images links in configdata[text] if blocktype is text.
                    if ($bi->get('blocktype') === 'text') {
                        require_once(get_config('libroot') . 'embeddedimage.php');
                        $configdata = $bi->get('configdata');
                        if (
                            isset($configdata['text']) &&
                            !empty($configdata['text']) &&
                            $configdata['text'] !== (
                                $newtext = EmbeddedImage::prepare_embedded_images(
                                    $configdata['text'],
                                    'text',
                                    $bi->get('id'),
                                    $view->get('group'),
                                    $view->get('owner')
                                )
                            )
                        ) {
                            // Update the text block_instance with the $newtext.
                            $configdata['text'] = $newtext;
                            $bi->set('configdata', $configdata);
                            $bi->commit();
                        }
                    }
                }
                else {
                    log_debug("Blocktype {$blockinstance['type']}'s import_create_blockinstance did not give us a blockinstance, so not importing this block");
@@ -7461,6 +7484,23 @@ class View {
            (object) array('resourcetype' => 'text', 'resourceid' => $bi->get('id')),
            array('resourcetype' => 'description', 'resourceid' => $this->get('id'))
        );

        require_once(get_config('libroot') . 'embeddedimage.php');
        $newdescription = EmbeddedImage::prepare_embedded_images(
            $description,
            'text',
            $bi->get('id'),
            $this->get('group'),
            $this->get('owner')
        );
        if ($description !== $newdescription) {
            $bi->set('configdata', array(
                'text' => $newdescription,
                'retractable' => false,
                'retractedonload' => false,
            ));
            $bi->commit();
        }
    }

    public function has_signoff_block() {