(MDL-10155) detect failed regexes duing multilang upgrade (it was causing data loss on some sites)
This commit is contained in:
@@ -59,12 +59,8 @@ foreach ($tables as $table) {
|
||||
if ($rs and $rs->RecordCount() > 0) {
|
||||
while (!$rs->EOF) {
|
||||
$text = $rs->fields[$column];
|
||||
$search = '/(<(?:lang|span) lang="[a-zA-Z0-9_-]*".*?>.+?<\/(?:lang|span)>)(\s*<(?:lang|span) lang="[a-zA-Z0-9_-]*".*?>.+?<\/(?:lang|span)>)+/is';
|
||||
$newtext = preg_replace_callback($search, 'multilangupgrade_impl', $text);
|
||||
if ($newtext != $text) {
|
||||
$newtext = addslashes($newtext);
|
||||
execute_sql("UPDATE $table SET $column='$newtext' WHERE id=".$rs->fields['id'], false);
|
||||
}
|
||||
$id = $rs->fields['id'];
|
||||
|
||||
if ($i % 600 == 0) {
|
||||
echo '<br />';
|
||||
}
|
||||
@@ -73,6 +69,22 @@ foreach ($tables as $table) {
|
||||
}
|
||||
$i++;
|
||||
$rs->MoveNext();
|
||||
|
||||
if (empty($text) or is_numeric($text)) {
|
||||
continue; // nothing to do
|
||||
}
|
||||
|
||||
$search = '/(<(?:lang|span) lang="[a-zA-Z0-9_-]*".*?>.+?<\/(?:lang|span)>)(\s*<(?:lang|span) lang="[a-zA-Z0-9_-]*".*?>.+?<\/(?:lang|span)>)+/is';
|
||||
$newtext = preg_replace_callback($search, 'multilangupgrade_impl', $text);
|
||||
|
||||
if (is_null($newtext)) {
|
||||
continue; // regex error
|
||||
}
|
||||
|
||||
if ($newtext != $text) {
|
||||
$newtext = addslashes($newtext);
|
||||
execute_sql("UPDATE $table SET $column='$newtext' WHERE id=$id", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,10 @@ function multilang_filter($courseid, $text) {
|
||||
// [nicolasconnault] Should support inverted attributes: <span class="multilang" lang="en"> (Doesn't work curently)
|
||||
// [skodak] it supports it now, though it is slower - any better idea?
|
||||
|
||||
if (empty($text) or is_numeric($text)) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
if (empty($CFG->filter_multilang_force_old) and !empty($CFG->filter_multilang_converted)) {
|
||||
// new syntax
|
||||
$search = '/(<span(\s+lang="[a-zA-Z0-9_-]+"|\s+class="multilang"){2}\s*>.*?<\/span>)(\s*<span(\s+lang="[a-zA-Z0-9_-]+"|\s+class="multilang"){2}\s*>.*?<\/span>)+/is';
|
||||
@@ -51,7 +55,14 @@ function multilang_filter($courseid, $text) {
|
||||
// old syntax
|
||||
$search = '/(<(?:lang|span) lang="[a-zA-Z0-9_-]*".*?>.*?<\/(?:lang|span)>)(\s*<(?:lang|span) lang="[a-zA-Z0-9_-]*".*?>.*?<\/(?:lang|span)>)+/is';
|
||||
}
|
||||
return preg_replace_callback($search, 'multilang_filter_impl', $text);
|
||||
|
||||
$result = preg_replace_callback($search, 'multilang_filter_impl', $text);
|
||||
|
||||
if (is_null($result)) {
|
||||
return $text; //error during regex processing (too many nested spans?)
|
||||
} else {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
function multilang_filter_impl($langblock) {
|
||||
|
||||
Reference in New Issue
Block a user