Skip to content

Commit 4d136ad

Browse files
Migrate existing activity notes to remove inline highlight markup
1 parent cb109bf commit 4d136ad

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

modules/install/Schema.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,56 @@ public static function get()
14421442
$db->query("ALTER TABLE `".$row[\'table_name\']."` ENGINE=InnoDB");
14431443
}
14441444
',
1445+
'376' => 'PHP:
1446+
$lastActivityID = 0;
1447+
$batchSize = 200;
1448+
$highlightPattern = "/<span\\b(?=[^>]*\\bstyle\\s*=\\s*([\\"\\\']).*?\\bcolor\\s*:\\s*#ff6c00\\s*;?.*?\\1)[^>]*>(.*?)<\\/span>/is";
1449+
1450+
while (true)
1451+
{
1452+
$activityRS = $db->getAllAssoc(
1453+
"SELECT
1454+
activity_id,
1455+
notes
1456+
FROM
1457+
activity
1458+
WHERE
1459+
activity_id > " . $lastActivityID . "
1460+
AND notes LIKE \'%<span%\'
1461+
AND notes LIKE \'%#ff6c00%\'
1462+
ORDER BY
1463+
activity_id ASC
1464+
LIMIT " . $batchSize
1465+
);
1466+
1467+
if (empty($activityRS))
1468+
{
1469+
break;
1470+
}
1471+
1472+
foreach ($activityRS as $rowIndex => $row)
1473+
{
1474+
$updatedNotes = preg_replace($highlightPattern, \'$2\', $row[\'notes\']);
1475+
1476+
if ($updatedNotes === null)
1477+
{
1478+
$lastActivityID = (int) $row[\'activity_id\'];
1479+
continue;
1480+
}
1481+
1482+
if ($updatedNotes !== $row[\'notes\'])
1483+
{
1484+
$db->query(
1485+
"UPDATE activity
1486+
SET notes = " . $db->makeQueryString($updatedNotes) . "
1487+
WHERE activity_id = " . (int) $row[\'activity_id\']
1488+
);
1489+
}
1490+
1491+
$lastActivityID = (int) $row[\'activity_id\'];
1492+
}
1493+
}
1494+
',
14451495

14461496
);
14471497
}

0 commit comments

Comments
 (0)