]> source.dussan.org Git - nextcloud-server.git/commitdiff
adding supported databases
authorThomas Müller <thomas.mueller@tmit.eu>
Mon, 1 Dec 2014 22:43:27 +0000 (23:43 +0100)
committerThomas Müller <thomas.mueller@tmit.eu>
Thu, 4 Dec 2014 10:40:33 +0000 (11:40 +0100)
lib/private/app/dependencyanalyzer.php
lib/private/app/platform.php
settings/controller/appsettingscontroller.php
tests/data/app/expected-info.json
tests/data/app/valid-info.xml
tests/lib/app/dependencyanalyzer.php

index c76181926e2141268cde003ce5cca1085999a7a0..7fd181c076c87a2c116eac3e1ad4f8d320a375b8 100644 (file)
@@ -33,6 +33,7 @@ class DependencyAnalyzer {
         */
        public function analyze() {
                $this->analysePhpVersion();
+               $this->analyseSupportedDatabases();
                return $this->missing;
        }
 
@@ -55,4 +56,19 @@ class DependencyAnalyzer {
                }
        }
 
+       private function analyseSupportedDatabases() {
+               if (!array_key_exists('database', $this->dependencies)) {
+                       return;
+               }
+
+               $supportedDatabases = $this->dependencies['database'];
+               if (empty($supportedDatabases)) {
+                       return;
+               }
+               $currentDatabase = $this->system->getDatabase();
+               if (!in_array($currentDatabase, $supportedDatabases)) {
+                       $this->missing[] = (string)$this->l->t('Following databases are supported: %s', join(', ', $supportedDatabases));
+               }
+       }
+
 }
index 292159337a0fa7385eb3fe1065063083aca783c9..39f8a2979f9267cc3fd3e016378c6ebd64ff5329 100644 (file)
 
 namespace OC\App;
 
+use OCP\IConfig;
+
 class Platform {
+
+       function __construct(IConfig $config) {
+               $this->config = $config;
+       }
+
        public function getPhpVersion() {
                return phpversion();
        }
+
+       public function getDatabase() {
+               $dbType = $this->config->getSystemValue('dbtype', 'sqlite');
+               if ($dbType === 'sqlite3') {
+                       $dbType = 'sqlite';
+               }
+
+               return $dbType;
+       }
 }
index 1f7e3b259fedec8947f1e5cba16867d544e039ed..3ad52bd2187ee9577eea85125748e72fb99394bb 100644 (file)
@@ -127,7 +127,7 @@ class AppSettingsController extends Controller {
                        $app['canUnInstall'] = !$app['active'] && $app['removable'];
 
                        // analyse dependencies
-                       $dependencyAnalyzer = new DependencyAnalyzer($app, new Platform(), $this->l10n);
+                       $dependencyAnalyzer = new DependencyAnalyzer($app, new Platform($this->config), $this->l10n);
                        $missing = $dependencyAnalyzer->analyze();
 
                        $app['canInstall'] = empty($missing);
index 50e81a48fd260ed72bfbf96eecbf56be04b45e3d..9be6062220ffe9c6eb446d96e5e7baffa6b633c6 100644 (file)
@@ -19,6 +19,7 @@
        "dependencies": {
                "php": {
                        "min-version": 5.4
-               }
+               },
+               "database":["sqlite", "mysql"]
        }
 }
index 81abb2769022a1f026efd4a99bc7c6674fd2bb51..3a40e62d147fdfdc9186e3ef45b810e184a9bb9e 100644 (file)
        </types>
        <ocsid>166047</ocsid>
        <dependencies>
-               <php><min-version>5.4</min-version></php>
+               <php>
+                       <min-version>5.4</min-version>
+               </php>
+               <database>sqlite</database>
+               <database>mysql</database>
        </dependencies>
 </info>
index d0c2919f47a351ae45ee039fb20d1793353756aa..25f2ad8caa87e4db42513335fdbe81f882d09c6f 100644 (file)
@@ -27,10 +27,14 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase {
 
        public function setUp() {
                $this->platformMock = $this->getMockBuilder('\OC\App\Platform')
+                       ->disableOriginalConstructor()
                        ->getMock();
                $this->platformMock->expects($this->any())
                        ->method('getPhpVersion')
                        ->will( $this->returnValue('5.4.3'));
+               $this->platformMock->expects($this->any())
+                       ->method('getDatabase')
+                       ->will( $this->returnValue('mysql'));
                $this->l10nMock = $this->getMockBuilder('\OCP\IL10N')
                        ->disableOriginalConstructor()
                        ->getMock();
@@ -64,6 +68,34 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase {
                $this->assertEquals($expectedMissing, $missing);
        }
 
+       /**
+        * @dataProvider providesDatabases
+        */
+       public function testDatabases($expectedMissing, $databases) {
+               $app = array(
+                       'dependencies' => array(
+                       )
+               );
+               if (!is_null($databases)) {
+                       $app['dependencies']['database'] = $databases;
+               }
+               $analyser = new \OC\App\DependencyAnalyzer($app, $this->platformMock, $this->l10nMock);
+               $missing = $analyser->analyze();
+
+               $this->assertTrue(is_array($missing));
+               $this->assertEquals(count($expectedMissing), count($missing));
+               $this->assertEquals($expectedMissing, $missing);
+       }
+
+       function providesDatabases() {
+               return array(
+                       // non BC - in case on databases are defined -> all are supported
+                       array(array(), null),
+                       array(array(), array()),
+                       array(array('Following databases are supported: sqlite, postgres'), array('sqlite', 'postgres')),
+               );
+       }
+
        function providesPhpVersion() {
                return array(
                        array(array(), null, null),