OC_Installer -> \OC\Installer

This commit is contained in:
Thomas Müller 2016-04-28 15:15:34 +02:00
parent 54f45f95f5
commit e049953d1a
No known key found for this signature in database
GPG Key ID: A943788A3BBEC44C
6 changed files with 52 additions and 43 deletions

View File

@ -367,7 +367,7 @@ class Setup {
\OC_User::login($username, $password); \OC_User::login($username, $password);
//guess what this does //guess what this does
\OC_Installer::installShippedApps(); Installer::installShippedApps();
// create empty file in data dir, so we can later find // create empty file in data dir, so we can later find
// out that this is indeed an ownCloud data directory // out that this is indeed an ownCloud data directory

View File

@ -36,7 +36,6 @@ namespace OC;
use OC\Hooks\BasicEmitter; use OC\Hooks\BasicEmitter;
use OC\IntegrityCheck\Checker; use OC\IntegrityCheck\Checker;
use OC_App; use OC_App;
use OC_Installer;
use OCP\IConfig; use OCP\IConfig;
use OC\Setup; use OC\Setup;
use OCP\ILogger; use OCP\ILogger;
@ -251,7 +250,7 @@ class Updater extends BasicEmitter {
// install new shipped apps on upgrade // install new shipped apps on upgrade
OC_App::loadApps('authentication'); OC_App::loadApps('authentication');
$errors = OC_Installer::installShippedApps(true); $errors = Installer::installShippedApps(true);
foreach ($errors as $appId => $exception) { foreach ($errors as $appId => $exception) {
/** @var \Exception $exception */ /** @var \Exception $exception */
$this->log->logException($exception, ['app' => $appId]); $this->log->logException($exception, ['app' => $appId]);
@ -443,11 +442,11 @@ class Updater extends BasicEmitter {
private function upgradeAppStoreApps(array $disabledApps) { private function upgradeAppStoreApps(array $disabledApps) {
foreach($disabledApps as $app) { foreach($disabledApps as $app) {
try { try {
if (OC_Installer::isUpdateAvailable($app)) { if (Installer::isUpdateAvailable($app)) {
$ocsId = \OC::$server->getConfig()->getAppValue($app, 'ocsid', ''); $ocsId = \OC::$server->getConfig()->getAppValue($app, 'ocsid', '');
$this->emit('\OC\Updater', 'upgradeAppStoreApp', array($app)); $this->emit('\OC\Updater', 'upgradeAppStoreApp', array($app));
OC_Installer::updateAppByOCSId($ocsId); Installer::updateAppByOCSId($ocsId);
} }
} catch (\Exception $ex) { } catch (\Exception $ex) {
$this->log->logException($ex, ['app' => 'core']); $this->log->logException($ex, ['app' => 'core']);

View File

@ -46,6 +46,7 @@
*/ */
use OC\App\DependencyAnalyzer; use OC\App\DependencyAnalyzer;
use OC\App\Platform; use OC\App\Platform;
use OC\Installer;
use OC\OCSClient; use OC\OCSClient;
use OC\Repair; use OC\Repair;
@ -304,7 +305,7 @@ class OC_App {
*/ */
public static function enable($app, $groups = null) { public static function enable($app, $groups = null) {
self::$enabledAppsCache = array(); // flush self::$enabledAppsCache = array(); // flush
if (!OC_Installer::isInstalled($app)) { if (!Installer::isInstalled($app)) {
$app = self::installApp($app); $app = self::installApp($app);
} }
@ -340,7 +341,7 @@ class OC_App {
// Replace spaces in download link without encoding entire URL // Replace spaces in download link without encoding entire URL
$download['downloadlink'] = str_replace(' ', '%20', $download['downloadlink']); $download['downloadlink'] = str_replace(' ', '%20', $download['downloadlink']);
$info = array('source' => 'http', 'href' => $download['downloadlink'], 'appdata' => $appData); $info = array('source' => 'http', 'href' => $download['downloadlink'], 'appdata' => $appData);
$app = OC_Installer::installApp($info); $app = Installer::installApp($info);
} }
return $app; return $app;
} }
@ -354,7 +355,7 @@ class OC_App {
return false; return false;
} }
return OC_Installer::removeApp($app); return Installer::removeApp($app);
} }
/** /**
@ -827,7 +828,7 @@ class OC_App {
$info['removable'] = true; $info['removable'] = true;
} }
$info['update'] = ($includeUpdateInfo) ? OC_Installer::isUpdateAvailable($app) : null; $info['update'] = ($includeUpdateInfo) ? Installer::isUpdateAvailable($app) : null;
$appPath = self::getAppPath($app); $appPath = self::getAppPath($app);
if($appPath !== false) { if($appPath !== false) {
@ -1073,7 +1074,7 @@ class OC_App {
if ($appData && version_compare($shippedVersion, $appData['version'], '<')) { if ($appData && version_compare($shippedVersion, $appData['version'], '<')) {
$app = self::downloadApp($app); $app = self::downloadApp($app);
} else { } else {
$app = OC_Installer::installShippedApp($app); $app = Installer::installShippedApp($app);
} }
} else { } else {
// Maybe the app is already installed - compare the version in this // Maybe the app is already installed - compare the version in this

View File

@ -37,15 +37,19 @@
* *
*/ */
namespace OC;
use OC\App\CodeChecker\CodeChecker; use OC\App\CodeChecker\CodeChecker;
use OC\App\CodeChecker\EmptyCheck; use OC\App\CodeChecker\EmptyCheck;
use OC\App\CodeChecker\PrivateCheck; use OC\App\CodeChecker\PrivateCheck;
use OC\OCSClient; use OC_App;
use OC_DB;
use OC_Helper;
/** /**
* This class provides the functionality needed to install, update and remove plugins/apps * This class provides the functionality needed to install, update and remove plugins/apps
*/ */
class OC_Installer { class Installer {
/** /**
* *
@ -138,15 +142,15 @@ class OC_Installer {
OC_App::executeRepairSteps($appId, $appData['repair-steps']['install']); OC_App::executeRepairSteps($appId, $appData['repair-steps']['install']);
//set the installed version //set the installed version
\OC::$server->getAppConfig()->setValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id'])); \OC::$server->getConfig()->setAppValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id']));
\OC::$server->getAppConfig()->setValue($info['id'], 'enabled', 'no'); \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no');
//set remote/public handelers //set remote/public handlers
foreach($info['remote'] as $name=>$path) { foreach($info['remote'] as $name=>$path) {
OCP\Config::setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path);
} }
foreach($info['public'] as $name=>$path) { foreach($info['public'] as $name=>$path) {
OCP\Config::setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path);
} }
OC_App::setAppTypes($info['id']); OC_App::setAppTypes($info['id']);
@ -162,14 +166,14 @@ class OC_Installer {
* Checks whether or not an app is installed, i.e. registered in apps table. * Checks whether or not an app is installed, i.e. registered in apps table.
*/ */
public static function isInstalled( $app ) { public static function isInstalled( $app ) {
return (\OC::$server->getAppConfig()->getValue($app, "installed_version") !== null); return (\OC::$server->getConfig()->getAppValue($app, "installed_version", null) !== null);
} }
/** /**
* @brief Update an application * @brief Update an application
* @param array $info * @param array $info
* @param bool $isShipped * @param bool $isShipped
* @throws Exception * @throws \Exception
* @return bool * @return bool
* *
* This function could work like described below, but currently it disables and then * This function could work like described below, but currently it disables and then
@ -232,7 +236,7 @@ class OC_Installer {
* *
* @param integer $ocsId * @param integer $ocsId
* @return bool * @return bool
* @throws Exception * @throws \Exception
*/ */
public static function updateAppByOCSId($ocsId) { public static function updateAppByOCSId($ocsId) {
$ocsClient = new OCSClient( $ocsClient = new OCSClient(
@ -260,7 +264,7 @@ class OC_Installer {
/** /**
* @param array $data * @param array $data
* @return array * @return array
* @throws Exception * @throws \Exception
*/ */
public static function downloadApp($data = array()) { public static function downloadApp($data = array()) {
$l = \OC::$server->getL10N('lib'); $l = \OC::$server->getL10N('lib');
@ -296,7 +300,7 @@ class OC_Installer {
$extractDir = \OC::$server->getTempManager()->getTemporaryFolder(); $extractDir = \OC::$server->getTempManager()->getTemporaryFolder();
OC_Helper::rmdirr($extractDir); OC_Helper::rmdirr($extractDir);
mkdir($extractDir); mkdir($extractDir);
if($archive=OC_Archive::open($path)) { if($archive=\OC_Archive::open($path)) {
$archive->extract($extractDir); $archive->extract($extractDir);
} else { } else {
OC_Helper::rmdirr($extractDir); OC_Helper::rmdirr($extractDir);
@ -378,7 +382,7 @@ class OC_Installer {
} }
// check the code for not allowed calls // check the code for not allowed calls
if(!$isShipped && !OC_Installer::checkCode($extractDir)) { if(!$isShipped && !Installer::checkCode($extractDir)) {
OC_Helper::rmdirr($extractDir); OC_Helper::rmdirr($extractDir);
throw new \Exception($l->t("App can't be installed because of not allowed code in the App")); throw new \Exception($l->t("App can't be installed because of not allowed code in the App"));
} }
@ -460,7 +464,7 @@ class OC_Installer {
* The function will check if the app is already downloaded in the apps repository * The function will check if the app is already downloaded in the apps repository
*/ */
public static function isDownloaded( $name ) { public static function isDownloaded( $name ) {
foreach(OC::$APPSROOTS as $dir) { foreach(\OC::$APPSROOTS as $dir) {
$dirToTest = $dir['path']; $dirToTest = $dir['path'];
$dirToTest .= '/'; $dirToTest .= '/';
$dirToTest .= $name; $dirToTest .= $name;
@ -494,7 +498,7 @@ class OC_Installer {
OC_App::executeRepairSteps($appId, $appData['repair-steps']['uninstall']); OC_App::executeRepairSteps($appId, $appData['repair-steps']['uninstall']);
} }
if(OC_Installer::isDownloaded( $appId )) { if(Installer::isDownloaded( $appId )) {
$appDir=OC_App::getInstallPath() . '/' . $appId; $appDir=OC_App::getInstallPath() . '/' . $appId;
OC_Helper::rmdirr($appDir); OC_Helper::rmdirr($appDir);
@ -517,25 +521,25 @@ class OC_Installer {
*/ */
public static function installShippedApps($softErrors = false) { public static function installShippedApps($softErrors = false) {
$errors = []; $errors = [];
foreach(OC::$APPSROOTS as $app_dir) { foreach(\OC::$APPSROOTS as $app_dir) {
if($dir = opendir( $app_dir['path'] )) { if($dir = opendir( $app_dir['path'] )) {
while( false !== ( $filename = readdir( $dir ))) { while( false !== ( $filename = readdir( $dir ))) {
if( substr( $filename, 0, 1 ) != '.' and is_dir($app_dir['path']."/$filename") ) { if( substr( $filename, 0, 1 ) != '.' and is_dir($app_dir['path']."/$filename") ) {
if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) { if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) {
if(!OC_Installer::isInstalled($filename)) { if(!Installer::isInstalled($filename)) {
$info=OC_App::getAppInfo($filename); $info=OC_App::getAppInfo($filename);
$enabled = isset($info['default_enable']); $enabled = isset($info['default_enable']);
if (($enabled || in_array($filename, \OC::$server->getAppManager()->getAlwaysEnabledApps())) if (($enabled || in_array($filename, \OC::$server->getAppManager()->getAlwaysEnabledApps()))
&& \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') { && \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') {
if ($softErrors) { if ($softErrors) {
try { try {
OC_Installer::installShippedApp($filename); Installer::installShippedApp($filename);
} catch (\Doctrine\DBAL\Exception\TableExistsException $e) { } catch (\Doctrine\DBAL\Exception\TableExistsException $e) {
$errors[$filename] = $e; $errors[$filename] = $e;
continue; continue;
} }
} else { } else {
OC_Installer::installShippedApp($filename); Installer::installShippedApp($filename);
} }
\OC::$server->getConfig()->setAppValue($filename, 'enabled', 'yes'); \OC::$server->getConfig()->setAppValue($filename, 'enabled', 'yes');
} }

View File

@ -50,7 +50,7 @@ $appId = OC_App::cleanAppId($appId);
$config = \OC::$server->getConfig(); $config = \OC::$server->getConfig();
$config->setSystemValue('maintenance', true); $config->setSystemValue('maintenance', true);
try { try {
$result = OC_Installer::updateAppByOCSId($appId); $result = \OC\Installer::updateAppByOCSId($appId);
$config->setSystemValue('maintenance', false); $config->setSystemValue('maintenance', false);
} catch(Exception $ex) { } catch(Exception $ex) {
$config->setSystemValue('maintenance', false); $config->setSystemValue('maintenance', false);

View File

@ -6,7 +6,12 @@
* See the COPYING-README file. * See the COPYING-README file.
*/ */
class Test_Installer extends \Test\TestCase { namespace Test;
use OC\Installer;
class InstallerTest extends TestCase {
private static $appid = 'testapp'; private static $appid = 'testapp';
private $appstore; private $appstore;
@ -17,11 +22,11 @@ class Test_Installer extends \Test\TestCase {
$config = \OC::$server->getConfig(); $config = \OC::$server->getConfig();
$this->appstore = $config->setSystemValue('appstoreenabled', true); $this->appstore = $config->setSystemValue('appstoreenabled', true);
$config->setSystemValue('appstoreenabled', true); $config->setSystemValue('appstoreenabled', true);
OC_Installer::removeApp(self::$appid); Installer::removeApp(self::$appid);
} }
protected function tearDown() { protected function tearDown() {
OC_Installer::removeApp(self::$appid); Installer::removeApp(self::$appid);
\OC::$server->getConfig()->setSystemValue('appstoreenabled', $this->appstore); \OC::$server->getConfig()->setSystemValue('appstoreenabled', $this->appstore);
parent::tearDown(); parent::tearDown();
@ -33,7 +38,7 @@ class Test_Installer extends \Test\TestCase {
$pathOfTestApp .= 'testapp.zip'; $pathOfTestApp .= 'testapp.zip';
$tmp = \OC::$server->getTempManager()->getTemporaryFile('.zip'); $tmp = \OC::$server->getTempManager()->getTemporaryFile('.zip');
OC_Helper::copyr($pathOfTestApp, $tmp); \OC_Helper::copyr($pathOfTestApp, $tmp);
$data = array( $data = array(
'path' => $tmp, 'path' => $tmp,
@ -44,8 +49,8 @@ class Test_Installer extends \Test\TestCase {
] ]
); );
OC_Installer::installApp($data); Installer::installApp($data);
$isInstalled = OC_Installer::isInstalled(self::$appid); $isInstalled = Installer::isInstalled(self::$appid);
$this->assertTrue($isInstalled); $this->assertTrue($isInstalled);
} }
@ -56,7 +61,7 @@ class Test_Installer extends \Test\TestCase {
$pathOfOldTestApp .= 'testapp.zip'; $pathOfOldTestApp .= 'testapp.zip';
$oldTmp = \OC::$server->getTempManager()->getTemporaryFile('.zip'); $oldTmp = \OC::$server->getTempManager()->getTemporaryFile('.zip');
OC_Helper::copyr($pathOfOldTestApp, $oldTmp); \OC_Helper::copyr($pathOfOldTestApp, $oldTmp);
$oldData = array( $oldData = array(
'path' => $oldTmp, 'path' => $oldTmp,
@ -72,7 +77,7 @@ class Test_Installer extends \Test\TestCase {
$pathOfNewTestApp .= 'testapp2.zip'; $pathOfNewTestApp .= 'testapp2.zip';
$newTmp = \OC::$server->getTempManager()->getTemporaryFile('.zip'); $newTmp = \OC::$server->getTempManager()->getTemporaryFile('.zip');
OC_Helper::copyr($pathOfNewTestApp, $newTmp); \OC_Helper::copyr($pathOfNewTestApp, $newTmp);
$newData = array( $newData = array(
'path' => $newTmp, 'path' => $newTmp,
@ -83,11 +88,11 @@ class Test_Installer extends \Test\TestCase {
] ]
); );
OC_Installer::installApp($oldData); Installer::installApp($oldData);
$oldVersionNumber = OC_App::getAppVersion(self::$appid); $oldVersionNumber = \OC_App::getAppVersion(self::$appid);
OC_Installer::updateApp($newData); Installer::updateApp($newData);
$newVersionNumber = OC_App::getAppVersion(self::$appid); $newVersionNumber = \OC_App::getAppVersion(self::$appid);
$this->assertNotEquals($oldVersionNumber, $newVersionNumber); $this->assertNotEquals($oldVersionNumber, $newVersionNumber);
} }