public static function checkUpgrade()
 {
     if (OC_Config::getValue('installed', false)) {
         $installedVersion = OC_Config::getValue('version', '0.0.0');
         $currentVersion = implode('.', OC_Util::getVersion());
         if (version_compare($currentVersion, $installedVersion, '>')) {
             OC_Log::write('core', 'starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, OC_Log::DEBUG);
             $result = OC_DB::updateDbFromStructure(OC::$SERVERROOT . '/db_structure.xml');
             if (!$result) {
                 echo 'Error while upgrading the database';
                 die;
             }
             if (file_exists(OC::$SERVERROOT . "/config/config.php") and !is_writable(OC::$SERVERROOT . "/config/config.php")) {
                 $tmpl = new OC_Template('', 'error', 'guest');
                 $tmpl->assign('errors', array(1 => array('error' => "Can't write into config directory 'config'", 'hint' => "You can usually fix this by giving the webserver user write access to the config directory in owncloud")));
                 $tmpl->printPage();
                 exit;
             }
             OC_Config::setValue('version', implode('.', OC_Util::getVersion()));
         }
         OC_App::updateApps();
     }
 }