From a27f92a17ae12d2d1ff48b26aadfecd7c221c589 Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Mon, 21 Jan 2013 20:40:23 +0100 Subject: [PATCH 01/12] we are getting closer. updating is not working yet. --- lib/app.php | 16 +++++- lib/installer.php | 99 ++++++++++++++++++++++++++++++++++--- lib/ocsclient.php | 2 + settings/ajax/apps/ocs.php | 1 + settings/ajax/updateapp.php | 17 +++++++ settings/apps.php | 5 +- settings/js/apps.js | 30 +++++++++++ settings/routes.php | 2 + settings/templates/apps.php | 4 +- 9 files changed, 167 insertions(+), 9 deletions(-) create mode 100644 settings/ajax/updateapp.php diff --git a/lib/app.php b/lib/app.php index e60bce2a20..13f54d6cf7 100644 --- a/lib/app.php +++ b/lib/app.php @@ -142,6 +142,8 @@ class OC_App{ * check if app is shipped * @param string $appid the id of the app to check * @return bool + * + * Check if an app that is installed is a shipped app or installed from the appstore. */ public static function isShipped($appid){ $info = self::getAppInfo($appid); @@ -197,9 +199,10 @@ class OC_App{ if(!is_numeric($app)) { $app = OC_Installer::installShippedApp($app); }else{ + $appdata=OC_OCSClient::getApplication($app); $download=OC_OCSClient::getApplicationDownload($app, 1); if(isset($download['downloadlink']) and $download['downloadlink']!='') { - $app=OC_Installer::installApp(array('source'=>'http', 'href'=>$download['downloadlink'])); + $app=OC_Installer::installApp(array('source'=>'http', 'href'=>$download['downloadlink'],'appdata'=>$appdata)); } } } @@ -212,6 +215,7 @@ class OC_App{ return false; }else{ OC_Appconfig::setValue( $app, 'enabled', 'yes' ); + if(isset($appdata['id'])) OC_Appconfig::setValue( $app, 'ocsid', $appdata['id'] ); return true; } }else{ @@ -229,6 +233,14 @@ class OC_App{ public static function disable( $app ) { // check if app is a shiped app or not. if not delete OC_Appconfig::setValue( $app, 'enabled', 'no' ); + + // check if app is a shiped app or not. if not delete + if(!OC_App::isShipped( $app )){ +// error_log($app.' not shipped'); + OC_Installer::removeApp( $app ); + }else{ +// error_log($app.' shipped'); + } } /** @@ -609,6 +621,8 @@ class OC_App{ $app1[$i]['author'] = $app['personid']; $app1[$i]['ocs_id'] = $app['id']; $app1[$i]['internal'] = $app1[$i]['active'] = 0; + $app1[$i]['update'] = false; + // rating img if($app['score']>=0 and $app['score']<5) $img=OC_Helper::imagePath( "core", "rating/s1.png" ); diff --git a/lib/installer.php b/lib/installer.php index 7dc8b0cef8..f4094a5d4c 100644 --- a/lib/installer.php +++ b/lib/installer.php @@ -141,6 +141,20 @@ class OC_Installer{ return false; } + // 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_Log::write('core', 'App can\'t be installed because it contains the true tag which is not allowed for non shipped apps', OC_Log::ERROR); + OC_Helper::rmdirr($extractDir); + return false; + } + + // check if the ocs version is the same as the version in info.xml/version + if(!isset($info['version']) or ($info['version']<>$data['appdata']['version'])) { + OC_Log::write('core', 'App can\'t be installed because the version in info.xml/version is not the same as the version reported from the app store', 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); @@ -226,7 +240,6 @@ class OC_Installer{ /** * @brief Update an application * @param $data array with all information - * @returns integer * * This function installs an app. All information needed are passed in the * associative array $data. @@ -250,11 +263,57 @@ class OC_Installer{ * * upgrade.php can determine the current installed version of the app using "OC_Appconfig::getValue($appid, 'installed_version')" */ - public static function upgradeApp( $data = array()) { - // TODO: write function - return true; + public static function updateApp( $app ) { + error_log('updater!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'); + return(true); + if(OC_Installer::isDownloaded( $name )) { + } } + /** + * @brief Check if an update for the app is available + * @param $name name of the application + * @returns emptry string is no update available or the version number of the update + * + * The function will check if an update for a version is available + */ + public static function isUpdateAvailable( $app ) { + //debug + return('1.1'); + + $ocsid=OC_Appconfig::getValue( $app, 'ocsid', ''); + + if($ocsid<>''){ + + $ocsdata=OC_OCSClient::getApplication($ocsid); + $ocsversion=$ocsdata['version']; + $currentversion=OC_App::getAppVersion($app); + +//error_log('bb'.$app.' '.$ocsversion); + return($ocsversion); + + }else{ + return(''); + } + + } + + /** + * @brief Check if app is already downloaded + * @param $name name of the application to remove + * @returns true/false + * + * The function will check if the app is already downloaded in the apps repository + */ + public static function isDownloaded( $name ) { + + $downloaded=false; + foreach(OC::$APPSROOTS as $dir) { + if(is_dir($dir['path'].'/'.$name)) $downloaded=true; + } + return($downloaded); + } + /** * @brief Removes an app * @param $name name of the application to remove @@ -276,8 +335,36 @@ class OC_Installer{ * this has to be done by the function oc_app_uninstall(). */ public static function removeApp( $name, $options = array()) { - // TODO: write function - return true; + + if(isset($options['keeppreferences']) and $options['keeppreferences']==false ){ + // todo + // remove preferences + } + + if(isset($options['keepappconfig']) and $options['keepappconfig']==false ){ + // todo + // remove app config + } + + if(isset($options['keeptables']) and $options['keeptables']==false ){ + // todo + // remove app database tables + } + + if(isset($options['keepfiles']) and $options['keepfiles']==false ){ + // todo + // remove user files + } + + if(OC_Installer::isDownloaded( $name )) { + $appdir=OC_App::getInstallPath().'/'.$name; + OC_Helper::rmdirr($appdir); + + }else{ + OC_Log::write('core', 'can\'t remove app '.$name.'. It is not installed.', OC_Log::ERROR); + + } + } /** diff --git a/lib/ocsclient.php b/lib/ocsclient.php index 24081425f1..3693078877 100644 --- a/lib/ocsclient.php +++ b/lib/ocsclient.php @@ -123,6 +123,7 @@ class OC_OCSClient{ $app=array(); $app['id']=(string)$tmp[$i]->id; $app['name']=(string)$tmp[$i]->name; + $app['version']=(string)$tmp[$i]->version; $app['type']=(string)$tmp[$i]->typeid; $app['typename']=(string)$tmp[$i]->typename; $app['personid']=(string)$tmp[$i]->personid; @@ -162,6 +163,7 @@ class OC_OCSClient{ $app=array(); $app['id']=$tmp->id; $app['name']=$tmp->name; + $app['version']=$tmp->version; $app['type']=$tmp->typeid; $app['typename']=$tmp->typename; $app['personid']=$tmp->personid; diff --git a/settings/ajax/apps/ocs.php b/settings/ajax/apps/ocs.php index 1ffba26ad1..6e09785d23 100644 --- a/settings/ajax/apps/ocs.php +++ b/settings/ajax/apps/ocs.php @@ -54,6 +54,7 @@ if(is_array($catagoryNames)) { 'preview'=>$pre, 'internal'=>false, 'internallabel'=>'3rd Party App', + 'update'=>false, ); } } diff --git a/settings/ajax/updateapp.php b/settings/ajax/updateapp.php new file mode 100644 index 0000000000..68c2bbf7f0 --- /dev/null +++ b/settings/ajax/updateapp.php @@ -0,0 +1,17 @@ + array('appid' => $appid))); +} else { + $l = OC_L10N::get('settings'); + OC_JSON::error(array("data" => array( "message" => $l->t("Could update app. ") ))); +} + + + diff --git a/settings/apps.php b/settings/apps.php index 99a3094399..a2015801e5 100644 --- a/settings/apps.php +++ b/settings/apps.php @@ -68,13 +68,16 @@ foreach ( $installedApps as $app ) { $info['internal']=true; $info['internallabel']='Internal App'; + + $info['update']=false; }else{ $info['internal']=false; $info['internallabel']='3rd Party App'; - + + $info['update']=OC_Installer::isUpdateAvailable($app); } $info['preview'] = OC_Helper::imagePath('settings', 'trans.png'); diff --git a/settings/js/apps.js b/settings/js/apps.js index c4c36b4bb1..8d214bd114 100644 --- a/settings/js/apps.js +++ b/settings/js/apps.js @@ -24,6 +24,14 @@ OC.Settings.Apps = OC.Settings.Apps || { page.find('span.author').text(app.author); page.find('span.licence').text(app.licence); + if (app.update != false) { + page.find('input.update').show(); + page.find('input.update').data('appid', app.id); + page.find('input.update').attr('value',t('settings', 'Update to ')+app.update); + } else { + page.find('input.update').hide(); + } + page.find('input.enable').show(); page.find('input.enable').val((app.active) ? t('settings', 'Disable') : t('settings', 'Enable')); page.find('input.enable').data('appid', app.id); @@ -44,6 +52,7 @@ OC.Settings.Apps = OC.Settings.Apps || { appData = appitem.data('app'); appData.active = !active; appitem.data('app', appData); + element.val(t('settings','Please wait....')); if(active) { $.post(OC.filePath('settings','ajax','disableapp.php'),{appid:appid},function(result) { if(!result || result.status!='success') { @@ -70,6 +79,20 @@ OC.Settings.Apps = OC.Settings.Apps || { $('#leftcontent li[data-id="'+appid+'"]').addClass('active'); } }, + updateApp:function(appid, element) { + console.log('updateApp:', appid, element); + element.val(t('settings','Updateing....')); + $.post(OC.filePath('settings','ajax','updateapp.php'),{appid:appid},function(result) { + if(!result || result.status!='success') { + OC.dialogs.alert('Error while updating app','Error'); + } + else { + element.val(t('settings','Updated')); + element.hide(); + } + },'json'); + }, + insertApp:function(appdata) { var applist = $('#leftcontent li'); var app = @@ -154,6 +177,13 @@ $(document).ready(function(){ OC.Settings.Apps.enableApp(appid, active, element); } }); + $('#rightcontent input.update').click(function(){ + var element = $(this); + var appid=$(this).data('appid'); + if(appid) { + OC.Settings.Apps.updateApp(appid, element); + } + }); if(appid) { var item = $('#leftcontent li[data-id="'+appid+'"]'); diff --git a/settings/routes.php b/settings/routes.php index 9b5bf80923..fa78f56652 100644 --- a/settings/routes.php +++ b/settings/routes.php @@ -51,6 +51,8 @@ $this->create('settings_ajax_enableapp', '/settings/ajax/enableapp.php') ->actionInclude('settings/ajax/enableapp.php'); $this->create('settings_ajax_disableapp', '/settings/ajax/disableapp.php') ->actionInclude('settings/ajax/disableapp.php'); +$this->create('settings_ajax_updateapp', '/settings/ajax/updateapp.php') + ->actionInclude('settings/ajax/updateapp.php'); $this->create('settings_ajax_navigationdetect', '/settings/ajax/navigationdetect.php') ->actionInclude('settings/ajax/navigationdetect.php'); // admin diff --git a/settings/templates/apps.php b/settings/templates/apps.php index 179ce9c540..8654547ecb 100644 --- a/settings/templates/apps.php +++ b/settings/templates/apps.php @@ -7,7 +7,7 @@ var appid = ''; @@ -31,7 +31,6 @@ - t('Update').' '.$app['update'].'" />'); ?> From 5e422dea614a90f351aee63405419db1b1ed2d58 Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Wed, 30 Jan 2013 14:52:35 +0100 Subject: [PATCH 04/12] fix typo --- settings/ajax/updateapp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings/ajax/updateapp.php b/settings/ajax/updateapp.php index 68c2bbf7f0..6d02dba984 100644 --- a/settings/ajax/updateapp.php +++ b/settings/ajax/updateapp.php @@ -10,7 +10,7 @@ if($result !== false) { OC_JSON::success(array('data' => array('appid' => $appid))); } else { $l = OC_L10N::get('settings'); - OC_JSON::error(array("data" => array( "message" => $l->t("Could update app. ") ))); + OC_JSON::error(array("data" => array( "message" => $l->t("Couldn\'t update app. ") ))); } From ea5861ed8c4e09eaaac36eb9e74e6d28d25516d3 Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Wed, 30 Jan 2013 15:27:20 +0100 Subject: [PATCH 05/12] remove leftover code --- settings/templates/apps.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/settings/templates/apps.php b/settings/templates/apps.php index bbd5de1fcb..3f0d2a9d1c 100644 --- a/settings/templates/apps.php +++ b/settings/templates/apps.php @@ -15,9 +15,6 @@
  • data-id="" data-type="" data-installed="1"> - '.$app['internallabel'].'' ?>
  • From 5112dac1023617f0cccb04c2472afb560f757087 Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Thu, 31 Jan 2013 10:00:42 +0100 Subject: [PATCH 06/12] remove spaces --- lib/installer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/installer.php b/lib/installer.php index bf81cbdada..f1b386a3e9 100644 --- a/lib/installer.php +++ b/lib/installer.php @@ -254,7 +254,7 @@ class OC_Installer{ * upgrade.php can determine the current installed version of the app using "OC_Appconfig::getValue($appid, 'installed_version')" */ public static function updateApp( $app ) { - $ocsid=OC_Appconfig::getValue( $app, 'ocsid', ''); + $ocsid=OC_Appconfig::getValue( $app, 'ocsid'); OC_App::disable($app); OC_App::enable($ocsid); } From 665bb41c1f1dc6ecf48a5c32f34d91533424f085 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Thu, 31 Jan 2013 10:27:02 +0100 Subject: [PATCH 07/12] style fixes --- lib/app.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/app.php b/lib/app.php index f851d802dc..2a87ec5950 100644 --- a/lib/app.php +++ b/lib/app.php @@ -215,7 +215,9 @@ class OC_App{ return false; }else{ OC_Appconfig::setValue( $app, 'enabled', 'yes' ); - if(isset($appdata['id'])) OC_Appconfig::setValue( $app, 'ocsid', $appdata['id'] ); + if(isset($appdata['id'])) { + OC_Appconfig::setValue( $app, 'ocsid', $appdata['id'] ); + } return true; } }else{ @@ -231,14 +233,13 @@ class OC_App{ * This function set an app as disabled in appconfig. */ public static function disable( $app ) { - // check if app is a shiped app or not. if not delete + // check if app is a shipped app or not. if not delete OC_Appconfig::setValue( $app, 'enabled', 'no' ); - // check if app is a shiped app or not. if not delete + // check if app is a shipped app or not. if not delete if(!OC_App::isShipped( $app )){ OC_Installer::removeApp( $app ); - }else{ - } + } } /** @@ -647,15 +648,15 @@ class OC_App{ } $remoteApps = OC_App::getAppstoreApps(); if ( $remoteApps ) { - // Remove duplicates + // Remove duplicates foreach ( $appList as $app ) { foreach ( $remoteApps AS $key => $remote ) { if ( $app['name'] == $remote['name'] - // To set duplicate detection to use OCS ID instead of string name, - // enable this code, remove the line of code above, - // and add [ID] to info.xml of each 3rd party app: - // OR $app['ocs_id'] == $remote['ocs_id'] + // To set duplicate detection to use OCS ID instead of string name, + // enable this code, remove the line of code above, + // and add [ID] to info.xml of each 3rd party app: + // OR $app['ocs_id'] == $remote['ocs_id'] ) { unset( $remoteApps[$key]); } From e8b423f6669afda88176181c73c5edde7cc5bf48 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Thu, 31 Jan 2013 10:30:13 +0100 Subject: [PATCH 08/12] style fixes --- lib/installer.php | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/installer.php b/lib/installer.php index f1b386a3e9..9786af45be 100644 --- a/lib/installer.php +++ b/lib/installer.php @@ -259,18 +259,18 @@ class OC_Installer{ OC_App::enable($ocsid); } - /** - * @brief Check if an update for the app is available - * @param $name name of the application - * @returns emptry string is no update available or the version number of the update - * - * The function will check if an update for a version is available - */ - public static function isUpdateAvailable( $app ) { + /** + * @brief Check if an update for the app is available + * @param $name name of the application + * @returns empty string is no update available or the version number of the update + * + * The function will check if an update for a version is available + */ + public static function isUpdateAvailable( $app ) { $ocsid=OC_Appconfig::getValue( $app, 'ocsid', ''); if($ocsid<>''){ - + $ocsdata=OC_OCSClient::getApplication($ocsid); $ocsversion= (string) $ocsdata['version']; $currentversion=OC_App::getAppVersion($app); @@ -285,23 +285,23 @@ class OC_Installer{ return(''); } - } + } - /** - * @brief Check if app is already downloaded - * @param $name name of the application to remove - * @returns true/false - * - * The function will check if the app is already downloaded in the apps repository - */ - public static function isDownloaded( $name ) { + /** + * @brief Check if app is already downloaded + * @param $name name of the application to remove + * @returns true/false + * + * The function will check if the app is already downloaded in the apps repository + */ + public static function isDownloaded( $name ) { $downloaded=false; foreach(OC::$APPSROOTS as $dir) { - if(is_dir($dir['path'].'/'.$name)) $downloaded=true; + if(is_dir($dir['path'].'/'.$name)) $downloaded=true; } return($downloaded); - } + } /** * @brief Removes an app @@ -345,7 +345,7 @@ class OC_Installer{ // remove user files } - if(OC_Installer::isDownloaded( $name )) { + if(OC_Installer::isDownloaded( $name )) { $appdir=OC_App::getInstallPath().'/'.$name; OC_Helper::rmdirr($appdir); From 8a662a6c74e5aa961aba7b317107293e559232e1 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Thu, 31 Jan 2013 10:34:54 +0100 Subject: [PATCH 09/12] Cleanup string - easier for translators --- settings/ajax/updateapp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings/ajax/updateapp.php b/settings/ajax/updateapp.php index 6d02dba984..77c0bbc3e3 100644 --- a/settings/ajax/updateapp.php +++ b/settings/ajax/updateapp.php @@ -10,7 +10,7 @@ if($result !== false) { OC_JSON::success(array('data' => array('appid' => $appid))); } else { $l = OC_L10N::get('settings'); - OC_JSON::error(array("data" => array( "message" => $l->t("Couldn\'t update app. ") ))); + OC_JSON::error(array("data" => array( "message" => $l->t("Couldn't update app.") ))); } From 3af09f2acf0baba5cb3e2dbed5d4e2b4aa2b365c Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Thu, 31 Jan 2013 10:43:59 +0100 Subject: [PATCH 10/12] l10n support for the error dialog added --- settings/js/apps.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings/js/apps.js b/settings/js/apps.js index 8d214bd114..5a52a69774 100644 --- a/settings/js/apps.js +++ b/settings/js/apps.js @@ -84,7 +84,7 @@ OC.Settings.Apps = OC.Settings.Apps || { element.val(t('settings','Updateing....')); $.post(OC.filePath('settings','ajax','updateapp.php'),{appid:appid},function(result) { if(!result || result.status!='success') { - OC.dialogs.alert('Error while updating app','Error'); + OC.dialogs.alert(t('settings','Error while updating app'),t('settings','Error')); } else { element.val(t('settings','Updated')); From f7d281af6797c632cd60a50af766d625438fb2c4 Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Thu, 31 Jan 2013 12:24:10 +0100 Subject: [PATCH 11/12] just return "true" for now --- lib/installer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/installer.php b/lib/installer.php index 9786af45be..c86f801b5f 100644 --- a/lib/installer.php +++ b/lib/installer.php @@ -257,6 +257,7 @@ class OC_Installer{ $ocsid=OC_Appconfig::getValue( $app, 'ocsid'); OC_App::disable($app); OC_App::enable($ocsid); + return(true); } /** From 85a12970c7a593a99016353fd66bd5270b013498 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Thu, 31 Jan 2013 14:11:31 +0100 Subject: [PATCH 12/12] update on translation string --- settings/js/apps.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings/js/apps.js b/settings/js/apps.js index 5a52a69774..68a3fa54de 100644 --- a/settings/js/apps.js +++ b/settings/js/apps.js @@ -27,7 +27,7 @@ OC.Settings.Apps = OC.Settings.Apps || { if (app.update != false) { page.find('input.update').show(); page.find('input.update').data('appid', app.id); - page.find('input.update').attr('value',t('settings', 'Update to ')+app.update); + page.find('input.update').attr('value',t('settings', 'Update to {appversion}', {appversion:app.update})); } else { page.find('input.update').hide(); }