Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2bcfd8e
make it possible to update shipped apps via the appstore
georgehrke May 21, 2014
c8636ca
Merge branch 'master' into update_shipped_apps_from_appstore
georgehrke May 31, 2014
020255b
add button for properly uninstalling apps
georgehrke May 31, 2014
c6dc9ae
Merge branch 'master' into update_shipped_apps_from_appstore
georgehrke May 31, 2014
c8a8c7e
read ocsid from shipped apps on install
georgehrke May 31, 2014
eea501b
various fixes as requested by pr reviewers
georgehrke Jun 2, 2014
19129b3
use isset() instead of array_key_exists()
georgehrke Jun 3, 2014
56a8010
remove console.log in apps.js
georgehrke Jun 4, 2014
2c00ab1
update autoloader
georgehrke Jun 4, 2014
724d027
add unit test
georgehrke Jun 4, 2014
00b7f36
remove not needed unlink in installer test
georgehrke Jun 4, 2014
6aab50f
fix unit tests
DeepDiver1975 Jun 5, 2014
fad3bd7
reenable checkCode()
DeepDiver1975 Jun 5, 2014
0fe8f77
Merge branch 'master' into update_shipped_apps_from_appstore
georgehrke Jun 5, 2014
498aa66
add additional type check
georgehrke Jun 6, 2014
a110973
some additional type checks
georgehrke Jun 6, 2014
1ab9bdc
remove unnecessary @return
georgehrke Jun 10, 2014
5d4f3ba
fix php doc block
georgehrke Jun 10, 2014
6bf0689
always return a bool in OC_App::updateApp
georgehrke Jun 10, 2014
602404c
fix php doc block
georgehrke Jun 10, 2014
5e9fa64
don't show update button when appstore is disabled or no writable dir…
georgehrke Jun 10, 2014
0890ce4
Update preseed-config.php
georgehrke Jun 12, 2014
c378e76
skip certain tests for shipped apps
georgehrke Jun 13, 2014
65028c4
don't skip code check for skipped apps
georgehrke Jun 13, 2014
86f546f
disable code check for shipped apps
georgehrke Jun 16, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add unit test
  • Loading branch information
georgehrke committed Jun 4, 2014
commit 724d027f199f77c6e1442c03dba4b3363f973412
41 changes: 25 additions & 16 deletions lib/private/installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,7 @@ public static function isInstalled( $app ) {
* upgrade.php can determine the current installed version of the app using
* "OC_Appconfig::getValue($appid, 'installed_version')"
*/
public static function updateApp( $app ) {
$appdata = OC_OCSClient::getApplication($app);
$download = OC_OCSClient::getApplicationDownload($app, 1);

if (isset($download['downloadlink']) && trim($download['downloadlink']) !== '') {
$download['downloadlink'] = str_replace(' ', '%20', $download['downloadlink']);
$info = array(
'source' => 'http',
'href' => $download['downloadlink'],
'appdata' => $appdata
);
} else {
throw new \Exception('Could not fetch app info!');
}

public static function updateApp( $info=array() ) {
list($extractDir, $path) = self::downloadApp($info);
$info = self::checkAppsIntegrity($info, $extractDir, $path);

Expand Down Expand Up @@ -206,6 +192,29 @@ public static function updateApp( $app ) {
return OC_App::updateApp($info['id']);
}

/**
* update an app by it's id
* @param integer $ocsid
* @return bool
* @throws Exception
*/
public static function updateAppByOCSId($ocsid) {
$appdata = OC_OCSClient::getApplication($ocsid);
$download = OC_OCSClient::getApplicationDownload($ocsid, 1);

if (isset($download['downloadlink']) && trim($download['downloadlink']) !== '') {
$download['downloadlink'] = str_replace(' ', '%20', $download['downloadlink']);
$info = array(
'source' => 'http',
'href' => $download['downloadlink'],
'appdata' => $appdata
);
} else {
throw new \Exception('Could not fetch app info!');
}

return self::updateApp($info);
}

/**
* @param array $data
Expand Down Expand Up @@ -322,7 +331,7 @@ public static function checkAppsIntegrity($data = array(), $extractDir, $path) {
$version = trim($info['version']);
}

if($version<>trim($data['appdata']['version'])) {
if(isset($data['appdata']['version']) && $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"));
}
Expand Down
2 changes: 1 addition & 1 deletion settings/ajax/updateapp.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

$appId = OC_App::cleanAppId($appId);

$result = OC_Installer::updateApp($appId);
$result = OC_Installer::updateAppByOCSId($appId);
if($result !== false) {
OC_JSON::success(array('data' => array('appid' => $appId)));
} else {
Expand Down
Binary file added tests/data/testapp.zip
Binary file not shown.
Binary file added tests/data/testapp2.zip
Binary file not shown.
74 changes: 74 additions & 0 deletions tests/lib/installer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* Copyright (c) 2014 Georg Ehrke <[email protected]>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/

class Test_Installer extends PHPUnit_Framework_TestCase {

private static $appid = 'testapp';

public function testInstallApp() {
$pathOfTestApp = __DIR__;
$pathOfTestApp .= '/../data/';
$pathOfTestApp .= 'testapp.zip';

$tmp = OC_Helper::tmpFile();
OC_Helper::copyr($pathOfTestApp, $tmp);

$data = array(
'path' => $tmp,
'source' => 'path',
);

OC_Installer::installApp($data);
$isInstalled = OC_Installer::isInstalled(self::$appid);

$this->assertTrue($isInstalled);

//clean-up
OC_Installer::removeApp(self::$appid);
unlink($tmp);
}

public function testUpdateApp() {
$pathOfOldTestApp = __DIR__;
$pathOfOldTestApp .= '/../data/';
$pathOfOldTestApp .= 'testapp.zip';

$oldTmp = OC_Helper::tmpFile();
OC_Helper::copyr($pathOfOldTestApp, $oldTmp);

$oldData = array(
'path' => $oldTmp,
'source' => 'path',
);

$pathOfNewTestApp = __DIR__;
$pathOfNewTestApp .= '/../data/';
$pathOfNewTestApp .= 'testapp2.zip';

$newTmp = OC_Helper::tmpFile();
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);

//clean-up
OC_Installer::removeApp(self::$appid);
unlink($oldTmp);
unlink($newTmp);
}
}