Example #1
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);
 }
Example #2
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);
 }
Example #3
0
 /**
  * Copy directory content skipping certain items
  * @param string $path
  * @param string $type
  * @param array $exclusions
  * @return bool 
  */
 public static function copyPath($path, $type, $exclusions)
 {
     $backupFullPath = self::getBackupPath() . DIRECTORY_SEPARATOR;
     // 3rd party and apps might have different location
     if ($type != 'core') {
         $backupFullPath .= $type . DIRECTORY_SEPARATOR;
         if (!@mkdir($backupFullPath, 0777, true)) {
             return self::error('Unable to create ' . $backupFullPath);
         }
     }
     $dh = opendir($path);
     while (($file = readdir($dh)) !== false) {
         $fullPath = $path . DIRECTORY_SEPARATOR . $file;
         if (is_dir($fullPath)) {
             if (in_array($file, $exclusions['relative']) || in_array($fullPath, $exclusions['full'])) {
                 continue;
             }
         }
         \OC_Helper::copyr($fullPath, $backupFullPath . $file);
     }
     return true;
 }
Example #4
0
 /**
  * @brief Update an application
  * @param array $info
  * @param bool $isShipped
  *
  * This function could work like described below, but currently it disables and then
  * enables the app again. This does result in an updated app.
  *
  *
  * This function installs an app. All information needed are passed in the
  * associative array $info.
  * The following keys are required:
  *   - source: string, can be "path" or "http"
  *
  * One of the following keys is required:
  *   - path: path to the file containing the app
  *   - href: link to the downloadable file containing the app
  *
  * The following keys are optional:
  *   - pretend: boolean, if set true the system won't do anything
  *   - noupgrade: boolean, if true appinfo/upgrade.php won't be loaded
  *
  * This function works as follows
  *   -# fetching the file
  *   -# removing the old files
  *   -# unzipping new file
  *   -# including appinfo/upgrade.php
  *   -# setting the installed version
  *
  * upgrade.php can determine the current installed version of the app using
  * "OC_Appconfig::getValue($appid, 'installed_version')"
  */
 public static function updateApp($info = array(), $isShipped = false)
 {
     list($extractDir, $path) = self::downloadApp($info);
     $info = self::checkAppsIntegrity($info, $extractDir, $path, $isShipped);
     $currentDir = OC_App::getAppPath($info['id']);
     $basedir = OC_App::getInstallPath();
     $basedir .= '/';
     $basedir .= $info['id'];
     if ($currentDir !== false && is_writable($currentDir)) {
         $basedir = $currentDir;
     }
     if (is_dir($basedir)) {
         OC_Helper::rmdirr($basedir);
     }
     $appInExtractDir = $extractDir;
     if (substr($extractDir, -1) !== '/') {
         $appInExtractDir .= '/';
     }
     $appInExtractDir .= $info['id'];
     OC_Helper::copyr($appInExtractDir, $basedir);
     OC_Helper::rmdirr($extractDir);
     return OC_App::updateApp($info['id']);
 }
Example #5
0
 /**
  * imports a user, or owncloud instance
  * @param string $path path to zip
  * @param string $type type of import (user or instance)
  * @param string|null|int $uid userid of new user
  * @return string
  */
 public static function import($path, $type = 'user', $uid = null)
 {
     $datadir = OC_Config::getValue('datadirectory');
     // Extract the zip
     if (!($extractpath = self::extractZip($path))) {
         return json_encode(array('success' => false));
     }
     // Get export_info.json
     $scan = scandir($extractpath);
     // Check for export_info.json
     if (!in_array('export_info.json', $scan)) {
         OC_Log::write('migration', 'Invalid import file, export_info.json not found', OC_Log::ERROR);
         return json_encode(array('success' => false));
     }
     $json = json_decode(file_get_contents($extractpath . 'export_info.json'));
     if ($json->exporttype != $type) {
         OC_Log::write('migration', 'Invalid import file', OC_Log::ERROR);
         return json_encode(array('success' => false));
     }
     self::$exporttype = $type;
     $currentuser = OC_User::getUser();
     // Have we got a user if type is user
     if (self::$exporttype == 'user') {
         self::$uid = !is_null($uid) ? $uid : $currentuser;
     }
     // We need to be an admin if we are not importing our own data
     if ($type == 'user' && self::$uid != $currentuser || $type != 'user') {
         if (!OC_User::isAdminUser($currentuser)) {
             // Naughty.
             OC_Log::write('migration', 'Import not permitted.', OC_Log::ERROR);
             return json_encode(array('success' => false));
         }
     }
     // Handle export types
     switch (self::$exporttype) {
         case 'user':
             // Check user availability
             if (!OC_User::userExists(self::$uid)) {
                 OC_Log::write('migration', 'User doesn\'t exist', OC_Log::ERROR);
                 return json_encode(array('success' => false));
             }
             // Check if the username is valid
             if (preg_match('/[^a-zA-Z0-9 _\\.@\\-]/', $json->exporteduser)) {
                 OC_Log::write('migration', 'Username is not valid', OC_Log::ERROR);
                 return json_encode(array('success' => false));
             }
             // Copy data
             $userfolder = $extractpath . $json->exporteduser;
             $newuserfolder = $datadir . '/' . self::$uid;
             foreach (scandir($userfolder) as $file) {
                 if ($file !== '.' && $file !== '..' && is_dir($userfolder . '/' . $file)) {
                     $file = str_replace(array('/', '\\'), '', $file);
                     // Then copy the folder over
                     OC_Helper::copyr($userfolder . '/' . $file, $newuserfolder . '/' . $file);
                 }
             }
             // Import user app data
             if (file_exists($extractpath . $json->exporteduser . '/migration.db')) {
                 if (!($appsimported = self::importAppData($extractpath . $json->exporteduser . '/migration.db', $json, self::$uid))) {
                     return json_encode(array('success' => false));
                 }
             }
             // All done!
             if (!self::unlink_r($extractpath)) {
                 OC_Log::write('migration', 'Failed to delete the extracted zip', OC_Log::ERROR);
             }
             return json_encode(array('success' => true, 'data' => $appsimported));
             break;
         case 'instance':
             /*
              * EXPERIMENTAL
             // Check for new data dir and dbexport before doing anything
             // TODO
             
             // Delete current data folder.
             OC_Log::write( 'migration', "Deleting current data dir", OC_Log::INFO );
             if( !self::unlink_r( $datadir, false ) ) {
             	OC_Log::write( 'migration', 'Failed to delete the current data dir', OC_Log::ERROR );
             	return json_encode( array( 'success' => false ) );
             }
             
             // Copy over data
             if( !self::copy_r( $extractpath . 'userdata', $datadir ) ) {
             	OC_Log::write( 'migration', 'Failed to copy over data directory', OC_Log::ERROR );
             	return json_encode( array( 'success' => false ) );
             }
             
             // Import the db
             if( !OC_DB::replaceDB( $extractpath . 'dbexport.xml' ) ) {
             	return json_encode( array( 'success' => false ) );
             }
             // Done
             return json_encode( array( 'success' => true ) );
             */
             break;
     }
 }
 /**
  * @brief Installs an app
  * @param $data array with all information
  * @returns integer
  *
  * This function installs an app. All information needed are passed in the
  * associative array $data.
  * The following keys are required:
  *   - source: string, can be "path" or "http"
  *
  * One of the following keys is required:
  *   - path: path to the file containing the app
  *   - href: link to the downloadable file containing the app
  *
  * The following keys are optional:
  *   - pretend: boolean, if set true the system won't do anything
  *   - noinstall: boolean, if true appinfo/install.php won't be loaded
  *   - inactive: boolean, if set true the appconfig/app.sample.php won't be
  *     renamed
  *
  * This function works as follows
  *   -# fetching the file
  *   -# unzipping it
  *   -# check the code
  *   -# installing the database at appinfo/database.xml
  *   -# including appinfo/install.php
  *   -# setting the installed version
  *
  * It is the task of oc_app_install to create the tables and do whatever is
  * needed to get the app working.
  */
 public static function installApp($data = array())
 {
     if (!isset($data['source'])) {
         OC_Log::write('core', 'No source specified when installing app', OC_Log::ERROR);
         return false;
     }
     //download the file if necesary
     if ($data['source'] == 'http') {
         $path = OC_Helper::tmpFile();
         if (!isset($data['href'])) {
             OC_Log::write('core', 'No href specified when installing app from http', OC_Log::ERROR);
             return false;
         }
         copy($data['href'], $path);
     } else {
         if (!isset($data['path'])) {
             OC_Log::write('core', 'No path specified when installing app from local file', OC_Log::ERROR);
             return false;
         }
         $path = $data['path'];
     }
     //detect the archive type
     $mime = OC_Helper::getMimeType($path);
     if ($mime == 'application/zip') {
         rename($path, $path . '.zip');
         $path .= '.zip';
     } elseif ($mime == 'application/x-gzip') {
         rename($path, $path . '.tgz');
         $path .= '.tgz';
     } else {
         OC_Log::write('core', 'Archives of type ' . $mime . ' are not supported', OC_Log::ERROR);
         return false;
     }
     //extract the archive in a temporary folder
     $extractDir = OC_Helper::tmpFolder();
     OC_Helper::rmdirr($extractDir);
     mkdir($extractDir);
     if ($archive = OC_Archive::open($path)) {
         $archive->extract($extractDir);
     } else {
         OC_Log::write('core', 'Failed to open archive when installing app', OC_Log::ERROR);
         OC_Helper::rmdirr($extractDir);
         if ($data['source'] == 'http') {
             unlink($path);
         }
         return false;
     }
     //load the info.xml file of the app
     if (!is_file($extractDir . '/appinfo/info.xml')) {
         //try to find it in a subdir
         $dh = opendir($extractDir);
         while ($folder = readdir($dh)) {
             if (substr($folder, 0, 1) != '.' and is_dir($extractDir . '/' . $folder)) {
                 if (is_file($extractDir . '/' . $folder . '/appinfo/info.xml')) {
                     $extractDir .= '/' . $folder;
                 }
             }
         }
     }
     if (!is_file($extractDir . '/appinfo/info.xml')) {
         OC_Log::write('core', 'App does not provide an info.xml file', OC_Log::ERROR);
         OC_Helper::rmdirr($extractDir);
         if ($data['source'] == 'http') {
             unlink($path);
         }
         return false;
     }
     $info = OC_App::getAppInfo($extractDir . '/appinfo/info.xml', true);
     $basedir = OC::$APPSROOT . '/apps/' . $info['id'];
     // check the code for not allowed calls
     if (!OC_Installer::checkCode($info['id'], $extractDir)) {
         OC_Log::write('core', 'App can\'t be installed because of not allowed code in the App', OC_Log::ERROR);
         OC_Helper::rmdirr($extractDir);
         return false;
     }
     // check if the app is compatible with this version of ownCloud
     $version = OC_Util::getVersion();
     if (!isset($info['require']) or $version[0] > $info['require']) {
         OC_Log::write('core', 'App can\'t be installed because it is not compatible with this version of ownCloud', OC_Log::ERROR);
         OC_Helper::rmdirr($extractDir);
         return false;
     }
     //check if an app with the same id is already installed
     if (self::isInstalled($info['id'])) {
         OC_Log::write('core', 'App already installed', OC_Log::WARN);
         OC_Helper::rmdirr($extractDir);
         if ($data['source'] == 'http') {
             unlink($path);
         }
         return false;
     }
     //check if the destination directory already exists
     if (is_dir($basedir)) {
         OC_Log::write('core', 'App directory already exists', OC_Log::WARN);
         OC_Helper::rmdirr($extractDir);
         if ($data['source'] == 'http') {
             unlink($path);
         }
         return false;
     }
     if (isset($data['pretent']) and $data['pretent'] == true) {
         return false;
     }
     //copy the app to the correct place
     if (@(!mkdir($basedir))) {
         OC_Log::write('core', 'Can\'t create app folder. Please fix permissions. (' . $basedir . ')', OC_Log::ERROR);
         OC_Helper::rmdirr($extractDir);
         if ($data['source'] == 'http') {
             unlink($path);
         }
         return false;
     }
     OC_Helper::copyr($extractDir, $basedir);
     //remove temporary files
     OC_Helper::rmdirr($extractDir);
     //install the database
     if (is_file($basedir . '/appinfo/database.xml')) {
         OC_DB::createDbFromStructure($basedir . '/appinfo/database.xml');
     }
     //run appinfo/install.php
     if ((!isset($data['noinstall']) or $data['noinstall'] == false) and file_exists($basedir . '/appinfo/install.php')) {
         include $basedir . '/appinfo/install.php';
     }
     //set the installed version
     OC_Appconfig::setValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id']));
     OC_Appconfig::setValue($info['id'], 'enabled', 'no');
     //set remote/public handelers
     foreach ($info['remote'] as $name => $path) {
         OCP\CONFIG::setAppValue('core', 'remote_' . $name, '/apps/' . $info['id'] . '/' . $path);
     }
     foreach ($info['public'] as $name => $path) {
         OCP\CONFIG::setAppValue('core', 'public_' . $name, '/apps/' . $info['id'] . '/' . $path);
     }
     OC_App::setAppTypes($info['id']);
     return $info['id'];
 }
 /**
  * @brief Installs an app
  * @param $data array with all information
  * @returns integer
  *
  * This function installs an app. All information needed are passed in the
  * associative array $data.
  * The following keys are required:
  *   - source: string, can be "path" or "http"
  *
  * One of the following keys is required:
  *   - path: path to the file containing the app
  *   - href: link to the downloadable file containing the app
  *
  * The following keys are optional:
  *   - pretend: boolean, if set true the system won't do anything
  *   - noinstall: boolean, if true appinfo/install.php won't be loaded
  *   - inactive: boolean, if set true the appconfig/app.sample.php won't be
  *     renamed
  *
  * This function works as follows
  *   -# fetching the file
  *   -# unzipping it
  *   -# installing the database at appinfo/database.xml
  *   -# including appinfo/install.php
  *   -# setting the installed version
  *
  * It is the task of oc_app_install to create the tables and do whatever is
  * needed to get the app working.
  */
 public static function installApp($data = array())
 {
     if (!isset($data['source'])) {
         if (defined("DEBUG") && DEBUG) {
             error_log("No source specified when installing app");
         }
         return false;
     }
     //download the file if necesary
     if ($data['source'] == 'http') {
         $path = tempnam(sys_get_temp_dir(), 'oc_installer_');
         if (!isset($data['href'])) {
             if (defined("DEBUG") && DEBUG) {
                 error_log("No href specified when installing app from http");
             }
             return false;
         }
         copy($data['href'], $path);
     } else {
         if (!isset($data['path'])) {
             if (defined("DEBUG") && DEBUG) {
                 error_log("No path specified when installing app from local file");
             }
             return false;
         }
         $path = $data['path'];
     }
     //extract the archive in a temporary folder
     $extractDir = tempnam(sys_get_temp_dir(), 'oc_installer_uncompressed_');
     unlink($extractDir);
     mkdir($extractDir);
     $zip = new ZipArchive();
     if ($zip->open($path) === true) {
         $zip->extractTo($extractDir);
         $zip->close();
     } else {
         if (defined("DEBUG") && DEBUG) {
             error_log("Failed to open archive when installing app");
         }
         OC_Helper::rmdirr($extractDir);
         if ($data['source'] == 'http') {
             unlink($path);
         }
         return false;
     }
     //load the info.xml file of the app
     if (!is_file($extractDir . '/appinfo/info.xml')) {
         if (defined("DEBUG") && DEBUG) {
             error_log("App does not provide an info.xml file");
         }
         OC_Helper::rmdirr($extractDir);
         if ($data['source'] == 'http') {
             unlink($path);
         }
         return false;
     }
     $info = OC_App::getAppInfo($extractDir . '/appinfo/info.xml');
     $basedir = OC::$SERVERROOT . '/apps/' . $info['id'];
     //check if an app with the same id is already installed
     if (self::isInstalled($info['id'])) {
         if (defined("DEBUG") && DEBUG) {
             error_log("App already installed");
         }
         OC_Helper::rmdirr($extractDir);
         if ($data['source'] == 'http') {
             unlink($path);
         }
         return false;
     }
     //check if the destination directory already exists
     if (is_dir($basedir)) {
         if (defined("DEBUG") && DEBUG) {
             error_log("App's directory already exists");
         }
         OC_Helper::rmdirr($extractDir);
         if ($data['source'] == 'http') {
             unlink($path);
         }
         return false;
     }
     if (isset($data['pretent']) and $data['pretent'] == true) {
         return false;
     }
     //copy the app to the correct place
     if (!mkdir($basedir)) {
         if (defined("DEBUG") && DEBUG) {
             error_log('Can\'t create app folder (' . $basedir . ')');
         }
         OC_Helper::rmdirr($extractDir);
         if ($data['source'] == 'http') {
             unlink($path);
         }
         return false;
     }
     OC_Helper::copyr($extractDir, $basedir);
     //remove temporary files
     OC_Helper::rmdirr($extractDir);
     if ($data['source'] == 'http') {
         unlink($path);
     }
     //install the database
     if (is_file($basedir . '/appinfo/database.xml')) {
         OC_DB::createDbFromStructure($basedir . '/appinfo/database.xml');
     }
     //run appinfo/install.php
     if (!isset($data['noinstall']) or $data['noinstall'] == false and is_file($basedir . '/appinfo/install.php')) {
         include $basedir . '/appinfo/install.php';
     }
     //set the installed version
     OC_Appconfig::setValue($info['id'], 'installed_version', $info['version']);
     OC_Appconfig::setValue($info['id'], 'enabled', 'no');
     return true;
 }
Example #8
0
 /**
  * @brief Installs an app
  * @param $data array with all information
  * @throws \Exception
  * @returns integer
  *
  * This function installs an app. All information needed are passed in the
  * associative array $data.
  * The following keys are required:
  *   - source: string, can be "path" or "http"
  *
  * One of the following keys is required:
  *   - path: path to the file containing the app
  *   - href: link to the downloadable file containing the app
  *
  * The following keys are optional:
  *   - pretend: boolean, if set true the system won't do anything
  *   - noinstall: boolean, if true appinfo/install.php won't be loaded
  *   - inactive: boolean, if set true the appconfig/app.sample.php won't be
  *     renamed
  *
  * This function works as follows
  *   -# fetching the file
  *   -# unzipping it
  *   -# check the code
  *   -# installing the database at appinfo/database.xml
  *   -# including appinfo/install.php
  *   -# setting the installed version
  *
  * It is the task of oc_app_install to create the tables and do whatever is
  * needed to get the app working.
  */
 public static function installApp($data = array())
 {
     $l = \OC_L10N::get('lib');
     if (!isset($data['source'])) {
         throw new \Exception($l->t("No source specified when installing app"));
     }
     //download the file if necessary
     if ($data['source'] == 'http') {
         $pathInfo = pathinfo($data['href']);
         $path = OC_Helper::tmpFile('.' . $pathInfo['extension']);
         if (!isset($data['href'])) {
             throw new \Exception($l->t("No href specified when installing app from http"));
         }
         copy($data['href'], $path);
     } else {
         if (!isset($data['path'])) {
             throw new \Exception($l->t("No path specified when installing app from local file"));
         }
         $path = $data['path'];
     }
     //detect the archive type
     $mime = OC_Helper::getMimeType($path);
     if ($mime !== 'application/zip' && $mime !== 'application/x-gzip') {
         throw new \Exception($l->t("Archives of type %s are not supported", array($mime)));
     }
     //extract the archive in a temporary folder
     $extractDir = OC_Helper::tmpFolder();
     OC_Helper::rmdirr($extractDir);
     mkdir($extractDir);
     if ($archive = OC_Archive::open($path)) {
         $archive->extract($extractDir);
     } else {
         OC_Helper::rmdirr($extractDir);
         if ($data['source'] == 'http') {
             unlink($path);
         }
         throw new \Exception($l->t("Failed to open archive when installing app"));
     }
     //load the info.xml file of the app
     if (!is_file($extractDir . '/appinfo/info.xml')) {
         //try to find it in a subdir
         $dh = opendir($extractDir);
         if (is_resource($dh)) {
             while (($folder = readdir($dh)) !== false) {
                 if ($folder[0] != '.' and is_dir($extractDir . '/' . $folder)) {
                     if (is_file($extractDir . '/' . $folder . '/appinfo/info.xml')) {
                         $extractDir .= '/' . $folder;
                     }
                 }
             }
         }
     }
     if (!is_file($extractDir . '/appinfo/info.xml')) {
         OC_Helper::rmdirr($extractDir);
         if ($data['source'] == 'http') {
             unlink($path);
         }
         throw new \Exception($l->t("App does not provide an info.xml file"));
     }
     $info = OC_App::getAppInfo($extractDir . '/appinfo/info.xml', true);
     // check the code for not allowed calls
     if (!OC_Installer::checkCode($info['id'], $extractDir)) {
         OC_Helper::rmdirr($extractDir);
         throw new \Exception($l->t("App can't be installed because of not allowed code in the App"));
     }
     // check if the app is compatible with this version of ownCloud
     if (!isset($info['require']) or !OC_App::isAppVersionCompatible(OC_Util::getVersion(), $info['require'])) {
         OC_Helper::rmdirr($extractDir);
         throw new \Exception($l->t("App can't be installed because it is not compatible with this version of ownCloud"));
     }
     // check if shipped tag is set which is only allowed for apps that are shipped with ownCloud
     if (isset($info['shipped']) and $info['shipped'] == 'true') {
         OC_Helper::rmdirr($extractDir);
         throw new \Exception($l->t("App can't be installed because it contains the <shipped>true</shipped> tag which is not allowed for non shipped apps"));
     }
     // check if the ocs version is the same as the version in info.xml/version
     $versionFile = $extractDir . '/appinfo/version';
     if (is_file($versionFile)) {
         $version = trim(file_get_contents($versionFile));
     } else {
         $version = trim($info['version']);
     }
     if ($version != trim($data['appdata']['version'])) {
         OC_Helper::rmdirr($extractDir);
         throw new \Exception($l->t("App can't be installed because the version in info.xml/version is not the same as the version reported from the app store"));
     }
     $basedir = OC_App::getInstallPath() . '/' . $info['id'];
     //check if the destination directory already exists
     if (is_dir($basedir)) {
         OC_Helper::rmdirr($extractDir);
         if ($data['source'] == 'http') {
             unlink($path);
         }
         throw new \Exception($l->t("App directory already exists"));
     }
     if (isset($data['pretent']) and $data['pretent'] == true) {
         return false;
     }
     //copy the app to the correct place
     if (@(!mkdir($basedir))) {
         OC_Helper::rmdirr($extractDir);
         if ($data['source'] == 'http') {
             unlink($path);
         }
         throw new \Exception($l->t("Can't create app folder. Please fix permissions. %s", array($basedir)));
     }
     OC_Helper::copyr($extractDir, $basedir);
     //remove temporary files
     OC_Helper::rmdirr($extractDir);
     //install the database
     if (is_file($basedir . '/appinfo/database.xml')) {
         if (OC_Appconfig::getValue($info['id'], 'installed_version') === null) {
             OC_DB::createDbFromStructure($basedir . '/appinfo/database.xml');
         } else {
             OC_DB::updateDbFromStructure($basedir . '/appinfo/database.xml');
         }
     }
     //run appinfo/install.php
     if ((!isset($data['noinstall']) or $data['noinstall'] == false) and file_exists($basedir . '/appinfo/install.php')) {
         include $basedir . '/appinfo/install.php';
     }
     //set the installed version
     OC_Appconfig::setValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id']));
     OC_Appconfig::setValue($info['id'], 'enabled', 'no');
     //set remote/public handelers
     foreach ($info['remote'] as $name => $path) {
         OCP\CONFIG::setAppValue('core', 'remote_' . $name, $info['id'] . '/' . $path);
     }
     foreach ($info['public'] as $name => $path) {
         OCP\CONFIG::setAppValue('core', 'public_' . $name, $info['id'] . '/' . $path);
     }
     OC_App::setAppTypes($info['id']);
     return $info['id'];
 }