Commit 9f894a25 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review
Browse files

Merge changes I71bcdb6c,I9c9b7fd7

* changes:
  Bug 1826948: update existing comments
  Bug 1826948: Stop comment text being saved with extra tags
parents 4ee3e066 9a42c680
......@@ -1181,7 +1181,7 @@ class ArtefactTypeComment extends ArtefactType {
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadHTML($comment);
$dom->loadHTML($comment, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$xpath = new DOMXPath($dom);
......
......@@ -1288,5 +1288,40 @@ function xmldb_core_upgrade($oldversion=0) {
}
if ($oldversion < 2019043000) {
log_debug('remove extra html from comment artefact descriptions');
// Get all the comment artefacts with the issue
$sql = "SELECT * FROM {artefact}
WHERE artefacttype = 'comment'
AND description " . db_ilike() . " '<!DOCTYPE%'";
if ($artefacts = get_records_sql_array($sql)) {
$count = 0;
$limit = 1000;
$total = count($artefacts);
// Loop through all of them and update the description
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
foreach ($artefacts as $artefact) {
$dom->loadHTML($artefact->description);
$xpath = new DOMXPath($dom);
$body = $xpath->query('/html/body');
$innerHtml = '';
foreach ($body->item(0)->childNodes as $child) {
$innerHtml .= $dom->saveHTML($child);
}
$artefact->description = $innerHtml;
update_record('artefact', $artefact);
$count++;
if (($count % $limit) == 0 || $count == $total) {
log_debug("$count/$total");
set_time_limit(30);
}
}
}
}
return $status;
}
......@@ -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 = 2019040900;
$config->version = 2019043000;
$config->series = '19.10';
$config->release = '19.10dev';
$config->minupgradefrom = 2017031605;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment