Merge pull request #1384 from owncloud/upgrade_fix

Check for upgrade/maintance mode before trying to load an app
This commit is contained in:
Bart Visscher 2013-02-01 07:12:06 -08:00
commit 2488a495c6
1 changed files with 53 additions and 70 deletions

View File

@ -27,8 +27,7 @@ require_once 'public/constants.php';
* No, we can not put this class in its own file because it is used by
* OC_autoload!
*/
class OC
{
class OC {
/**
* Associative array for autoloading. classname => filename
*/
@ -78,8 +77,7 @@ class OC
/**
* SPL autoload
*/
public static function autoload($className)
{
public static function autoload($className) {
if (array_key_exists($className, OC::$CLASSPATH)) {
$path = OC::$CLASSPATH[$className];
/** @TODO: Remove this when necessary
@ -96,7 +94,7 @@ class OC
} elseif (strpos($className, 'OCP\\') === 0) {
$path = 'public/' . strtolower(str_replace('\\', '/', substr($className, 3)) . '.php');
} elseif (strpos($className, 'OCA\\') === 0) {
foreach(self::$APPSROOTS as $appDir) {
foreach (self::$APPSROOTS as $appDir) {
$path = $appDir['path'] . '/' . strtolower(str_replace('\\', '/', substr($className, 3)) . '.php');
$fullPath = stream_resolve_include_path($path);
if (file_exists($fullPath)) {
@ -124,8 +122,7 @@ class OC
return false;
}
public static function initPaths()
{
public static function initPaths() {
// calculate the root directories
OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4));
OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT)));
@ -188,8 +185,9 @@ class OC
exit;
}
$paths = array();
foreach (OC::$APPSROOTS as $path)
foreach (OC::$APPSROOTS as $path) {
$paths[] = $path['path'];
}
// set the right include path
set_include_path(
@ -211,8 +209,7 @@ class OC
}
}
public static function checkInstalled()
{
public static function checkInstalled() {
// Redirect to installer if not installed
if (!OC_Config::getValue('installed', false) && OC::$SUBURI != '/index.php') {
if (!OC::$CLI) {
@ -223,8 +220,7 @@ class OC
}
}
public static function checkSSL()
{
public static function checkSSL() {
// redirect to https site if configured
if (OC_Config::getValue("forcessl", false)) {
header('Strict-Transport-Security: max-age=31536000');
@ -274,8 +270,7 @@ class OC
}
}
public static function initTemplateEngine()
{
public static function initTemplateEngine() {
// Add the stuff we need always
OC_Util::addScript("jquery-1.7.2.min");
OC_Util::addScript("jquery-ui-1.10.0.custom");
@ -297,8 +292,7 @@ class OC
OC_Util::addScript("oc-requesttoken");
}
public static function initSession()
{
public static function initSession() {
// prevents javascript from accessing php session cookies
ini_set('session.cookie_httponly', '1;');
@ -328,8 +322,7 @@ class OC
$_SESSION['LAST_ACTIVITY'] = time();
}
public static function getRouter()
{
public static function getRouter() {
if (!isset(OC::$router)) {
OC::$router = new OC_Router();
OC::$router->loadRoutes();
@ -339,19 +332,17 @@ class OC
}
public static function loadAppClassPaths()
{
foreach(OC_APP::getEnabledApps() as $app) {
$file = OC_App::getAppPath($app).'/appinfo/classpath.php';
if(file_exists($file)) {
public static function loadAppClassPaths() {
foreach (OC_APP::getEnabledApps() as $app) {
$file = OC_App::getAppPath($app) . '/appinfo/classpath.php';
if (file_exists($file)) {
require_once $file;
}
}
}
public static function init()
{
public static function init() {
// register autoloader
spl_autoload_register(array('OC', 'autoload'));
setlocale(LC_ALL, 'en_US.UTF-8');
@ -516,8 +507,7 @@ class OC
/**
* register hooks for the cache
*/
public static function registerCacheHooks()
{
public static function registerCacheHooks() {
// register cache cleanup jobs
OC_BackgroundJob_RegularTask::register('OC_Cache_FileGlobal', 'gc');
OC_Hook::connect('OC_User', 'post_login', 'OC_Cache_File', 'loginListener');
@ -526,8 +516,7 @@ class OC
/**
* register hooks for the filesystem
*/
public static function registerFilesystemHooks()
{
public static function registerFilesystemHooks() {
// Check for blacklisted files
OC_Hook::connect('OC_Filesystem', 'write', 'OC_Filesystem', 'isBlacklisted');
OC_Hook::connect('OC_Filesystem', 'rename', 'OC_Filesystem', 'isBlacklisted');
@ -536,8 +525,7 @@ class OC
/**
* register hooks for sharing
*/
public static function registerShareHooks()
{
public static function registerShareHooks() {
OC_Hook::connect('OC_User', 'post_deleteUser', 'OCP\Share', 'post_deleteUser');
OC_Hook::connect('OC_User', 'post_addToGroup', 'OCP\Share', 'post_addToGroup');
OC_Hook::connect('OC_User', 'post_removeFromGroup', 'OCP\Share', 'post_removeFromGroup');
@ -547,12 +535,22 @@ class OC
/**
* @brief Handle the request
*/
public static function handleRequest()
{
public static function handleRequest() {
// load all the classpaths from the enabled apps so they are available
// in the routing files of each app
OC::loadAppClassPaths();
// Check if ownCloud is installed or in maintenance (update) mode
if (!OC_Config::getValue('installed', false)) {
require_once 'core/setup.php';
exit();
}
$request = OC_Request::getPathInfo();
if(substr($request, -3) !== '.js'){// we need these files during the upgrade
self::checkMaintenanceMode();
self::checkUpgrade();
}
try {
OC::getRouter()->match(OC_Request::getPathInfo());
return;
@ -562,6 +560,7 @@ class OC
OC_Response::setStatus(405);
return;
}
$app = OC::$REQUESTEDAPP;
$file = OC::$REQUESTEDFILE;
$param = array('app' => $app, 'file' => $file);
@ -571,14 +570,6 @@ class OC
return;
}
// Check if ownCloud is installed or in maintenance (update) mode
if (!OC_Config::getValue('installed', false)) {
require_once 'core/setup.php';
exit();
}
self::checkMaintenanceMode();
self::checkUpgrade();
// Handle redirect URL for logged in users
if (isset($_REQUEST['redirect_url']) && OC_User::isLoggedIn()) {
$location = OC_Helper::makeURLAbsolute(urldecode($_REQUEST['redirect_url']));
@ -618,8 +609,7 @@ class OC
self::handleLogin();
}
public static function loadAppScriptFile($param)
{
public static function loadAppScriptFile($param) {
OC_App::loadApps();
$app = $param['app'];
$file = $param['file'];
@ -633,8 +623,7 @@ class OC
return false;
}
public static function loadCSSFile($param)
{
public static function loadCSSFile($param) {
$app = $param['app'];
$file = $param['file'];
$app_path = OC_App::getAppPath($app);
@ -647,8 +636,7 @@ class OC
}
}
protected static function handleLogin()
{
protected static function handleLogin() {
OC_App::loadApps(array('prelogin'));
$error = array();
// remember was checked after last login
@ -666,8 +654,7 @@ class OC
OC_Util::displayLoginPage(array_unique($error));
}
protected static function cleanupLoginTokens($user)
{
protected static function cleanupLoginTokens($user) {
$cutoff = time() - OC_Config::getValue('remember_login_cookie_lifetime', 60 * 60 * 24 * 15);
$tokens = OC_Preferences::getKeys($user, 'login_token');
foreach ($tokens as $token) {
@ -678,8 +665,7 @@ class OC
}
}
protected static function tryRememberLogin()
{
protected static function tryRememberLogin() {
if (!isset($_COOKIE["oc_remember_login"])
|| !isset($_COOKIE["oc_token"])
|| !isset($_COOKIE["oc_username"])
@ -719,8 +705,7 @@ class OC
return true;
}
protected static function tryFormLogin()
{
protected static function tryFormLogin() {
if (!isset($_POST["user"]) || !isset($_POST['password'])) {
return false;
}
@ -753,8 +738,7 @@ class OC
return true;
}
protected static function tryBasicAuthLogin()
{
protected static function tryBasicAuthLogin() {
if (!isset($_SERVER["PHP_AUTH_USER"])
|| !isset($_SERVER["PHP_AUTH_PW"])
) {
@ -778,8 +762,7 @@ if (!isset($RUNTIME_NOAPPS)) {
}
if (!function_exists('get_temp_dir')) {
function get_temp_dir()
{
function get_temp_dir() {
if ($temp = ini_get('upload_tmp_dir')) return $temp;
if ($temp = getenv('TMP')) return $temp;
if ($temp = getenv('TEMP')) return $temp;