-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check for missing app code before upgrade #26227
- Loading branch information
Showing
6 changed files
with
312 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
/** | ||
* @author Victor Dubiniuk <dubiniuk@owncloud.com> | ||
* | ||
* @copyright Copyright (c) 2017, ownCloud GmbH. | ||
* @license AGPL-3.0 | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* 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 Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OC\Core\Command\Upgrade; | ||
|
||
use OC\Updater\PreUpdate; | ||
use OCP\App\IAppManager; | ||
use OCP\ILogger; | ||
use OC\Core\Command\Base; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class CheckApps extends Base { | ||
/** @var PreUpdate */ | ||
private $preUpdate; | ||
|
||
/** @var ILogger */ | ||
private $logger; | ||
|
||
/** | ||
* @param IAppManager $appManager | ||
* @param ILogger $logger | ||
*/ | ||
public function __construct(PreUpdate $preUpdate, ILogger $logger) { | ||
parent::__construct(); | ||
$this->preUpdate = $preUpdate; | ||
$this->logger = $logger; | ||
} | ||
|
||
|
||
protected function configure() { | ||
parent::configure(); | ||
$this | ||
->setName('upgrade:checkapps') | ||
->setDescription('Check if there are apps with missing code.') | ||
; | ||
} | ||
|
||
/** | ||
* Execute the command | ||
* | ||
* @param InputInterface $input input interface | ||
* @param OutputInterface $output output interface | ||
* @return int|null | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) { | ||
$missingApps = $this->preUpdate->getMissingApps(); | ||
if (count($missingApps) !==0 ){ | ||
$this->writeArrayInOutputFormat($input, $output, $missingApps); | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/** | ||
* @author Victor Dubiniuk <dubiniuk@owncloud.com> | ||
* | ||
* @copyright Copyright (c) 2017, ownCloud GmbH. | ||
* @license AGPL-3.0 | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* 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 Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OC\Updater; | ||
|
||
use OCP\App\IAppManager; | ||
|
||
class PreUpdate { | ||
/** @var IAppManager */ | ||
private $appManager; | ||
|
||
public function __construct(IAppManager $appManager) { | ||
$this->appManager = $appManager; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getMissingApps(){ | ||
$installedApps = $this->appManager->getInstalledApps(); | ||
$missingApps = []; | ||
foreach ($installedApps as $appId){ | ||
$info = $this->appManager->getAppInfo($appId); | ||
if (!isset($info['id'])){ | ||
$missingApps[] = $appId; | ||
} | ||
} | ||
return $missingApps; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
/** | ||
* @author Victor Dubiniuk <dubiniuk@owncloud.com> | ||
* | ||
* @copyright Copyright (c) 2017, ownCloud GmbH. | ||
* @license AGPL-3.0 | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* 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 Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace Tests\Core\Command\Upgrade; | ||
|
||
|
||
use OC\Core\Command\Upgrade\CheckApps; | ||
use OC\Updater\PreUpdate; | ||
use OCP\ILogger; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Test\TestCase; | ||
|
||
class CheckAppsTest extends TestCase { | ||
/** @var \PHPUnit_Framework_MockObject_MockObject */ | ||
protected $consoleInput; | ||
/** @var \PHPUnit_Framework_MockObject_MockObject */ | ||
protected $consoleOutput; | ||
|
||
/** @var Command */ | ||
protected $command; | ||
|
||
/** @var \PHPUnit_Framework_MockObject_MockObject */ | ||
protected $preUpdate; | ||
|
||
/** @var \PHPUnit_Framework_MockObject_MockObject */ | ||
protected $logger; | ||
|
||
|
||
protected function setUp() { | ||
parent::setUp(); | ||
|
||
$this->preUpdate = $this->getMockBuilder(PreUpdate::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->logger = $this->getMockBuilder(ILogger::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
|
||
$this->consoleInput = $this->createMock(InputInterface::class); | ||
$this->consoleOutput = $this->createMock(OutputInterface::class); | ||
|
||
$this->command = new CheckApps($this->preUpdate, $this->logger); | ||
} | ||
|
||
public function testCheckAppsData(){ | ||
return [ | ||
[ | ||
[], 0, | ||
], | ||
[ | ||
['foo_app'], 1, | ||
], | ||
]; | ||
} | ||
|
||
/** @dataProvider testCheckAppsData | ||
* @param [] $appIds | ||
* @param int $expected | ||
*/ | ||
public function testCheckApps($appIds, $expected) { | ||
$this->preUpdate->expects($this->any()) | ||
->method('getMissingApps') | ||
->willReturn($appIds); | ||
|
||
$exitCode = $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); | ||
$this->assertEquals($expected, $exitCode); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
/** | ||
* @author Victor Dubiniuk <dubiniuk@owncloud.com> | ||
* | ||
* @copyright Copyright (c) 2017, ownCloud GmbH. | ||
* @license AGPL-3.0 | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* 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 Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace Tests\Lib\Updater; | ||
|
||
use OC\Updater\PreUpdate; | ||
use OCP\App\IAppManager; | ||
use Test\TestCase; | ||
|
||
class PreUpdateTest extends TestCase { | ||
|
||
/** @var \PHPUnit_Framework_MockObject_MockObject */ | ||
protected $appManager; | ||
|
||
/** @var PreUpdate */ | ||
protected $instance; | ||
|
||
protected function setUp() { | ||
parent::setUp(); | ||
$this->appManager = $this->getMockBuilder(IAppManager::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->instance = new PreUpdate($this->appManager); | ||
} | ||
|
||
public function testGetMissingAppsData(){ | ||
return [ | ||
[ | ||
['firstapp', 'secondapp', 'thirdapp'], | ||
[ | ||
['firstapp', [ 'id' => 'firstapp' ]], | ||
['secondapp', [ 'id' => 'secondapp' ]], | ||
['thirdapp', [ 'id' => 'thirdapp' ]], | ||
], | ||
[] | ||
], | ||
|
||
[ | ||
['firstapp', 'secondapp', 'thirdapp'], | ||
[ | ||
['firstapp', [ 'id' => 'firstapp' ]], | ||
['secondapp', [] ], | ||
['thirdapp', [ 'id' => 'thirdapp' ]], | ||
], | ||
['secondapp'] | ||
], | ||
|
||
]; | ||
} | ||
|
||
/** @dataProvider testGetMissingAppsData | ||
* @param string[] $installedApps | ||
* @param [] $appMap | ||
* @param [] $expected | ||
*/ | ||
public function testGetMissingApps($installedApps, $appMap, $expected) { | ||
$this->appManager->expects($this->any()) | ||
->method('getInstalledApps') | ||
->willReturn($installedApps); | ||
|
||
$this->appManager->expects($this->any()) | ||
->method('getAppInfo') | ||
->willReturnMap($appMap); | ||
|
||
$actual = $this->instance->getMissingApps(); | ||
$this->assertEquals($expected, $actual); | ||
} | ||
} |