Parcourir la source

Fixed apps loading order

On SQLite the app order can be arbitrary and cause strange bugs.
On MySQL, the app order seems to be always alphabetical.

This fix enforces alphabetical order to make sure that all environments
behave the same and to reduce bugs related to app loading order.

Fixes #6442
tags/v7.0.0alpha2
Vincent Petry il y a 10 ans
Parent
révision
c6377e9125
4 fichiers modifiés avec 21 ajouts et 6 suppressions
  1. 6
    4
      lib/private/app.php
  2. 1
    1
      lib/private/appconfig.php
  3. 13
    0
      tests/lib/app.php
  4. 1
    1
      tests/lib/appconfig.php

+ 6
- 4
lib/private/app.php Voir le fichier

* get all enabled apps * get all enabled apps
*/ */
private static $enabledAppsCache = array(); private static $enabledAppsCache = array();
public static function getEnabledApps() {
public static function getEnabledApps($forceRefresh = false) {
if(!OC_Config::getValue('installed', false)) { if(!OC_Config::getValue('installed', false)) {
return array(); return array();
} }
if(!empty(self::$enabledAppsCache)) {
if(!$forceRefresh && !empty(self::$enabledAppsCache)) {
return self::$enabledAppsCache; return self::$enabledAppsCache;
} }
$apps=array('files'); $apps=array('files');
$sql = 'SELECT `appid` FROM `*PREFIX*appconfig`' $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') { if (OC_Config::getValue( 'dbtype', 'sqlite' ) === 'oci') {
//FIXME oracle hack: need to explicitly cast CLOB to CHAR for comparison //FIXME oracle hack: need to explicitly cast CLOB to CHAR for comparison
$sql = 'SELECT `appid` FROM `*PREFIX*appconfig`' $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 ); $query = OC_DB::prepare( $sql );
$result=$query->execute(); $result=$query->execute();

+ 1
- 1
lib/private/appconfig.php Voir le fichier

*/ */
public static function getApps() { public static function getApps() {
// No magic in here! // 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(); $result = $query->execute();


$apps = array(); $apps = array();

+ 13
- 0
tests/lib/app.php Voir le fichier

$this->assertFalse(OC_App::isAppVersionCompatible($oc, $app)); $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);
}
} }

+ 1
- 1
tests/lib/appconfig.php Voir le fichier

} }


public function testGetApps() { 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(); $result = $query->execute();
$expected = array(); $expected = array();
while ($row = $result->fetchRow()) { while ($row = $result->fetchRow()) {

Chargement…
Annuler
Enregistrer