diff --git a/CHANGELOG.md b/CHANGELOG.md index 09cce95..cb15c7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,4 +15,4 @@ While the module is in development the status carries the phase: 1.0.0 Alpha 8 i - 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. - License: imforum is released under the GNU General Public License version 2 again, like iForum and ImpressCMS. `LICENSE`, `composer.json` (`GPL-2.0-only`), the module definition and the file headers say so. The first phases carried the MIT license. -- Phase 8: migration. A stub module `stub/iforum` replaces the old module folder and sends `index`, `viewforum`, `viewtopic` (also with only a `post_id`), `viewall`, `viewpost` and `rss` to the same page of imforum with a permanent redirect; `LegacyUrl` holds the translation and is covered by unit tests. `docs/MIGRATION.md` describes the steps, the address table, a web server rule and the rollback. `tools/build-release.sh` builds the release zip with both folders. +- Phase 8: migration. A stub module `stub/iforum` replaces the old module folder and sends `index`, `viewforum`, `viewtopic` (also with only a `post_id`), `viewall`, `viewpost` and `rss` to the same page of imforum with a permanent redirect; `LegacyUrl` holds the translation and is covered by unit tests. `docs/MIGRATION.md` describes the steps, the address table, a web server rule and the rollback. `bin/build-release.php` (cross-platform PHP script) builds the release zip with both folders. diff --git a/bin/build-release.php b/bin/build-release.php new file mode 100755 index 0000000..b83b19b --- /dev/null +++ b/bin/build-release.php @@ -0,0 +1,99 @@ +#!/usr/bin/env php +.zip: the module folder `imforum` and the redirect stub `iforum`. + * + * Cross-platform (Windows, Linux, macOS); needs only PHP 8 with the zip extension. + * Usage: php bin/build-release.php + */ + +declare(strict_types=1); + +if (PHP_SAPI !== 'cli') { + fwrite(STDERR, "This script must be run from the command line.\n"); + exit(1); +} + +if (!class_exists(ZipArchive::class)) { + fwrite(STDERR, "The PHP zip extension is required.\n"); + exit(1); +} + +$root = dirname(__DIR__); + +/** Reads the module version, with spaces replaced by dashes (1.0.0 Alpha 8 -> 1.0.0-Alpha-8). */ +function readVersion(string $root): string +{ + $source = file_get_contents($root . '/src/icms_version.php'); + if ($source === false || !preg_match("/'status_version' => '([^']+)'/", $source, $m)) { + throw new RuntimeException('Cannot read status_version from src/icms_version.php'); + } + + return str_replace(' ', '-', $m[1]); +} + +/** + * Adds a directory tree (or single file) to the archive under $target, with forward slashes. + */ +function addTree(ZipArchive $zip, string $source, string $target): void +{ + if (is_file($source)) { + if (!$zip->addFile($source, $target)) { + throw new RuntimeException("Cannot add $source"); + } + return; + } + + $zip->addEmptyDir($target); + $iterator = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($source, FilesystemIterator::SKIP_DOTS), + RecursiveIteratorIterator::SELF_FIRST + ); + $entries = []; + foreach ($iterator as $item) { + $entries[str_replace('\\', '/', $iterator->getSubPathname())] = $item->isDir(); + } + ksort($entries); + foreach ($entries as $relative => $isDir) { + $path = $source . '/' . $relative; + $ok = $isDir ? $zip->addEmptyDir("$target/$relative") : $zip->addFile($path, "$target/$relative"); + if (!$ok) { + throw new RuntimeException("Cannot add $path"); + } + } +} + +try { + $version = readVersion($root); + $distDir = $root . '/dist'; + if (!is_dir($distDir) && !mkdir($distDir, 0777, true) && !is_dir($distDir)) { + throw new RuntimeException("Cannot create $distDir"); + } + + $out = $distDir . '/imforum-' . $version . '.zip'; + if (is_file($out) && !unlink($out)) { + throw new RuntimeException("Cannot remove old $out"); + } + + $zip = new ZipArchive(); + if ($zip->open($out, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== true) { + throw new RuntimeException("Cannot create $out"); + } + + $zip->addEmptyDir('modules'); + addTree($zip, $root . '/src', 'modules/imforum'); + addTree($zip, $root . '/stub/iforum', 'modules/iforum'); + foreach (['LICENSE', 'README.md', 'CHANGELOG.md'] as $file) { + addTree($zip, "$root/$file", "modules/imforum/$file"); + } + addTree($zip, $root . '/docs', 'modules/imforum/docs'); + + if (!$zip->close()) { + throw new RuntimeException("Cannot write $out"); + } +} catch (Throwable $e) { + fwrite(STDERR, 'Build failed: ' . $e->getMessage() . "\n"); + exit(1); +} + +echo $out, "\n"; diff --git a/tools/build-release.sh b/tools/build-release.sh deleted file mode 100755 index 558e30c..0000000 --- a/tools/build-release.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh -# Builds dist/imforum-.zip: the module folder `imforum` and the redirect stub `iforum` -set -e -cd "$(dirname "$0")/.." -version=$(php -r 'define("ICMS_ROOT_PATH", "x"); $modversion = []; $s = file_get_contents("src/icms_version.php"); preg_match("/\x27status_version\x27 => \x27([^\x27]+)\x27/", $s, $m); echo str_replace(" ", "-", $m[1]);') -work=$(mktemp -d) -mkdir -p "$work/modules" dist -cp -r src "$work/modules/imforum" -cp -r stub/iforum "$work/modules/iforum" -cp LICENSE README.md CHANGELOG.md "$work/modules/imforum/" -cp -r docs "$work/modules/imforum/docs" -out="$(pwd)/dist/imforum-$version.zip" -rm -f "$out" -(cd "$work" && zip -qr "$out" modules) -rm -rf "$work" -echo "$out"