Make isUpdateAvailable non-static
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
parent
0e2f00ec59
commit
df61d43529
|
@ -53,6 +53,9 @@ class BackgroundJob extends TimedJob {
|
||||||
/** @var IClientService */
|
/** @var IClientService */
|
||||||
protected $client;
|
protected $client;
|
||||||
|
|
||||||
|
/** @var Installer */
|
||||||
|
protected $installer;
|
||||||
|
|
||||||
/** @var string[] */
|
/** @var string[] */
|
||||||
protected $users;
|
protected $users;
|
||||||
|
|
||||||
|
@ -64,8 +67,9 @@ class BackgroundJob extends TimedJob {
|
||||||
* @param IGroupManager $groupManager
|
* @param IGroupManager $groupManager
|
||||||
* @param IAppManager $appManager
|
* @param IAppManager $appManager
|
||||||
* @param IClientService $client
|
* @param IClientService $client
|
||||||
|
* @param Installer $installer
|
||||||
*/
|
*/
|
||||||
public function __construct(IConfig $config, IManager $notificationManager, IGroupManager $groupManager, IAppManager $appManager, IClientService $client) {
|
public function __construct(IConfig $config, IManager $notificationManager, IGroupManager $groupManager, IAppManager $appManager, IClientService $client, Installer $installer) {
|
||||||
// Run once a day
|
// Run once a day
|
||||||
$this->setInterval(60 * 60 * 24);
|
$this->setInterval(60 * 60 * 24);
|
||||||
|
|
||||||
|
@ -74,6 +78,7 @@ class BackgroundJob extends TimedJob {
|
||||||
$this->groupManager = $groupManager;
|
$this->groupManager = $groupManager;
|
||||||
$this->appManager = $appManager;
|
$this->appManager = $appManager;
|
||||||
$this->client = $client;
|
$this->client = $client;
|
||||||
|
$this->installer = $installer;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function run($argument) {
|
protected function run($argument) {
|
||||||
|
@ -257,6 +262,6 @@ class BackgroundJob extends TimedJob {
|
||||||
* @return string|false
|
* @return string|false
|
||||||
*/
|
*/
|
||||||
protected function isUpdateAvailable($app) {
|
protected function isUpdateAvailable($app) {
|
||||||
return Installer::isUpdateAvailable($app, \OC::$server->getAppFetcher());
|
return $this->installer->isUpdateAvailable($app);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
namespace OCA\UpdateNotification\Tests\Notification;
|
namespace OCA\UpdateNotification\Tests\Notification;
|
||||||
|
|
||||||
|
|
||||||
|
use OC\Installer;
|
||||||
use OCA\UpdateNotification\Notification\BackgroundJob;
|
use OCA\UpdateNotification\Notification\BackgroundJob;
|
||||||
use OCP\App\IAppManager;
|
use OCP\App\IAppManager;
|
||||||
use OCP\Http\Client\IClientService;
|
use OCP\Http\Client\IClientService;
|
||||||
|
@ -47,6 +48,8 @@ class BackgroundJobTest extends TestCase {
|
||||||
protected $appManager;
|
protected $appManager;
|
||||||
/** @var IClientService|\PHPUnit_Framework_MockObject_MockObject */
|
/** @var IClientService|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
protected $client;
|
protected $client;
|
||||||
|
/** @var Installer|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
|
protected $installer;
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
@ -56,6 +59,7 @@ class BackgroundJobTest extends TestCase {
|
||||||
$this->groupManager = $this->createMock(IGroupManager::class);
|
$this->groupManager = $this->createMock(IGroupManager::class);
|
||||||
$this->appManager = $this->createMock(IAppManager::class);
|
$this->appManager = $this->createMock(IAppManager::class);
|
||||||
$this->client = $this->createMock(IClientService::class);
|
$this->client = $this->createMock(IClientService::class);
|
||||||
|
$this->installer = $this->createMock(Installer::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,7 +73,8 @@ class BackgroundJobTest extends TestCase {
|
||||||
$this->notificationManager,
|
$this->notificationManager,
|
||||||
$this->groupManager,
|
$this->groupManager,
|
||||||
$this->appManager,
|
$this->appManager,
|
||||||
$this->client
|
$this->client,
|
||||||
|
$this->installer
|
||||||
);
|
);
|
||||||
} {
|
} {
|
||||||
return $this->getMockBuilder(BackgroundJob::class)
|
return $this->getMockBuilder(BackgroundJob::class)
|
||||||
|
@ -79,6 +84,7 @@ class BackgroundJobTest extends TestCase {
|
||||||
$this->groupManager,
|
$this->groupManager,
|
||||||
$this->appManager,
|
$this->appManager,
|
||||||
$this->client,
|
$this->client,
|
||||||
|
$this->installer,
|
||||||
])
|
])
|
||||||
->setMethods($methods)
|
->setMethods($methods)
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
|
@ -67,6 +67,10 @@ class Installer {
|
||||||
private $logger;
|
private $logger;
|
||||||
/** @var IConfig */
|
/** @var IConfig */
|
||||||
private $config;
|
private $config;
|
||||||
|
/** @var array - for caching the result of app fetcher */
|
||||||
|
private $apps = null;
|
||||||
|
/** @var bool|null - for caching the result of the ready status */
|
||||||
|
private $isInstanceReadyForUpdates = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param AppFetcher $appFetcher
|
* @param AppFetcher $appFetcher
|
||||||
|
@ -187,7 +191,7 @@ class Installer {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function updateAppstoreApp($appId) {
|
public function updateAppstoreApp($appId) {
|
||||||
if(self::isUpdateAvailable($appId, $this->appFetcher)) {
|
if($this->isUpdateAvailable($appId)) {
|
||||||
try {
|
try {
|
||||||
$this->downloadApp($appId);
|
$this->downloadApp($appId);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
@ -375,29 +379,24 @@ class Installer {
|
||||||
* Check if an update for the app is available
|
* Check if an update for the app is available
|
||||||
*
|
*
|
||||||
* @param string $appId
|
* @param string $appId
|
||||||
* @param AppFetcher $appFetcher
|
|
||||||
* @return string|false false or the version number of the update
|
* @return string|false false or the version number of the update
|
||||||
*/
|
*/
|
||||||
public static function isUpdateAvailable($appId,
|
public function isUpdateAvailable($appId) {
|
||||||
AppFetcher $appFetcher) {
|
if ($this->isInstanceReadyForUpdates === null) {
|
||||||
static $isInstanceReadyForUpdates = null;
|
|
||||||
|
|
||||||
if ($isInstanceReadyForUpdates === null) {
|
|
||||||
$installPath = OC_App::getInstallPath();
|
$installPath = OC_App::getInstallPath();
|
||||||
if ($installPath === false || $installPath === null) {
|
if ($installPath === false || $installPath === null) {
|
||||||
$isInstanceReadyForUpdates = false;
|
$this->isInstanceReadyForUpdates = false;
|
||||||
} else {
|
} else {
|
||||||
$isInstanceReadyForUpdates = true;
|
$this->isInstanceReadyForUpdates = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($isInstanceReadyForUpdates === false) {
|
if ($this->isInstanceReadyForUpdates === false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static $apps = null;
|
if ($this->apps === null) {
|
||||||
if ($apps === null) {
|
$apps = $this->appFetcher->get();
|
||||||
$apps = $appFetcher->get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($apps as $app) {
|
foreach($apps as $app) {
|
||||||
|
|
|
@ -468,7 +468,7 @@ class Updater extends BasicEmitter {
|
||||||
foreach($disabledApps as $app) {
|
foreach($disabledApps as $app) {
|
||||||
try {
|
try {
|
||||||
$this->emit('\OC\Updater', 'checkAppStoreAppBefore', [$app]);
|
$this->emit('\OC\Updater', 'checkAppStoreAppBefore', [$app]);
|
||||||
if (Installer::isUpdateAvailable($app, \OC::$server->getAppFetcher())) {
|
if ($this->installer->isUpdateAvailable($app)) {
|
||||||
$this->emit('\OC\Updater', 'upgradeAppStoreApp', [$app]);
|
$this->emit('\OC\Updater', 'upgradeAppStoreApp', [$app]);
|
||||||
$this->installer->updateAppstoreApp($app);
|
$this->installer->updateAppstoreApp($app);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ use OC\App\AppStore\Fetcher\CategoryFetcher;
|
||||||
use OC\App\AppStore\Version\VersionParser;
|
use OC\App\AppStore\Version\VersionParser;
|
||||||
use OC\App\DependencyAnalyzer;
|
use OC\App\DependencyAnalyzer;
|
||||||
use OC\App\Platform;
|
use OC\App\Platform;
|
||||||
|
use OC\Installer;
|
||||||
use OCP\App\IAppManager;
|
use OCP\App\IAppManager;
|
||||||
use \OCP\AppFramework\Controller;
|
use \OCP\AppFramework\Controller;
|
||||||
use OCP\AppFramework\Http\ContentSecurityPolicy;
|
use OCP\AppFramework\Http\ContentSecurityPolicy;
|
||||||
|
@ -74,6 +75,8 @@ class AppSettingsController extends Controller {
|
||||||
private $l10nFactory;
|
private $l10nFactory;
|
||||||
/** @var BundleFetcher */
|
/** @var BundleFetcher */
|
||||||
private $bundleFetcher;
|
private $bundleFetcher;
|
||||||
|
/** @var Installer */
|
||||||
|
private $installer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $appName
|
* @param string $appName
|
||||||
|
@ -86,6 +89,7 @@ class AppSettingsController extends Controller {
|
||||||
* @param AppFetcher $appFetcher
|
* @param AppFetcher $appFetcher
|
||||||
* @param IFactory $l10nFactory
|
* @param IFactory $l10nFactory
|
||||||
* @param BundleFetcher $bundleFetcher
|
* @param BundleFetcher $bundleFetcher
|
||||||
|
* @param Installer $installer
|
||||||
*/
|
*/
|
||||||
public function __construct($appName,
|
public function __construct($appName,
|
||||||
IRequest $request,
|
IRequest $request,
|
||||||
|
@ -96,7 +100,8 @@ class AppSettingsController extends Controller {
|
||||||
CategoryFetcher $categoryFetcher,
|
CategoryFetcher $categoryFetcher,
|
||||||
AppFetcher $appFetcher,
|
AppFetcher $appFetcher,
|
||||||
IFactory $l10nFactory,
|
IFactory $l10nFactory,
|
||||||
BundleFetcher $bundleFetcher) {
|
BundleFetcher $bundleFetcher,
|
||||||
|
Installer $installer) {
|
||||||
parent::__construct($appName, $request);
|
parent::__construct($appName, $request);
|
||||||
$this->l10n = $l10n;
|
$this->l10n = $l10n;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
|
@ -106,6 +111,7 @@ class AppSettingsController extends Controller {
|
||||||
$this->appFetcher = $appFetcher;
|
$this->appFetcher = $appFetcher;
|
||||||
$this->l10nFactory = $l10nFactory;
|
$this->l10nFactory = $l10nFactory;
|
||||||
$this->bundleFetcher = $bundleFetcher;
|
$this->bundleFetcher = $bundleFetcher;
|
||||||
|
$this->installer = $installer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -270,8 +276,7 @@ class AppSettingsController extends Controller {
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
$appFetcher = \OC::$server->getAppFetcher();
|
$newVersion = $this->installer->isUpdateAvailable($app['id']);
|
||||||
$newVersion = \OC\Installer::isUpdateAvailable($app['id'], $appFetcher);
|
|
||||||
if($newVersion && $this->appManager->isInstalled($app['id'])) {
|
if($newVersion && $this->appManager->isInstalled($app['id'])) {
|
||||||
$formattedApps[count($formattedApps)-1]['update'] = $newVersion;
|
$formattedApps[count($formattedApps)-1]['update'] = $newVersion;
|
||||||
}
|
}
|
||||||
|
@ -284,7 +289,7 @@ class AppSettingsController extends Controller {
|
||||||
$appClass = new \OC_App();
|
$appClass = new \OC_App();
|
||||||
$apps = $appClass->listAllApps();
|
$apps = $appClass->listAllApps();
|
||||||
foreach($apps as $key => $app) {
|
foreach($apps as $key => $app) {
|
||||||
$newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher);
|
$newVersion = $this->installer->isUpdateAvailable($app['id']);
|
||||||
if($newVersion !== false) {
|
if($newVersion !== false) {
|
||||||
$apps[$key]['update'] = $newVersion;
|
$apps[$key]['update'] = $newVersion;
|
||||||
} else {
|
} else {
|
||||||
|
@ -317,7 +322,7 @@ class AppSettingsController extends Controller {
|
||||||
$apps = $appClass->listAllApps();
|
$apps = $appClass->listAllApps();
|
||||||
|
|
||||||
foreach($apps as $key => $app) {
|
foreach($apps as $key => $app) {
|
||||||
$newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher);
|
$newVersion = $this->installer->isUpdateAvailable($app['id']);
|
||||||
$apps[$key]['update'] = $newVersion;
|
$apps[$key]['update'] = $newVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,7 +347,7 @@ class AppSettingsController extends Controller {
|
||||||
});
|
});
|
||||||
|
|
||||||
foreach($apps as $key => $app) {
|
foreach($apps as $key => $app) {
|
||||||
$newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher);
|
$newVersion = $this->installer->isUpdateAvailable($app['id']);
|
||||||
$apps[$key]['update'] = $newVersion;
|
$apps[$key]['update'] = $newVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,7 +368,7 @@ class AppSettingsController extends Controller {
|
||||||
});
|
});
|
||||||
|
|
||||||
$apps = array_map(function ($app) {
|
$apps = array_map(function ($app) {
|
||||||
$newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher);
|
$newVersion = $this->installer->isUpdateAvailable($app['id']);
|
||||||
if ($newVersion !== false) {
|
if ($newVersion !== false) {
|
||||||
$app['update'] = $newVersion;
|
$app['update'] = $newVersion;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ namespace Tests\Settings\Controller;
|
||||||
use OC\App\AppStore\Bundles\BundleFetcher;
|
use OC\App\AppStore\Bundles\BundleFetcher;
|
||||||
use OC\App\AppStore\Fetcher\AppFetcher;
|
use OC\App\AppStore\Fetcher\AppFetcher;
|
||||||
use OC\App\AppStore\Fetcher\CategoryFetcher;
|
use OC\App\AppStore\Fetcher\CategoryFetcher;
|
||||||
|
use OC\Installer;
|
||||||
use OC\Settings\Controller\AppSettingsController;
|
use OC\Settings\Controller\AppSettingsController;
|
||||||
use OCP\AppFramework\Http\ContentSecurityPolicy;
|
use OCP\AppFramework\Http\ContentSecurityPolicy;
|
||||||
use OCP\AppFramework\Http\JSONResponse;
|
use OCP\AppFramework\Http\JSONResponse;
|
||||||
|
@ -63,6 +64,8 @@ class AppSettingsControllerTest extends TestCase {
|
||||||
private $l10nFactory;
|
private $l10nFactory;
|
||||||
/** @var BundleFetcher|\PHPUnit_Framework_MockObject_MockObject */
|
/** @var BundleFetcher|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $bundleFetcher;
|
private $bundleFetcher;
|
||||||
|
/** @var Installer|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
|
private $installer;
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
@ -79,6 +82,7 @@ class AppSettingsControllerTest extends TestCase {
|
||||||
$this->appFetcher = $this->createMock(AppFetcher::class);
|
$this->appFetcher = $this->createMock(AppFetcher::class);
|
||||||
$this->l10nFactory = $this->createMock(IFactory::class);
|
$this->l10nFactory = $this->createMock(IFactory::class);
|
||||||
$this->bundleFetcher = $this->createMock(BundleFetcher::class);
|
$this->bundleFetcher = $this->createMock(BundleFetcher::class);
|
||||||
|
$this->installer = $this->createMock(Installer::class);
|
||||||
|
|
||||||
$this->appSettingsController = new AppSettingsController(
|
$this->appSettingsController = new AppSettingsController(
|
||||||
'settings',
|
'settings',
|
||||||
|
@ -90,11 +94,15 @@ class AppSettingsControllerTest extends TestCase {
|
||||||
$this->categoryFetcher,
|
$this->categoryFetcher,
|
||||||
$this->appFetcher,
|
$this->appFetcher,
|
||||||
$this->l10nFactory,
|
$this->l10nFactory,
|
||||||
$this->bundleFetcher
|
$this->bundleFetcher,
|
||||||
|
$this->installer
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testListCategories() {
|
public function testListCategories() {
|
||||||
|
$this->installer->expects($this->any())
|
||||||
|
->method('isUpdateAvailable')
|
||||||
|
->willReturn(false);
|
||||||
$expected = new JSONResponse([
|
$expected = new JSONResponse([
|
||||||
[
|
[
|
||||||
'id' => 2,
|
'id' => 2,
|
||||||
|
|
|
@ -154,7 +154,8 @@ class InstallerTest extends TestCase {
|
||||||
->method('get')
|
->method('get')
|
||||||
->willReturn($appArray);
|
->willReturn($appArray);
|
||||||
|
|
||||||
$this->assertSame($updateAvailable, Installer::isUpdateAvailable('files', $this->appFetcher));
|
$installer = $this->getInstaller();
|
||||||
|
$this->assertSame($updateAvailable, $installer->isUpdateAvailable('files'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue