#!/usr/bin/php getParameterOption(['--site']) ?: null; } try { $bypass_siteclose_check = true; require_once 'tiki-setup.php'; if (Installer::getInstance()->requiresUpdate()) { throw new ConsoleSetupException('Database Needs updating', 1004); } /** * @var int The code representing different stages of Tki functioning. Each builds on the next. * Auto-loading is always present. Most codes show progressive stages of tiki-setup.php being loaded. * * 1001 - No database available. (we are running in auto-load only mode) * * 1002 - Database connected, but tiki not installed. * * 1003 - Tiki-Setup stopped by Database errors - probably because the database needs updating (and database initialized) * * 1004 - Tiki-Setup completed successfully (but the database is not up to date) * * 1100 - The database is up to date (and Tiki-setup completed successfully) */ $statusCode = 1100; // this code denotes everything works perfectly :) } catch (ConsoleSetupException $e) { $statusCode = $e->getCode(); } catch (Throwable $e) { $statusCode = 1001; $exceptionToRender = $e; } /** * Define our constants, based on what error (if any) was thrown * @see $statusCode For explanations on what these constants these do. */ define('DB_RUNNING', $statusCode > 1001); define('DB_STATUS', $statusCode > 1002); define('DB_TIKI_SETUP', $statusCode > 1003); define('DB_SYNCHRONAL', $statusCode > 1004); if (DB_TIKI_SETUP) { $asUser = $input->getParameterOption(['--as-user']) ?: 'admin'; if (TikiLib::lib('user')->user_exists($asUser)) { $permissionContext = new Perms_Context($asUser); } } $exitCode = 0; $output = new ConsoleOutput(); $console = new ConsoleApplicationBuilder(); $console = $console->create(); $console->setAutoExit(false); try { $exitCode = $console->run(null, $output); } catch (Throwable $e) { $output->writeln('A error was encountered while running a command'); TikiLib::lib('errortracking')->captureException($e); if ($e instanceof Exception) { $console->renderException($e, $output); } else { $output->write('' . $e->getMessage() . ' on line ' . $e->getLine() . ' of ' . $e->getFile()); } } $output->writeln(''); if ($input->getFirstArgument() === null) { $output->write('Tiki-Files-Installed->'); $output->write((DB_RUNNING ? '' : '') . 'DB-Running->'); $output->write((DB_STATUS ? '' : '') . 'DB-Installed->'); $output->write((DB_TIKI_SETUP ? '' : '') . 'DB-Initialized->'); $output->writeln((DB_SYNCHRONAL ? '' : '') . 'DB-in-Sync'); $output->writeln(''); $output->writeln('To run a specific command (with default values): php console.php index:rebuild'); $output->writeln('To get more help on a specific command, use the following pattern: php console.php index:rebuild --help'); $output->writeln(''); } if (isset($exceptionToRender)) { $output->writeln('An unexpected error interrupted console initialization'); if ($e instanceof Exception) { $console->renderException($e, $output); } else { $output->write('' . $e->getMessage() . ' on line ' . $e->getLine() . ' of ' . $e->getFile()); } } /** * Errors while using the console can be difficult because they normally end with the command providing no input. * Here we attempt to provide some feedback to the user so failed commands are not as cryptic. * * IF the error is not fatal, then we log it in PHP's error log (like it would have been done without this error handling) * * @param $number int Error number (type of error) provided * @param $message string Error Message provided * @param $file string The file name that the error occurred on * @param $line string The line number that the error occurred on * * @throws ErrorException When a fatal error is encountered */ function custom_error_handler($number, $message, $file, $line): void { if (0 === error_reporting()) { // This error was triggered when evaluating an expression prepended by the at sign (@) error control operator, but since we are in a custom error handler, we have to ignore it manually. // See http://ca3.php.net/manual/en/language.operators.errorcontrol.php#98895 and http://php.net/set_error_handler return; } // Determine if this error is one of the enabled ones in php config (php.ini, .htaccess, etc) $error_is_enabled = (bool)($number & (int)ini_get('error_reporting')); // Fatal Errors // throw an Error Exception, to be handled by whatever Exception handling logic is available in this context if (in_array($number, [E_USER_ERROR, E_RECOVERABLE_ERROR]) && $error_is_enabled) { throw new ErrorException($message, 0, $number, $file, $line); } // Non-Fatal Errors (ERROR/WARNING/NOTICE) // Log the error if it's enabled, otherwise just ignore it if ($error_is_enabled) { error_log($message . ' on line ' . $line . ' of ' . $file, 0); } } exit($exitCode);