diff --git a/lib/private/app.php b/lib/private/app.php
index eca40a81cc14c9e9576fdcc958ace8143598b74a..34c00e97fb9462eaf40272a2600c2d109ed4c03a 100644
--- a/lib/private/app.php
+++ b/lib/private/app.php
@@ -166,20 +166,22 @@ class OC_App{
 	 * get all enabled apps
 	 */
 	private static $enabledAppsCache = array();
-	public static function getEnabledApps() {
+	public static function getEnabledApps($forceRefresh = false) {
 		if(!OC_Config::getValue('installed', false)) {
 			return array();
 		}
-		if(!empty(self::$enabledAppsCache)) {
+		if(!$forceRefresh && !empty(self::$enabledAppsCache)) {
 			return self::$enabledAppsCache;
 		}
 		$apps=array('files');
 		$sql = 'SELECT `appid` FROM `*PREFIX*appconfig`'
-			.' WHERE `configkey` = \'enabled\' AND `configvalue`=\'yes\'';
+			. ' WHERE `configkey` = \'enabled\' AND `configvalue`=\'yes\''
+			. ' ORDER BY `appid`';
 		if (OC_Config::getValue( 'dbtype', 'sqlite' ) === 'oci') {
 			//FIXME oracle hack: need to explicitly cast CLOB to CHAR for comparison
 			$sql = 'SELECT `appid` FROM `*PREFIX*appconfig`'
-			.' WHERE `configkey` = \'enabled\' AND to_char(`configvalue`)=\'yes\'';
+			. ' WHERE `configkey` = \'enabled\' AND to_char(`configvalue`)=\'yes\''
+			. ' ORDER BY `appid`';
 		}
 		$query = OC_DB::prepare( $sql );
 		$result=$query->execute();
diff --git a/lib/private/appconfig.php b/lib/private/appconfig.php
index dfe03698059b79f23d8f11feb335bf8b650fc88a..da0b2ff8604ea472384d090060541b26d2cfdf2b 100644
--- a/lib/private/appconfig.php
+++ b/lib/private/appconfig.php
@@ -52,7 +52,7 @@ class OC_Appconfig {
 	 */
 	public static function getApps() {
 		// No magic in here!
-		$query = OC_DB::prepare('SELECT DISTINCT `appid` FROM `*PREFIX*appconfig`');
+		$query = OC_DB::prepare('SELECT DISTINCT `appid` FROM `*PREFIX*appconfig` ORDER BY `appid`');
 		$result = $query->execute();
 
 		$apps = array();
diff --git a/tests/lib/app.php b/tests/lib/app.php
index 52eade90a6e1ea2f99db6e83e6adec3c5848c84a..49f40f089bb8e1b5c65d53451b5cbdc0d16aa49f 100644
--- a/tests/lib/app.php
+++ b/tests/lib/app.php
@@ -79,4 +79,17 @@ class Test_App extends PHPUnit_Framework_TestCase {
 		$this->assertFalse(OC_App::isAppVersionCompatible($oc, $app));
 	}
 
+	/**
+	 * Tests that the app order is correct
+	 */
+	public function testGetEnabledAppsIsSorted() {
+		$apps = \OC_App::getEnabledApps(true);
+		// copy array
+		$sortedApps = $apps;
+		sort($sortedApps);
+		// 'files' is always on top
+		unset($sortedApps[array_search('files', $sortedApps)]);
+		array_unshift($sortedApps, 'files');
+		$this->assertEquals($sortedApps, $apps);
+	}
 }
diff --git a/tests/lib/appconfig.php b/tests/lib/appconfig.php
index 4d82cd5ba7b8b52fa37e23260ab90f7df7e010b8..23dd2549e32b6cb2d57c41a7aab2915175b9d4d5 100644
--- a/tests/lib/appconfig.php
+++ b/tests/lib/appconfig.php
@@ -35,7 +35,7 @@ class Test_Appconfig extends PHPUnit_Framework_TestCase {
 	}
 
 	public function testGetApps() {
-		$query = \OC_DB::prepare('SELECT DISTINCT `appid` FROM `*PREFIX*appconfig`');
+		$query = \OC_DB::prepare('SELECT DISTINCT `appid` FROM `*PREFIX*appconfig` ORDER BY `appid`');
 		$result = $query->execute();
 		$expected = array();
 		while ($row = $result->fetchRow()) {