Files
itflow/admin/database_updates/4.4.5.php

55 lines
3.2 KiB
PHP

<?php
/*
* ITFlow - Database update to version 4.4.5 (from 4.4.4)
* Included by admin/database_updates.php - do not access directly
*
* Email (mailto:) and phone (tel:) links are let through now (purifierUriSchemes(), functions/
* sanitize.php). A document or Knowledge Base article written in Markdown keeps the HTML made from
* it when it was saved (markdownToHtml()), which had those links taken out - each one whose
* Markdown has such a link has its HTML made again, so they work without saving it again. When it
* was last updated stays as it was. Rich text is made safe as it is shown, so it needs nothing.
*
* Re-runnable: the same Markdown makes the same HTML.
*/
defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");
// Made by the code from before this release, the links would come out again - so stop, and the
// next run, on the updated code, picks up here (scripts/update_cli.php runs it so when it can)
if (!function_exists('purifierUriSchemes') || !function_exists('markdownToHtml')) {
throw new Exception('this update needs the updated code loaded - run the update again');
}
$itflow_column_there = function ($table, $column) use ($mysqli) {
$result = mysqli_query($mysqli, "SELECT 1 FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = '$table' AND COLUMN_NAME = '$column' LIMIT 1");
return $result && mysqli_num_rows($result) > 0;
};
if ($itflow_column_there('documents', 'document_markdown')) {
$itflow_rows = mysqli_query($mysqli, "SELECT document_id, document_name, document_markdown FROM documents
WHERE document_markdown IS NOT NULL AND (document_markdown LIKE '%mailto:%' OR document_markdown LIKE '%tel:%')");
while ($itflow_rows && ($itflow_row = mysqli_fetch_assoc($itflow_rows))) {
$itflow_html = markdownToHtml($itflow_row['document_markdown']);
mysqli_query($mysqli, "UPDATE documents SET
document_content = '" . mysqli_real_escape_string($mysqli, $itflow_html) . "',
document_content_raw = '" . escapeSql(documentContentRaw($itflow_row['document_name'], $itflow_html)) . "',
document_updated_at = document_updated_at
WHERE document_id = " . intval($itflow_row['document_id']));
}
}
if ($itflow_column_there('kb_articles', 'kb_article_markdown')) {
$itflow_rows = mysqli_query($mysqli, "SELECT kb_article_id, kb_article_title, kb_article_summary, kb_article_markdown FROM kb_articles
WHERE kb_article_markdown IS NOT NULL AND (kb_article_markdown LIKE '%mailto:%' OR kb_article_markdown LIKE '%tel:%')");
while ($itflow_rows && ($itflow_row = mysqli_fetch_assoc($itflow_rows))) {
$itflow_html = markdownToHtml($itflow_row['kb_article_markdown']);
mysqli_query($mysqli, "UPDATE kb_articles SET
kb_article_content = '" . mysqli_real_escape_string($mysqli, $itflow_html) . "',
kb_article_content_raw = '" . escapeSql(kbArticleContentRaw($itflow_row['kb_article_title'], (string) $itflow_row['kb_article_summary'], $itflow_html)) . "',
kb_article_updated_at = kb_article_updated_at
WHERE kb_article_id = " . intval($itflow_row['kb_article_id']));
}
}