[Pkg-owncloud-commits] [owncloud] 98/121: extract upgrade parts to their own methods

David Prévot taffit at moszumanska.debian.org
Thu Aug 21 16:44:39 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud.

commit d9008f8ae4529c2ce8ca5803ffc93cb053120da9
Author: Robin Appelman <icewind at owncloud.com>
Date:   Thu Jul 24 17:18:54 2014 +0200

    extract upgrade parts to their own methods
---
 lib/private/updater.php | 81 +++++++++++++++++++++++++++++++++++++------------
 1 file changed, 62 insertions(+), 19 deletions(-)

diff --git a/lib/private/updater.php b/lib/private/updater.php
index 7acd644..029664c 100644
--- a/lib/private/updater.php
+++ b/lib/private/updater.php
@@ -7,6 +7,7 @@
  */
 
 namespace OC;
+
 use OC\Hooks\BasicEmitter;
 
 /**
@@ -61,6 +62,7 @@ class Updater extends BasicEmitter {
 
 	/**
 	 * Check if a new version is available
+	 *
 	 * @param string $updaterUrl the url to check, i.e. 'http://apps.owncloud.com/updater.php'
 	 * @return array|bool
 	 */
@@ -161,7 +163,7 @@ class Updater extends BasicEmitter {
 		// create empty file in data dir, so we can later find
 		// out that this is indeed an ownCloud data directory
 		// (in case it didn't exist before)
-		file_put_contents(\OC_Config::getValue('datadirectory', \OC::$SERVERROOT.'/data').'/.ocdata', '');
+		file_put_contents(\OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', '');
 
 		/*
 		 * START CONFIG CHANGES FOR OLDER VERSIONS
@@ -182,22 +184,11 @@ class Updater extends BasicEmitter {
 
 		// simulate DB upgrade
 		if ($this->simulateStepEnabled) {
-			// simulate core DB upgrade
-			\OC_DB::simulateUpdateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml');
+			$this->checkCoreUpgrade();
 
 			// simulate apps DB upgrade
-			$version = \OC_Util::getVersion();
-			$apps = \OC_App::getEnabledApps();
-			foreach ($apps as $appId) {
-				$info = \OC_App::getAppInfo($appId);
-				if (\OC_App::isAppCompatible($version, $info) && \OC_App::shouldUpgrade($appId)) {
-					if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/database.xml')) {
-						\OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId) . '/appinfo/database.xml');
-					}
-				}
-			}
+			$this->checkAppUpgrade($currentVersion);
 
-			$this->emit('\OC\Updater', 'dbSimulateUpgrade');
 		}
 
 		// upgrade from OC6 to OC7
@@ -208,16 +199,14 @@ class Updater extends BasicEmitter {
 		}
 
 		if ($this->updateStepEnabled) {
-			// do the real upgrade
-			\OC_DB::updateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml');
-			$this->emit('\OC\Updater', 'dbUpgrade');
+			$this->doCoreUpgrade();
 
 			$disabledApps = \OC_App::checkAppsRequirements();
 			if (!empty($disabledApps)) {
 				$this->emit('\OC\Updater', 'disabledApps', array($disabledApps));
 			}
-			// load all apps to also upgrade enabled apps
-			\OC_App::loadApps();
+
+			$this->doAppUpgrade();
 
 			// post-upgrade repairs
 			$repair = new \OC\Repair(\OC\Repair::getRepairSteps());
@@ -230,5 +219,59 @@ class Updater extends BasicEmitter {
 			\OC_Config::setValue('version', implode('.', \OC_Util::getVersion()));
 		}
 	}
+
+	protected function checkCoreUpgrade() {
+		// simulate core DB upgrade
+		\OC_DB::simulateUpdateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml');
+
+		$this->emit('\OC\Updater', 'dbSimulateUpgrade');
+	}
+
+	protected function doCoreUpgrade() {
+		\OC_Config::setValue('version', implode('.', \OC_Util::getVersion()));
+
+		// do the real upgrade
+		\OC_DB::updateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml');
+
+		$this->emit('\OC\Updater', 'dbUpgrade');
+	}
+
+	/**
+	 * @param string $version the oc version to check app compatibilty with
+	 */
+	protected function checkAppUpgrade($version) {
+		$apps = \OC_App::getEnabledApps();
+
+
+		foreach ($apps as $appId) {
+			if ($version) {
+				$info = \OC_App::getAppInfo($appId);
+				$compatible = \OC_App::isAppCompatible($version, $info);
+			} else {
+				$compatible = true;
+			}
+
+			if ($compatible && \OC_App::shouldUpgrade($appId)) {
+				if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/database.xml')) {
+					\OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId) . '/appinfo/database.xml');
+				}
+			}
+		}
+
+		$this->emit('\OC\Updater', 'appUpgradeCheck');
+	}
+
+	protected function doAppUpgrade() {
+		$apps = \OC_App::getEnabledApps();
+
+		foreach ($apps as $appId) {
+			if (\OC_App::shouldUpgrade($appId)) {
+				\OC_App::updateApp($appId);
+				$version = \OC_App::getAppVersion($appId);
+				\OC_Appconfig::setValue($appId, 'installed_version', $version);
+				$this->emit('\OC\Updater', 'appUpgrade', array($appId, $version));
+			}
+		}
+	}
 }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list