Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 1.0.0 Alpha (unreleased)

While the module is in development the status carries the phase: 1.0.0 Alpha 5 is phase 5.
While the module is in development the status carries the phase: 1.0.0 Alpha 7 is phase 7.

- Phase 0: module skeleton for ImpressCMS 2.0 in IPF mode, install and update routines, English and Dutch language files, CI on PHP 8.2 to 8.5.
- Phase 1: data model. 13 IPF objects with handlers (category, forum, moderator, topic, post, attachment, report, suspension, readmark, online, digest, archive, permtemplate), group permissions on categories and forums, counters and cascading deletes through handler events, indexes in `imforum_db_upgrade_1()`, labels in English and Dutch, integration tests against MySQL 5.5, MySQL 5.7 (MyISAM) and MariaDB 10.11.
Expand All @@ -13,3 +13,4 @@ While the module is in development the status carries the phase: 1.0.0 Alpha 5 i
- Phase 6: background tasks. Two autotasks, registered by the core when the module is installed or updated: the digest mail and a cleanup. Members subscribe to the digest with the notification "Digest" for all forums. `DigestMailer` covers the time since the last digest (one day for the first), lists titles, counts and links but never the text of a post, sends each member only the forums that member may read, and stores the complete digest for the administrators before it sends, so a failure halfway never causes a second mail. The cleanup removes visitors that are no longer online, read marks older than a preference (90 days; 0 keeps them) and suspensions that ended more than 30 days ago. A topic without a read mark counts as unread, so posts older than the limit first count as read for members who have marks, and only then the old marks go.
- Database access: all hand-written SQL now goes through `mod_imforum_Db` over the core's PDO connection (`icms::$db`) with bound parameters, instead of `queryF()` on the legacy adapter (`icms::$xoopsDB`) with values glued into the SQL. The IPF handlers keep the legacy adapter the core gives them for their own queries; both share one PDO connection. Without PDO (`XOOPS_DB_TYPE` not `pdo.*`) the module stops with a clear message. Prepared statements do not show up in the debug console of the core, which only logs `query()`.
- Editor: the post, forum and category forms use the `dhtmltextarea` control, as the content module does, so the WYSIWYG editor chosen in the site preferences loads (the plain `textarea` control of the IPF ignores the editor). A post written in an editor is stored as HTML (`dohtml` on, line breaks off) and is shown through the purifier; without an editor the text still stays as typed. The quick reply and the moderation forms stay plain textareas.
- Phase 7: importer. `admin/import.php` and `Importer` copy the data of a running iForum installation into imforum, keeping every id, and never change iForum: categories, forums, the serialized moderator lists (one row per member), topics (ratings, polls and tags are left out), posts joined with their text (IP addresses become text), edit histories (base64 serialized lists become JSON), attachments from the posts and from the reserved table (names that could leave the upload folder are refused, files are copied and measured), reports, suspensions that have not ended, read marks (one per member and item), digests, the archive, group permissions of the forums and categories under the id of imforum (poll rights are left out), subscriptions that imforum has events for, the preferences that exist in both modules (the `NONE` entry of the subject prefixes is dropped, as imforum counts prefixes from 1) and the cached permission template. The check writes nothing: it reports missing tables and columns, character sets, orphans, posts that grow past 64 KB when converted, missing attachment files and text that looks like UTF-8 in latin1 columns, for which the import can read the bytes as UTF-8. Importing and rolling back ask for a confirmation and run only on a POST with a token. Every import starts by emptying the imforum tables, so an interrupted run is simply repeated; rolling back empties them again and removes the copied rights, subscriptions and files. Afterwards the counters are recounted and `verify()` compares row counts, posts per forum and per topic, a checksum of 200 random posts, the rights and the attachment files. Tests build an old installation, check every table, run the largest case (43,778 posts) and prove that iForum's tables are unchanged.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Community forum module for ImpressCMS 2.0, built on the ImpressCMS Persistable Framework (IPF). imforum is the successor of iForum: same features, new code, and an importer that takes over the data of a running iForum installation.

Status: phase 6 (background tasks), module version 1.0.0 Alpha 6. Members start topics, reply (with a quick reply under the topic), quote, edit and delete their own posts, attach files and follow topics and forums by notification; guests can post where the group permissions allow it, behind a captcha. Posts wait for a moderator when the group lacks forum_noapprove. Moderators of a forum lock, pin and feature topics, move, merge and split them, delete topics, approve waiting posts, handle reports from members and suspend members, all from the front end through `moderate.php`; members report posts through `report.php`. Two autotasks (Systeem > Autotasks, daily by default) send a digest of new topics and posts to members who subscribe to it and clean up old read marks, the visitors list and ended suspensions. Categories, forums, moderators, permissions, reports, suspensions, digests, the archive and pruning are managed from the admin area.
Status: phase 7 (importer), module version 1.0.0 Alpha 7. Members start topics, reply (with a quick reply under the topic), quote, edit and delete their own posts, attach files and follow topics and forums by notification; guests can post where the group permissions allow it, behind a captcha. Posts wait for a moderator when the group lacks forum_noapprove. Moderators of a forum lock, pin and feature topics, move, merge and split them, delete topics, approve waiting posts, handle reports from members and suspend members, all from the front end through `moderate.php`; members report posts through `report.php`. Two autotasks (Systeem > Autotasks, daily by default) send a digest of new topics and posts to members who subscribe to it and clean up old read marks, the visitors list and ended suspensions. Categories, forums, moderators, permissions, reports, suspensions, digests, the archive and pruning are managed from the admin area. The import page copies the data of a running iForum installation into imforum: check, import, verify and roll back.

## Requirements

Expand Down
82 changes: 82 additions & 0 deletions src/admin/import.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
/**
* Import the data of a running iForum installation
*
* The check reads and reports. Importing and rolling back first ask for a
* confirmation and then run only on a POST with a security token.
*
* @copyright The iForum project
* @license MIT, see LICENSE
* @package imforum
* @since 1.0
*/

include_once __DIR__ . '/admin_header.php';

$op = imforum_admin_op(['run', 'rollback']);
$encoding = ($_POST['encoding'] ?? $_GET['encoding'] ?? '') === mod_imforum_Importer::ENCODING_UTF8_BYTES
? mod_imforum_Importer::ENCODING_UTF8_BYTES
: mod_imforum_Importer::ENCODING_AS_IS;
$importer = new mod_imforum_Importer($encoding);

/** The form that starts every action; the choice of encoding travels with it */
$form = static function () use ($encoding): string {
$e = static fn (string $text): string => htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
$form = new icms_form_Theme(_AM_IMFORUM_IMPORT, 'import', imforum_admin_url('import.php'), 'post', true);
$select = new icms_form_elements_Select(_AM_IMFORUM_IMPORT_ENCODING, 'encoding', $encoding);
$select->addOptionArray([
mod_imforum_Importer::ENCODING_AS_IS => _AM_IMFORUM_IMPORT_ENCODING_AS_IS,
mod_imforum_Importer::ENCODING_UTF8_BYTES => _AM_IMFORUM_IMPORT_ENCODING_BYTES,
]);
imforum_form_add($form, new icms_form_elements_Label('', $e(_AM_IMFORUM_IMPORT_STEPS)));
imforum_form_add($form, $select);
$buttons = '';
foreach (['check' => _AM_IMFORUM_IMPORT_CHECK, 'askrun' => _AM_IMFORUM_IMPORT_RUN, 'verify' => _AM_IMFORUM_IMPORT_VERIFY, 'askrollback' => _AM_IMFORUM_IMPORT_ROLLBACK] as $value => $label) {
$buttons .= '<button type="submit" name="op" value="' . $value . '">' . $e($label) . '</button> ';
}
imforum_form_add($form, new icms_form_elements_Label('', $buttons));
return $form->render();
};

switch ($op) {
case 'askrun':
case 'askrollback':
icms_cp_header();
imforum_admin_menu(9, _AM_IMFORUM_IMPORT);
icms_core_Message::confirm(
['op' => $op === 'askrun' ? 'run' : 'rollback', 'encoding' => $encoding, 'confirm' => 1],
imforum_admin_url('import.php'),
$op === 'askrun' ? _AM_IMFORUM_IMPORT_CONFIRM_RUN : _AM_IMFORUM_IMPORT_CONFIRM_ROLLBACK,
_AM_IMFORUM_IMPORT_GO
);
icms_cp_footer();
break;

case 'run':
// a long import must not stop when the browser gives up waiting
@set_time_limit(0);
ignore_user_abort(true);
$report = $importer->run();
$html = imforum_import_report_html($report);
if ($report['ok']) {
$html .= '<h2>' . htmlspecialchars(_AM_IMFORUM_IMPORT_VERIFY, ENT_QUOTES, 'UTF-8') . '</h2>' . imforum_import_report_html($importer->verify());
}
imforum_admin_page(9, _AM_IMFORUM_IMPORT, static fn (): string => $form() . $html, $report['ok'] ? _AM_IMFORUM_IMPORT_DONE : '');
break;

case 'rollback':
imforum_admin_page(9, _AM_IMFORUM_IMPORT, static fn (): string => $form() . imforum_import_report_html($importer->rollback()), _AM_IMFORUM_IMPORT_ROLLED_BACK);
break;

case 'check':
imforum_admin_page(9, _AM_IMFORUM_IMPORT, static fn (): string => $form() . imforum_import_report_html($importer->check()));
break;

case 'verify':
imforum_admin_page(9, _AM_IMFORUM_IMPORT, static fn (): string => $form() . imforum_import_report_html($importer->verify()));
break;

default:
imforum_admin_page(9, _AM_IMFORUM_IMPORT, $form, _AM_IMFORUM_IMPORT_DSC);
break;
}
1 change: 1 addition & 0 deletions src/admin/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
'digest' => _MI_IMFORUM_MENU_DIGESTS,
'archive' => _MI_IMFORUM_MENU_ARCHIVE,
'prune' => _MI_IMFORUM_MENU_PRUNE,
'import' => _MI_IMFORUM_MENU_IMPORT,
] as $script => $title) {
$adminmenu[] = [
'title' => $title,
Expand Down
Loading
Loading