Ejemplo n.º 1
0
 public function testUpdateApp()
 {
     $pathOfOldTestApp = __DIR__;
     $pathOfOldTestApp .= '/../data/';
     $pathOfOldTestApp .= 'testapp.zip';
     $oldTmp = OC_Helper::tmpFile('.zip');
     OC_Helper::copyr($pathOfOldTestApp, $oldTmp);
     $oldData = array('path' => $oldTmp, 'source' => 'path');
     $pathOfNewTestApp = __DIR__;
     $pathOfNewTestApp .= '/../data/';
     $pathOfNewTestApp .= 'testapp2.zip';
     $newTmp = OC_Helper::tmpFile('.zip');
     OC_Helper::copyr($pathOfNewTestApp, $newTmp);
     $newData = array('path' => $newTmp, 'source' => 'path');
     OC_Installer::installApp($oldData);
     $oldVersionNumber = OC_App::getAppVersion(self::$appid);
     OC_Installer::updateApp($newData);
     $newVersionNumber = OC_App::getAppVersion(self::$appid);
     $this->assertNotEquals($oldVersionNumber, $newVersionNumber);
 }
Ejemplo n.º 2
0
 public function testUpdateApp()
 {
     $pathOfOldTestApp = __DIR__;
     $pathOfOldTestApp .= '/../data/';
     $pathOfOldTestApp .= 'testapp.zip';
     $oldTmp = \OC::$server->getTempManager()->getTemporaryFile('.zip');
     OC_Helper::copyr($pathOfOldTestApp, $oldTmp);
     $oldData = array('path' => $oldTmp, 'source' => 'path', 'appdata' => ['id' => 'Bar', 'level' => 100]);
     $pathOfNewTestApp = __DIR__;
     $pathOfNewTestApp .= '/../data/';
     $pathOfNewTestApp .= 'testapp2.zip';
     $newTmp = \OC::$server->getTempManager()->getTemporaryFile('.zip');
     OC_Helper::copyr($pathOfNewTestApp, $newTmp);
     $newData = array('path' => $newTmp, 'source' => 'path', 'appdata' => ['id' => 'Bar', 'level' => 100]);
     OC_Installer::installApp($oldData);
     $oldVersionNumber = OC_App::getAppVersion(self::$appid);
     OC_Installer::updateApp($newData);
     $newVersionNumber = OC_App::getAppVersion(self::$appid);
     $this->assertNotEquals($oldVersionNumber, $newVersionNumber);
 }
Ejemplo n.º 3
0
 /**
  * install an app already placed in the app folder
  * @param string $app id of the app to install
  * @return integer
  */
 public static function installShippedApp($app)
 {
     //install the database
     if (is_file(OC_App::getAppPath($app) . "/appinfo/database.xml")) {
         OC_DB::createDbFromStructure(OC_App::getAppPath($app) . "/appinfo/database.xml");
     }
     //run appinfo/install.php
     if (is_file(OC_App::getAppPath($app) . "/appinfo/install.php")) {
         include OC_App::getAppPath($app) . "/appinfo/install.php";
     }
     $info = OC_App::getAppInfo($app);
     if (is_null($info)) {
         return false;
     }
     OC_Appconfig::setValue($app, 'installed_version', OC_App::getAppVersion($app));
     if (array_key_exists('ocsid', $info)) {
         OC_Appconfig::setValue($app, 'ocsid', $info['ocsid']);
     }
     //set remote/public handelers
     foreach ($info['remote'] as $name => $path) {
         OCP\CONFIG::setAppValue('core', 'remote_' . $name, $app . '/' . $path);
     }
     foreach ($info['public'] as $name => $path) {
         OCP\CONFIG::setAppValue('core', 'public_' . $name, $app . '/' . $path);
     }
     OC_App::setAppTypes($info['id']);
     return $info['id'];
 }
Ejemplo n.º 4
0
 /**
  * upgrades all apps within a major ownCloud upgrade. Also loads "priority"
  * (types authentication, filesystem, logging, in that order) afterwards.
  *
  * @throws NeedsUpdateException
  */
 protected function doAppUpgrade()
 {
     $apps = \OC_App::getEnabledApps();
     $priorityTypes = array('authentication', 'filesystem', 'logging');
     $pseudoOtherType = 'other';
     $stacks = array($pseudoOtherType => array());
     foreach ($apps as $appId) {
         $priorityType = false;
         foreach ($priorityTypes as $type) {
             if (!isset($stacks[$type])) {
                 $stacks[$type] = array();
             }
             if (\OC_App::isType($appId, $type)) {
                 $stacks[$type][] = $appId;
                 $priorityType = true;
                 break;
             }
         }
         if (!$priorityType) {
             $stacks[$pseudoOtherType][] = $appId;
         }
     }
     foreach ($stacks as $type => $stack) {
         foreach ($stack as $appId) {
             if (\OC_App::shouldUpgrade($appId)) {
                 $this->emit('\\OC\\Updater', 'appUpgradeStarted', [$appId, \OC_App::getAppVersion($appId)]);
                 \OC_App::updateApp($appId);
                 $this->emit('\\OC\\Updater', 'appUpgrade', [$appId, \OC_App::getAppVersion($appId)]);
             }
             if ($type !== $pseudoOtherType) {
                 // load authentication, filesystem and logging apps after
                 // upgrading them. Other apps my need to rely on modifying
                 // user and/or filesystem aspects.
                 \OC_App::loadApp($appId, false);
             }
         }
     }
 }
Ejemplo n.º 5
0
 protected function doAppUpgrade()
 {
     $apps = \OC_App::getEnabledApps();
     foreach ($apps as $appId) {
         if (\OC_App::shouldUpgrade($appId)) {
             \OC_App::updateApp($appId);
             $this->emit('\\OC\\Updater', 'appUpgrade', array($appId, \OC_App::getAppVersion($appId)));
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * update the database for the app and call the update script
  *
  * @param string $appId
  * @return bool
  */
 public static function updateApp($appId)
 {
     $appPath = self::getAppPath($appId);
     if ($appPath === false) {
         return false;
     }
     if (file_exists($appPath . '/appinfo/database.xml')) {
         OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml');
     }
     unset(self::$appVersion[$appId]);
     // run upgrade code
     if (file_exists($appPath . '/appinfo/update.php')) {
         self::loadApp($appId, false);
         include $appPath . '/appinfo/update.php';
     }
     //set remote/public handlers
     $appData = self::getAppInfo($appId);
     if (array_key_exists('ocsid', $appData)) {
         \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']);
     } elseif (\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) {
         \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid');
     }
     foreach ($appData['remote'] as $name => $path) {
         \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path);
     }
     foreach ($appData['public'] as $name => $path) {
         \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path);
     }
     self::setAppTypes($appId);
     $version = \OC_App::getAppVersion($appId);
     \OC::$server->getAppConfig()->setValue($appId, 'installed_version', $version);
     return true;
 }
Ejemplo n.º 7
0
 /**
  * Returns the app information from "appinfo/info.xml".
  *
  * If no version was present in "appinfo/info.xml", reads it
  * from the external "appinfo/version" file instead.
  *
  * @param string $appId app id
  *
  * @return array app iinfo
  *
  * @internal
  */
 public function getAppInfo($appId)
 {
     $appInfo = \OC_App::getAppInfo($appId);
     if (!isset($appInfo['version'])) {
         // read version from separate file
         $appInfo['version'] = \OC_App::getAppVersion($appId);
     }
     return $appInfo;
 }
Ejemplo n.º 8
0
 /**
  * check if any apps need updating and update those
  */
 public static function updateApps()
 {
     $versions = self::getAppVersions();
     //ensure files app is installed for upgrades
     if (!isset($versions['files'])) {
         $versions['files'] = '0';
     }
     foreach ($versions as $app => $installedVersion) {
         $currentVersion = OC_App::getAppVersion($app);
         if ($currentVersion) {
             if (version_compare($currentVersion, $installedVersion, '>')) {
                 OC_Log::write($app, 'starting app upgrade from ' . $installedVersion . ' to ' . $currentVersion, OC_Log::DEBUG);
                 OC_App::updateApp($app);
                 OC_Appconfig::setValue($app, 'installed_version', OC_App::getAppVersion($app));
             }
         }
     }
     // check if the current enabled apps are compatible with the current ownCloud version. disable them if not.
     // this is important if you upgrade ownCloud and have non ported 3rd party apps installed
     $apps = OC_App::getEnabledApps();
     $version = OC_Util::getVersion();
     foreach ($apps as $app) {
         // check if the app is compatible with this version of ownCloud
         $info = OC_App::getAppInfo($app);
         if (!isset($info['require']) or $version[0] > $info['require']) {
             OC_Log::write('core', 'App "' . $info['name'] . '" can\'t be used because it is not compatible with this version of ownCloud', OC_Log::ERROR);
             OC_App::disable($app);
         }
     }
 }
Ejemplo n.º 9
0
        }
        if (OC_Appconfig::getValue($app, 'enabled', 'no') == 'yes') {
            $active = true;
        } else {
            $active = false;
        }
        $info['active'] = $active;
        if (isset($info['shipped']) and $info['shipped'] == 'true') {
            $info['internal'] = true;
            $info['internallabel'] = 'Internal App';
        } else {
            $info['internal'] = false;
            $info['internallabel'] = '3rd Party App';
        }
        $info['preview'] = OC_Helper::imagePath('settings', 'trans.png');
        $info['version'] = OC_App::getAppVersion($app);
        $appList[] = $info;
    }
}
$remoteApps = OC_App::getAppstoreApps();
if ($remoteApps) {
    // Remove duplicates
    foreach ($appList as $app) {
        foreach ($remoteApps as $key => $remote) {
            if ($app['name'] == $remote['name']) {
                unset($remoteApps[$key]);
            }
        }
    }
    $combinedApps = array_merge($appList, $remoteApps);
} else {
Ejemplo n.º 10
0
 /**
  * check if the app needs updating and update when needed
  */
 public static function checkUpgrade($app)
 {
     if (in_array($app, self::$checkedApps)) {
         return;
     }
     self::$checkedApps[] = $app;
     $versions = self::getAppVersions();
     $currentVersion = OC_App::getAppVersion($app);
     if ($currentVersion) {
         $installedVersion = $versions[$app];
         if (version_compare($currentVersion, $installedVersion, '>')) {
             $info = self::getAppInfo($app);
             OC_Log::write($app, 'starting app upgrade from ' . $installedVersion . ' to ' . $currentVersion, OC_Log::DEBUG);
             try {
                 OC_App::updateApp($app);
                 OC_Hook::emit('update', 'success', 'Updated ' . $info['name'] . ' app');
             } catch (Exception $e) {
                 OC_Hook::emit('update', 'failure', 'Failed to update ' . $info['name'] . ' app: ' . $e->getMessage());
                 $l = OC_L10N::get('lib');
                 throw new RuntimeException($l->t('Failed to upgrade "%s".', array($app)), 0, $e);
             }
             OC_Appconfig::setValue($app, 'installed_version', OC_App::getAppVersion($app));
         }
     }
 }
Ejemplo n.º 11
0
 /**
  * creates a migration.db in the users data dir with their app data in
  * @return bool whether operation was successfull
  */
 private static function exportAppData()
 {
     $success = true;
     $return = array();
     // Foreach provider
     foreach (self::$providers as $provider) {
         // Check if the app is enabled
         if (OC_App::isEnabled($provider->getID())) {
             $success = true;
             // Does this app use the database?
             if (file_exists(OC_App::getAppPath($provider->getID()) . '/appinfo/database.xml')) {
                 // Create some app tables
                 $tables = self::createAppTables($provider->getID());
                 if (is_array($tables)) {
                     // Save the table names
                     foreach ($tables as $table) {
                         $return['apps'][$provider->getID()]['tables'][] = $table;
                     }
                 } else {
                     // It failed to create the tables
                     $success = false;
                 }
             }
             // Run the export function?
             if ($success) {
                 // Set the provider properties
                 $provider->setData(self::$uid, self::$content);
                 $return['apps'][$provider->getID()]['success'] = $provider->export();
             } else {
                 $return['apps'][$provider->getID()]['success'] = false;
                 $return['apps'][$provider->getID()]['message'] = 'failed to create the app tables';
             }
             // Now add some app info the the return array
             $appinfo = OC_App::getAppInfo($provider->getID());
             $return['apps'][$provider->getID()]['version'] = OC_App::getAppVersion($provider->getID());
         }
     }
     return $return;
 }
Ejemplo n.º 12
0
 /**
  * install an app already placed in the app folder
  * @param string $app id of the app to install
  * @return integer
  */
 public static function installShippedApp($app)
 {
     //install the database
     $appPath = OC_App::getAppPath($app);
     if (is_file("{$appPath}/appinfo/database.xml")) {
         OC_DB::createDbFromStructure("{$appPath}/appinfo/database.xml");
     }
     //run appinfo/install.php
     \OC::$loader->addValidRoot($appPath);
     self::includeAppScript("{$appPath}/appinfo/install.php");
     $info = OC_App::getAppInfo($app);
     if (is_null($info)) {
         return false;
     }
     $config = \OC::$server->getConfig();
     $config->setAppValue($app, 'installed_version', OC_App::getAppVersion($app));
     if (array_key_exists('ocsid', $info)) {
         $config->setAppValue($app, 'ocsid', $info['ocsid']);
     }
     //set remote/public handlers
     foreach ($info['remote'] as $name => $path) {
         $config->setAppValue('core', 'remote_' . $name, $app . '/' . $path);
     }
     foreach ($info['public'] as $name => $path) {
         $config->setAppValue('core', 'public_' . $name, $app . '/' . $path);
     }
     OC_App::setAppTypes($info['id']);
     return $info['id'];
 }
Ejemplo n.º 13
0
 /**
  * install an app already placed in the app folder
  * @param string $app id of the app to install
  * @returns array see OC_App::getAppInfo
  */
 public static function installShippedApp($app)
 {
     //install the database
     if (is_file(OC::$APPSROOT . "/apps/{$app}/appinfo/database.xml")) {
         OC_DB::createDbFromStructure(OC::$APPSROOT . "/apps/{$app}/appinfo/database.xml");
     }
     //run appinfo/install.php
     if (is_file(OC::$APPSROOT . "/apps/{$app}/appinfo/install.php")) {
         include OC::$APPSROOT . "/apps/{$app}/appinfo/install.php";
     }
     $info = OC_App::getAppInfo($app);
     OC_Appconfig::setValue($app, 'installed_version', OC_App::getAppVersion($app));
     //set remote/public handelers
     foreach ($info['remote'] as $name => $path) {
         OCP\CONFIG::setAppValue('core', 'remote_' . $name, '/apps/' . $app . '/' . $path);
     }
     foreach ($info['public'] as $name => $path) {
         OCP\CONFIG::setAppValue('core', 'public_' . $name, '/apps/' . $app . '/' . $path);
     }
     OC_App::setAppTypes($info['id']);
     return $info;
 }
Ejemplo n.º 14
0
 /**
  * check if the app need updating and update when needed
  */
 public static function checkUpgrade($app)
 {
     if (in_array($app, self::$checkedApps)) {
         return;
     }
     self::$checkedApps[] = $app;
     $versions = self::getAppVersions();
     $currentVersion = OC_App::getAppVersion($app);
     if ($currentVersion) {
         $installedVersion = $versions[$app];
         if (version_compare($currentVersion, $installedVersion, '>')) {
             OC_Log::write($app, 'starting app upgrade from ' . $installedVersion . ' to ' . $currentVersion, OC_Log::DEBUG);
             try {
                 OC_App::updateApp($app);
             } catch (Exception $e) {
                 echo 'Failed to upgrade "' . $app . '". Exception="' . $e->getMessage() . '"';
                 die;
             }
             OC_Appconfig::setValue($app, 'installed_version', OC_App::getAppVersion($app));
         }
     }
 }
Ejemplo n.º 15
0
 /**
  * Get the last version of the app, either from appinfo/version or from appinfo/info.xml
  * @param string $app
  * @return string
  * @since 4.0.0
  */
 public static function getAppVersion($app)
 {
     return \OC_App::getAppVersion($app);
 }
Ejemplo n.º 16
0
 /**
  * update the database for the app and call the update script
  *
  * @param string $appId
  * @return bool
  */
 public static function updateApp($appId)
 {
     if (file_exists(self::getAppPath($appId) . '/appinfo/database.xml')) {
         OC_DB::updateDbFromStructure(self::getAppPath($appId) . '/appinfo/database.xml');
     }
     if (!self::isEnabled($appId)) {
         return false;
     }
     if (file_exists(self::getAppPath($appId) . '/appinfo/update.php')) {
         self::loadApp($appId, false);
         include self::getAppPath($appId) . '/appinfo/update.php';
     }
     //set remote/public handlers
     $appData = self::getAppInfo($appId);
     if (array_key_exists('ocsid', $appData)) {
         OC_Appconfig::setValue($appId, 'ocsid', $appData['ocsid']);
     }
     foreach ($appData['remote'] as $name => $path) {
         OCP\CONFIG::setAppValue('core', 'remote_' . $name, $appId . '/' . $path);
     }
     foreach ($appData['public'] as $name => $path) {
         OCP\CONFIG::setAppValue('core', 'public_' . $name, $appId . '/' . $path);
     }
     self::setAppTypes($appId);
     $version = \OC_App::getAppVersion($appId);
     \OC_Appconfig::setValue($appId, 'installed_version', $version);
     return true;
 }
Ejemplo n.º 17
0
 /**
  * check if any apps need updating and update those
  */
 public static function updateApps()
 {
     $versions = self::getAppVersions();
     //ensure files app is installed for upgrades
     if (!isset($versions['files'])) {
         $versions['files'] = '0';
     }
     foreach ($versions as $app => $installedVersion) {
         $currentVersion = OC_App::getAppVersion($app);
         if ($currentVersion) {
             if (version_compare($currentVersion, $installedVersion, '>')) {
                 OC_Log::write($app, 'starting app upgrade from ' . $installedVersion . ' to ' . $currentVersion, OC_Log::DEBUG);
                 OC_App::updateApp($app);
                 OC_Appconfig::setValue($app, 'installed_version', OC_App::getAppVersion($app));
             }
         }
     }
 }