public function __construct() { /** * Explicitly set the locale to C (POSIX) for all categories so there hopefully * won't be any unexpected results between platforms. */ setlocale(LC_ALL, 'C'); /** * Use the default value until a user specified timezone is loaded. */ date_default_timezone_set($this->timezone); /** * Read options from the command line. Print the manual on invalid input. */ $options = getopt('b:c:e:i:n:o:s'); ksort($options); $options_keys = implode('', array_keys($options)); if (!preg_match('/^(bc?i?o|c|c?(e|i|i?o|n|s))$/', $options_keys)) { $this->print_manual(); } /** * Some options require additional settings to be set in the configuration file. * Add those to the list. */ if (array_key_exists('i', $options)) { array_push($this->settings_list_required, 'parser', 'logfile_dateformat'); } if (array_key_exists('o', $options) || array_key_exists('s', $options)) { $this->settings_list_required[] = 'channel'; } /** * Read the configuration file. */ if (array_key_exists('c', $options)) { $this->read_config($options['c']); } else { $this->read_config(dirname(__FILE__) . '/sss.conf'); } /** * After the configuration file has been read we can update the used timezone * and the level of console output messages with user specified values. */ if (!date_default_timezone_set($this->timezone)) { output::output('critical', __METHOD__ . '(): invalid timezone: \'' . $this->timezone . '\''); } /** * Prior to having the updated value of $outputbits take effect there were no * message types other than critical events, which cannot be suppressed. */ output::set_outputbits($this->outputbits); /** * Export settings from the configuration file in the format vars.php accepts * them. */ if (array_key_exists('s', $options)) { $this->export_settings(); } /** * Open the database connection. Always needed from this point forward. */ try { $sqlite3 = new SQLite3($this->database, SQLITE3_OPEN_READWRITE); $sqlite3->busyTimeout(60000); } catch (Exception $e) { output::output('critical', basename(__FILE__) . ':' . __LINE__ . ', sqlite3 says: ' . $e->getMessage()); } /** * Set SQLite3 PRAGMAs: * journal_mode = OFF - Disable the rollback journal completely. * synchronous = OFF - Continue without syncing as soon as data is handed off * to the operating system. * temp_store = MEMORY - Temporary tables and indices are kept in memory. */ $pragmas = ['journal_mode' => 'OFF', 'synchronous' => 'OFF', 'temp_store' => 'MEMORY']; foreach ($pragmas as $key => $value) { $sqlite3->exec('PRAGMA ' . $key . ' = ' . $value); } output::output('notice', __METHOD__ . '(): succesfully connected to database: \'' . $this->database . '\''); /** * The following options are listed in order of execution. Ie. "i" before "o", * "b" before "o". */ if (array_key_exists('b', $options) && preg_match('/^\\d+$/', $options['b'])) { $this->settings['sectionbits'] = (int) $options['b']; } if (array_key_exists('e', $options)) { $this->export_nicks($sqlite3, $options['e']); } if (array_key_exists('i', $options)) { $this->parse_log($sqlite3, $options['i']); } if (array_key_exists('n', $options)) { $this->import_nicks($sqlite3, $options['n']); /** * Run maintenance after import. */ $this->do_maintenance($sqlite3); } if (array_key_exists('o', $options)) { $this->make_html($sqlite3, $options['o']); } $sqlite3->close(); output::output('notice', __METHOD__ . '(): kthxbye'); }