getMessage() . PHP_EOL; return null; } } if (file_exists("/var/www/app/config.php")) { echo "Loading config.php" . PHP_EOL; require_once "/var/www/app/config.php"; $pdo = pdo_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_TYPE, DB_PORT); if (!$pdo) { exit(2); } echo "Running sanity check."; $errors = sanity_check(DB_TYPE); if (count($errors) > 0) { foreach ($errors as $error) { echo "$error"; } } echo "Connected to the database" . PHP_EOL; $res = $pdo->query("SELECT true FROM ttrss_feeds"); if ($res && $res->fetch()) { echo "Some tt-rss data already exists in this database, skipping database installation" . PHP_EOL; exit(0); } echo "tt-rss data not found, initializing the database" . PHP_EOL; $lines = explode(";", preg_replace("/[\r\n]/", "", file_get_contents("/var/www/app/schema/ttrss_schema_".basename(DB_TYPE).".sql"))); $dbInitError = 0; foreach ($lines as $line) { if (strpos($line, "--") !== 0 && $line) { $res = $pdo->query($line); if (!$res) { echo "Query: $line" . PHP_EOL; echo "Error: " . implode(", ", $this->pdo->errorInfo()) . PHP_EOL; $dbInitError++; } } } if($dbInitError == 0) { echo "Database initialization completed." . PHP_EOL; exit(0); } else { echo "Database initialization failed." . PHP_EOL; exit(1); } }