+<?php
+/**
+ * CLI script to create a phpBB board using QuickInstall
+ *
+ * Usage: php create-board.php <board_name>
+ *
+ * This script bootstraps QuickInstall and invokes the board creation module
+ * to create a fully populated board during Docker build.
+ */
+
+if (php_sapi_name() !== 'cli') {
+ die("This script must be run from the command line.\n");
+}
+
+if ($argc < 2) {
+ die("Usage: php create-board.php <board_name>\n");
+}
+
+$board_name = $argv[1];
+
+// Change to QuickInstall directory
+chdir('/var/www/html/quickinstall');
+
+// Define required constants
+define('IN_PHPBB', true);
+define('IN_QUICKINSTALL', true);
+define('IN_INSTALL', true);
+
+$quickinstall_path = './';
+$phpbb_root_path = $quickinstall_path . 'sources/phpBB3/';
+$phpEx = 'php';
+
+// Report all errors, except notices
+$level = E_ALL ^ E_NOTICE;
+
+// Include scripts for quickinstall
+require("{$quickinstall_path}includes/qi_constants.$phpEx");
+require("{$quickinstall_path}includes/qi.$phpEx");
+require("{$quickinstall_path}includes/settings.$phpEx");
+require("{$quickinstall_path}includes/qi_functions.$phpEx");
+require("{$quickinstall_path}includes/qi_file.$phpEx");
+require("{$quickinstall_path}includes/qi_module.$phpEx");
+require("{$quickinstall_path}includes/twig.$phpEx");
+require("{$quickinstall_path}vendor/autoload.$phpEx");
+
+if (PHP_VERSION_ID >= 50400) {
+ if (!defined('E_STRICT')) {
+ define('E_STRICT', 2048);
+ }
+ $level &= ~E_STRICT;
+}
+
+if (PHP_VERSION_ID >= 50500) {
+ if (!defined('E_DEPRECATED')) {
+ define('E_DEPRECATED', 8192);
+ }
+ $level &= ~E_DEPRECATED;
+}
+error_reporting($level);
+
+// Define STRIP constant
+define('STRIP', false);
+
+// Set limits
+@set_time_limit(0);
+@ini_set('memory_limit', '256M');
+
+// Set PHP error handler to qi's handler
+set_error_handler(array('qi', 'msg_handler'), E_ALL);
+
+// Load settings from the debianforumde profile
+$settings = new settings($quickinstall_path);
+$settings->import_profile('debianforumde');
+
+// Get phpBB version and load dependencies
+$phpbb_version = get_phpbb_version($phpbb_root_path);
+
+if (file_exists($phpbb_root_path . 'phpbb/class_loader.' . $phpEx)) {
+ define('PHPBB_31', true);
+
+ require($phpbb_root_path . 'phpbb/class_loader.' . $phpEx);
+ $phpbb_class_loader = new \phpbb\class_loader('phpbb\\', $phpbb_root_path . 'phpbb/', $phpEx);
+ $phpbb_class_loader->register();
+
+ require($phpbb_root_path . 'vendor/autoload.' . $phpEx);
+}
+
+if (!file_exists($phpbb_root_path . 'includes/functions_install.' . $phpEx) || version_compare($phpbb_version, '3.2', '>=')) {
+ define('PHPBB_32', true);
+}
+
+if (file_exists($phpbb_root_path . 'vendor-ext') || version_compare($phpbb_version, '4.0', '>=')) {
+ define('PHPBB_40', true);
+}
+
+require($phpbb_root_path . 'includes/functions.' . $phpEx);
+require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
+
+if (!function_exists('phpbb_email_hash') || version_compare($phpbb_version, '3.3', '>=')) {
+ define('PHPBB_33', true);
+}
+
+// Need to set prefix here before constants.php are included
+$table_prefix = $settings->get_config('table_prefix', '');
+
+require($phpbb_root_path . 'includes/constants.' . $phpEx);
+
+if (!qi::phpbb_branch('3.2')) {
+ require($phpbb_root_path . 'includes/functions_install.' . $phpEx);
+}
+
+// Initialize user, cache, auth - mirroring index.php exactly
+if (qi::phpbb_branch('3.1')) {
+ if (qi::phpbb_branch('3.2')) {
+ $cache_dir = $quickinstall_path . $settings->get_config('cache_dir', '');
+ $cache = new \phpbb\cache\driver\file($cache_dir);
+ $user = new \phpbb\user(
+ new \phpbb\language\language(
+ new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)),
+ '\phpbb\datetime'
+ );
+ } else {
+ $user = new \phpbb\user('\phpbb\datetime');
+ $cache = new \phpbb\cache\driver\file();
+ }
+
+ $auth = new \phpbb\auth\auth();
+ require($phpbb_root_path . 'includes/functions_compatibility.' . $phpEx);
+} else {
+ require($phpbb_root_path . 'includes/acm/acm_file.' . $phpEx);
+ require($phpbb_root_path . 'includes/auth.' . $phpEx);
+ require($phpbb_root_path . 'includes/cache.' . $phpEx);
+ require($phpbb_root_path . 'includes/session.' . $phpEx);
+
+ $user = new user();
+ $auth = new auth();
+ $cache = new cache();
+}
+
+// Initialize template
+$template = new twig($user, $settings->get_cache_dir(), $quickinstall_path);
+
+// Apply QuickInstall language
+qi::apply_lang($settings->get_config('qi_lang', 'en'));
+
+// Validate settings
+if (!$settings->validate()) {
+ $errors = $settings->get_errors();
+ echo "Settings validation errors:\n";
+ foreach ($errors as $error) {
+ if (is_array($error)) {
+ echo " - " . implode(': ', $error) . "\n";
+ } else {
+ echo " - $error\n";
+ }
+ }
+ exit(1);
+}
+
+// Set config as per index.php
+if (qi::phpbb_branch('3.1')) {
+ $config = new \phpbb\config\config(array(
+ 'load_tplcompile' => '1',
+ ));
+ qi_set_config(false, false, false, $config);
+ qi_set_config_count(null, null, null, $config);
+} else {
+ $config = array(
+ 'load_tplcompile' => '1',
+ );
+}
+
+// Set the board name via POST simulation
+$_POST['dbname'] = $board_name;
+$_REQUEST['dbname'] = $board_name;
+
+echo "Creating board '$board_name' with profile 'debianforumde'...\n";
+
+// Load and run the create module
+require("{$quickinstall_path}modules/qi_create.$phpEx");
+
+$create_module = new qi_create();
+$create_module->run();
+
+echo "Board '$board_name' created successfully!\n";