Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
language: php
php:
- 5.6
- "7.0"
- 7.0
- 7.1
- 7.2

env:
global:
Expand Down Expand Up @@ -54,6 +55,8 @@ matrix:
include:
- php: 5.6
env: DB=mysql
- php: 5.6
env: DB=mysql CORE_BRANCH=stable10
- php: 5.6
env: DB=pgsql
- php: 5.6
Expand Down
1 change: 1 addition & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ To use this application click on "Files" in the top left corner and click on "Ma
</background-jobs>
<commands>
<command>OCA\Market\Command\InstallApp</command>
<command>OCA\Market\Command\UnInstallApp</command>
<command>OCA\Market\Command\ListApps</command>
<command>OCA\Market\Command\UpgradeApp</command>
</commands>
Expand Down
4 changes: 4 additions & 0 deletions lib/Command/InstallApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ protected function configure() {
}

protected function execute(InputInterface $input, OutputInterface $output) {
if (!$this->marketService->canInstall()) {
throw new \Exception("Installing apps is not supported because the app folder is not writable.");
}

$appIds = $input->getArgument('ids');
$appIds = array_unique($appIds);
$localPackagesArray = $input->getOption('local');
Expand Down
74 changes: 74 additions & 0 deletions lib/Command/UnInstallApp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* @author Thomas Müller <[email protected]>
*
* @copyright Copyright (c) 2016, 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 OCA\Market\Command;

use OCA\Market\MarketService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class UnInstallApp extends Command {

/** @var MarketService */
private $marketService;

public function __construct(MarketService $marketService) {
parent::__construct();
$this->marketService = $marketService;
}

protected function configure() {
$this
->setName('market:uninstall')
->setDescription('Un-Install apps.')
->addArgument('ids',
InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
'Ids of the apps'
);
}

protected function execute(InputInterface $input, OutputInterface $output) {
if (!$this->marketService->canInstall()) {
throw new \Exception("Un-Installing apps is not supported because the app folder is not writable.");
}

$appIds = $input->getArgument('ids');
$appIds = array_unique($appIds);

if (!count($appIds)){
$output->writeln("No appId or path to a local package specified. Nothing to do.");
return;
}

foreach ($appIds as $appId) {
try {
$output->writeln("$appId: Un-Installing new version ...");
$this->marketService->uninstallApp($appId);
$output->writeln("$appId: App uninstalled.");
} catch (\Exception $ex) {
$output->writeln("$appId: {$ex->getMessage()}");
}
}
}
}
3 changes: 3 additions & 0 deletions lib/Command/UpgradeApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ protected function configure() {
}

protected function execute(InputInterface $input, OutputInterface $output) {
if (!$this->marketService->canInstall()) {
throw new \Exception("Installing apps is not supported because the app folder is not writable.");
}
$localPackagesArray = $input->getOption('local');
$localPackagesArray = array_unique($localPackagesArray);
if (count($localPackagesArray)){
Expand Down
20 changes: 20 additions & 0 deletions lib/MarketService.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public function __construct(IAppManager $appManager, IConfig $config, ICacheFact
* @throws \Exception
*/
public function installApp($appId, $skipMigrations = false) {
if (!$this->canInstall()) {
throw new \Exception("Installing apps is not supported because the app folder is not writable.");
}

$availableReleases = array_column($this->getApps(), 'releases', 'id')[$appId];
if (array_pop($availableReleases)['license'] == 'ownCloud Commercial License') {
Expand Down Expand Up @@ -252,6 +255,10 @@ public function getInstalledAppInfo($appId) {
* @throws AppNotInstalledException
*/
public function updateApp($appId) {
if (!$this->canInstall()) {
throw new \Exception("Installing apps is not supported because the app folder is not writable.");
}

try {
$info = $this->getInstalledAppInfo($appId);
if (is_null($info)) {
Expand All @@ -275,6 +282,10 @@ public function updateApp($appId) {
* @throws AppManagerException
*/
public function uninstallApp($appId) {
if (!$this->canInstall()) {
throw new \Exception("Installing apps is not supported because the app folder is not writable.");
}

if ($this->appManager->isShipped($appId)) {
throw new AppManagerException($this->l10n->t('Shipped apps cannot be uninstalled'));
}
Expand Down Expand Up @@ -580,4 +591,13 @@ public function requestLicenseKey() {

return $demoLicenseKey;
}

public function canInstall() {
if (!method_exists($this->appManager, 'canInstall')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add TODO: remove once min-version is set to 10.0.3+

$appsFolder = \OC_App::getInstallPath();
return $appsFolder !== null && is_writable($appsFolder) && is_readable($appsFolder);
}

return $this->appManager->canInstall();
}
}
65 changes: 35 additions & 30 deletions tests/unit/MarketServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,26 @@

class MarketServiceTest extends TestCase {

/** @var MarketService */
private $marketService;
/** @var boolean */
private $hasInternetConnection;
/** @var IAppManager | PHPUnit_Framework_MockObject_MockObject */
private $appManager;

public function setUp(){
$this->hasInternetConnection = true;
$appManagerMock = $this->getMockBuilder(IAppManager::class)->getMock();
$appManagerMock->method('getAllApps')->will($this->returnValue([]));

$this->appManager = $this->createMock(IAppManager::class);
$this->appManager->method('getAllApps')->willReturn([]);

/** @var IConfig | PHPUnit_Framework_MockObject_MockObject $configMock */
$configMock = $this->getConfigMock();
$cacheFactoryMock = $this->getMockBuilder(ICacheFactory::class)->getMock();
$l10nMock = $this->getMockBuilder(IL10N::class)->getMock();
/** @var ICacheFactory | PHPUnit_Framework_MockObject_MockObject $cacheFactoryMock */
$cacheFactoryMock = $this->createMock(ICacheFactory::class);
/** @var IL10N | PHPUnit_Framework_MockObject_MockObject $l10nMock */
$l10nMock = $this->createMock(IL10N::class);
$this->marketService = new MarketService(
$appManagerMock,
$this->appManager,
$configMock,
$cacheFactoryMock,
$l10nMock
Expand All @@ -33,6 +40,7 @@ public function setUp(){
*/
public function testInstallWithInternetConnectionDisabled(){
$this->hasInternetConnection = false;
$this->appManager->method('canInstall')->willReturn(true);
$this->marketService->installApp('fubar');
}

Expand All @@ -41,8 +49,28 @@ public function testInstallWithInternetConnectionDisabled(){
*/
public function testUpdateWithInternetConnectionDisabled(){
$this->hasInternetConnection = false;
$this->appManager->method('canInstall')->willReturn(true);
$this->marketService->updateApp('files');
}

/**
* @dataProvider providesMarketMethods
* @expectedException \Exception
* @expectedExceptionMessage Installing apps is not supported because the app folder is not writable.
*/
public function testInstallNotPossible($method) {
$this->appManager->method('canInstall')->willReturn(false);

$this->marketService->$method('test');
}

public function providesMarketMethods() {
return [
['installApp'],
['uninstallApp'],
['updateApp']
];
}

public function getSystemValue($configKey, $default = null){
if ($configKey==='has_internet_connection'){
Expand All @@ -52,30 +80,7 @@ public function getSystemValue($configKey, $default = null){
}

private function getConfigMock(){
$config = $this->getMockBuilder(IConfig::class)
->setMethods([
'getSystemValue',
'setSystemValue',
'getSystemValues',
'setSystemValues',
'getFilteredSystemValue',
'deleteSystemValue',
'getAppKeys',
'setAppValue',
'getAppValue',
'deleteAppValue',
'deleteAppValues',
'setUserValue',
'getUserValue',
'getUserValueForUsers',
'getUserKeys',
'deleteUserValue',
'deleteAllUserValues',
'deleteAppFromAllUsers',
'getUsersForUserValue',
])
->getMock();

$config = $this->createMock(IConfig::class);
$config->method('getSystemValue')
->will($this->returnCallback([$this, 'getSystemValue']));
return $config;
Expand Down