diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index d9c6907..53106fa 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -38,7 +38,8 @@ private function registerServices() { \OC_Util::getEditionString(), \OCP\User::getDisplayName(), \OC::$server->getSystemConfig(), - \OC::$server->getAppConfig() + \OC::$server->getAppConfig(), + \OC::$server->getDatabaseConnection() ); }); diff --git a/lib/Command/ConfigReport.php b/lib/Command/ConfigReport.php index 1c6658d..59fa3d8 100644 --- a/lib/Command/ConfigReport.php +++ b/lib/Command/ConfigReport.php @@ -50,7 +50,8 @@ public function run(InputInterface $input, OutputInterface $output) { \OC_Util::getEditionString(), \OCP\User::getDisplayName(), \OC::$server->getSystemConfig(), - \OC::$server->getAppConfig() + \OC::$server->getAppConfig(), + \OC::$server->getDatabaseConnection() ); return parent::run($input, $output); // TODO: Change the autogenerated stub diff --git a/lib/ReportDataCollector.php b/lib/ReportDataCollector.php index be431a8..6175e31 100644 --- a/lib/ReportDataCollector.php +++ b/lib/ReportDataCollector.php @@ -21,6 +21,7 @@ use OC\SystemConfig; use OC\User\Manager; use OCP\IAppConfig; +use OCP\IDBConnection; use OCP\IGroupManager; use OCP\IUser; use Symfony\Component\EventDispatcher\GenericEvent; @@ -90,6 +91,9 @@ class ReportDataCollector { */ private $appConfig; + /** @var IDBConnection */ + private $connection; + /** * @param Checker $integrityChecker * @param Manager $userManager @@ -100,6 +104,7 @@ class ReportDataCollector { * @param string $displayName * @param SystemConfig $systemConfig * @param IAppConfig $appConfig + * @param IDBConnection $connection */ public function __construct( Checker $integrityChecker, @@ -110,7 +115,8 @@ public function __construct( $editionString, $displayName, SystemConfig $systemConfig, - IAppConfig $appConfig + IAppConfig $appConfig, + IDBConnection $connection ) { $this->integrityChecker = $integrityChecker; $this->userManager = $userManager; @@ -125,6 +131,7 @@ public function __construct( $this->systemConfig = $systemConfig; $this->apps = \OC_App::listAllApps(); $this->appConfig = $appConfig; + $this->connection = $connection; $event = new GenericEvent(); $this->appConfigData = \OC::$server->getEventDispatcher()->dispatch('OCA\ConfigReport::loadData', $event); @@ -166,6 +173,7 @@ public function getReport() { 'integritychecker' => $this->getIntegrityCheckerDetailArray(), 'core' => $this->getCoreConfigArray(), 'apps' => $this->getAppsDetailArray(), + 'migrations' => $this->getOcMigrationArray(), 'phpinfo' => $this->getPhpInfoDetailArray() ]; @@ -292,6 +300,21 @@ private function getAppsDetailArray() { return $this->apps; } + /** + * @return array + */ + private function getOcMigrationArray() { + //Get data from oc_migrations table + $queryBuilder = $this->connection->getQueryBuilder(); + $results = $queryBuilder + ->select('app', 'version') + ->from('migrations') + ->execute() + ->fetchAll(); + + return $results; + } + /** * @return array */ diff --git a/tests/unit/ReportDataCollectorTest.php b/tests/unit/ReportDataCollectorTest.php new file mode 100644 index 0000000..14b3079 --- /dev/null +++ b/tests/unit/ReportDataCollectorTest.php @@ -0,0 +1,82 @@ + + * + * @copyright Copyright (c) 2018, ownCloud GmbH + * @license AGPL + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License, version 2, + * along with this program. If not, see + * + */ + +namespace OCA\ConfigReport\Tests; + +use OC\IntegrityCheck\Checker; +use OC\SystemConfig; +use OC\User\Manager; +use OCA\ConfigReport\ReportDataCollector; +use OCP\IAppConfig; +use OCP\IGroupManager; +use Test\TestCase; + +/** + * Class ReportDataCollectorTest + * + * @group DB + * @package OCA\ConfigReport\Tests + */ +class ReportDataCollectorTest extends TestCase { + private $integrityChecker; + private $userManager; + private $groupManager; + private $sysConfig; + private $appConfig; + private $connection; + private $reportDataCollector; + + protected function setUp() { + parent::setUp(); + + $this->integrityChecker = $this->createMock(Checker::class); + $this->userManager = $this->createMock(Manager::class); + $this->groupManager = $this->createMock(IGroupManager::class); + $this->sysConfig = $this->createMock(SystemConfig::class); + $this->appConfig = $this->createMock(IAppConfig::class); + //$this->connection = $this->createMock(IDBConnection::class); + $this->connection = \OC::$server->getDatabaseConnection(); + + $this->reportDataCollector = new ReportDataCollector($this->integrityChecker, + $this->userManager, $this->groupManager, [], "1.0", + '1', 'foo', $this->sysConfig, $this->appConfig, + $this->connection); + } + + public function testGetOcMigrationArray() { + $results = $this->invokePrivate($this->reportDataCollector, 'getOcMigrationArray', []); + foreach ($results as $result) { + $this->assertArrayHasKey('app', $result); + $this->assertArrayHasKey('version', $result); + $values = \array_values($result); + $this->assertContains($values[0], ['core', 'dav', 'files_sharing', 'files_trashbin', 'notifications', 'dav', 'files_external', 'federatedfilesharing', 'customgroups']); + $this->assertContains($values[1], + ['20170101010100','20170101215145','20170111103310','20170213215145','20170214112458','20170221114437', + '20170221121536','20170315173825','20170320173955','20170418154659','20170516100103','20170526104128', + '20170605143658','20170711191432','20170804201253','20170928120000','20171026130750','20180123131835', + '20180302155233','20180319102121','20180607072706','20170116150538','20170116170538','20170202213905', + '20170202220512','20170427182800','20170519091921','20170526100342','20170711193427','20170927201245', + '20170804201125','20170804201253','20170814051424','20170804201125','20170804201253','20170830112305', + '20171115154900', '20171215103657','20170804201125','20170804201253','20170801085340','20170801152524', + '20180119080933','20180604132522','20161209151129', '20180622095921']); + } + } +}