$res = Database::RunFolder($root . '/protected/install/database/schema/'); if (true !== $res) { throw new Exception('Error loading database schema:<br/><div class="nested-error">' . $res . '</div>'); } // Save the new version @file_put_contents($root . '/protected/install/database/version', DATABASE_VERSION); Check::good('[' . date('H:i:s') . '] Loaded database schema.'); $subs = array('username' => $_POST['config_username'], 'userpass' => md5($_POST['config_password'])); $res = Database::RunFile($root . '/protected/install/database/data/add_user.sql', $subs); if (true !== $res) { throw new Exception('Error loading database data:<br/><div class="nested-error">' . $res . '</div>'); } Check::good('[' . date('H:i:s') . '] Loaded database data.'); $substitutions = array('mysql_host' => $_POST['mysql_host'], 'mysql_database' => $_POST['mysql_database'], 'mysql_password' => $_POST['mysql_password'], 'mysql_username' => $_POST['mysql_user'], 'security_cookie' => sha1(time() . $_SERVER['SERVER_NAME']), 'host' => $_SERVER['SERVER_NAME'], 'path' => $_SERVER['REQUEST_URI'], 'user' => $_POST['config_username'], 'flickr_comment' => empty($_POST['config_flickr_api_key']) ? ';' : '', 'flickr_key' => $_POST['config_flickr_api_key'], 'google_map_comment' => empty($_POST['config_google_maps_api_key']) ? ';' : '', 'google_map_key' => $_POST['config_google_maps_api_key']); if (Config::SaveFile($root . '/protected/install/config.ini.template', $root . '/protected/config/config.ini', $substitutions)) { Check::good('[' . date('H:i:s') . '] Saved config file.'); } else { $_SESSION['config'] = Config::RenderFile($root . '/protected/install/config.ini.template', $substitutions); Check::warn("Could not write config.ini.<br/>Please below to download your config file and place it in <tt>protected/config/</tt>.<br/><a href=\"?config\">Download config.ini</a>"); } print "<p>Installation Complete!</p>"; print "<p>Please remove or rename protected/install/install.php</p>"; print '<p>Go To: <a href="http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] . '/admin">Administration</a> or <a href="http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] . '">Front Page</a></p>'; return 'Installation'; } else { throw new Exception('Your configuration has errors, please see below.'); } } catch (Exception $e) { Check::bad($e->getMessage()); Check::restart(); }
// Connect to the database $res = Database::Connect($config->db->host, $config->db->dbname, $config->db->username, $config->db->password); if (true !== $res) { throw new Exception('Error connecting to the database:<br/><div class="nested-error">' . $res . '</div>'); } // If version = 0, run the initial schema if ($current_version == 0) { $res = Database::RunFolder($root . '/protected/install/database/schema/'); if (true !== $res) { throw new Exception('Error loading database schema:<br/><div class="nested-error">' . $res . '</div>'); } } // Run the update scripts while ($current_version < DATABASE_VERSION) { $next_version = $current_version + 1; $folder = sprintf($root . '/protected/install/database/update/%03d/', $next_version); $res = Database::RunFolder($folder); if (true !== $res) { throw new Exception('Error running database upgrade script:<br/><div class="nested-error">' . $res . '</div><p>While processing folder ' . $folder . '</p>'); } // Save the new version and move to the next one @file_put_contents($root . '/protected/install/database/version', $next_version); Check::good("Applied upgrade script to version {$next_version}."); $current_version++; } // Done ! Check::good("Successfully upgraded the database !"); } catch (Exception $e) { Check::bad($e->getMessage()); } return "Database upgrade";
public static function PathWritable($path, $warn_only = false) { $root = dirname(__FILE__) . '/../../'; if (is_writable($root . $path)) { Check::good("{$path} is writable."); } else { if ($warn_only) { Check::warn("{$path} is not writable."); } else { Check::bad("{$path} is not writable."); } } }