Skip to content

Commit

Permalink
Add data from migrations table to report
Browse files Browse the repository at this point in the history
Add data from migrations table to the
report.

Signed-off-by: Sujith H <sharidasan@owncloud.com>
  • Loading branch information
sharidas committed Sep 5, 2018
1 parent c11fdcb commit dc7db3d
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
});

Expand Down
3 changes: 2 additions & 1 deletion lib/Command/ConfigReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 24 additions & 1 deletion lib/ReportDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -90,6 +91,9 @@ class ReportDataCollector {
*/
private $appConfig;

/** @var IDBConnection */
private $connection;

/**
* @param Checker $integrityChecker
* @param Manager $userManager
Expand All @@ -100,6 +104,7 @@ class ReportDataCollector {
* @param string $displayName
* @param SystemConfig $systemConfig
* @param IAppConfig $appConfig
* @param IDBConnection $connection
*/
public function __construct(
Checker $integrityChecker,
Expand All @@ -110,7 +115,8 @@ public function __construct(
$editionString,
$displayName,
SystemConfig $systemConfig,
IAppConfig $appConfig
IAppConfig $appConfig,
IDBConnection $connection
) {
$this->integrityChecker = $integrityChecker;
$this->userManager = $userManager;
Expand All @@ -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);
Expand Down Expand Up @@ -166,6 +173,7 @@ public function getReport() {
'integritychecker' => $this->getIntegrityCheckerDetailArray(),
'core' => $this->getCoreConfigArray(),
'apps' => $this->getAppsDetailArray(),
'migrations' => $this->getOcMigrationArray(),
'phpinfo' => $this->getPhpInfoDetailArray()
];

Expand Down Expand Up @@ -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
*/
Expand Down
82 changes: 82 additions & 0 deletions tests/unit/ReportDataCollectorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
/**
* @author Sujith Haridasan <sharidasan@owncloud.com>
*
* @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 <http://www.gnu.org/licenses/>
*
*/

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']);
}
}
}

0 comments on commit dc7db3d

Please sign in to comment.