-
Notifications
You must be signed in to change notification settings - Fork 19
/
backup.php
85 lines (72 loc) · 2.48 KB
/
backup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
* ownCloud - Updater plugin
*
* @author Victor Dubiniuk
* @copyright 2014 Victor Dubiniuk victor.dubiniuk@gmail.com
*
* This file is licensed under the Affero General Public License version 3 or
* later.
*/
namespace OCA\Updater;
\OCP\JSON::checkAdminUser();
\OCP\JSON::callCheck();
set_time_limit(0);
clearstatcache();
try {
// Url to download package e.g. http://download.owncloud.org/releases/owncloud-4.0.5.tar.bz2
$packageUrl = '';
//Package version e.g. 4.0.4
$packageVersion = '';
$updateData = App::getFeed();
if (isset($updateData['version']) && $updateData['version'] !== Array()){
$packageVersion = $updateData['version'];
}
if (isset($updateData['url']) && $updateData['url'] !== Array()){
$packageUrl = $updateData['url'];
}
if (!strlen($packageVersion) || !strlen($packageUrl)) {
App::log('Invalid response from update feed.');
throw new \Exception((string) App::$l10n->t('Version not found'));
}
$packageVersionArray = explode('.', $packageVersion);
Helper::checkVersion($packageVersionArray, $packageVersion);
//Some cleanup first
Downloader::cleanUp($packageVersion);
if (!Downloader::isClean($packageVersion)){
$message = App::$l10n->t('Upgrade is not possible. Your web server does not have permission to remove the following directory:');
$message .= '<br />' . Downloader::getPackageDir($packageVersion);
$message .= '<br />' . App::$l10n->t('Update permissions on this directory and its content or remove it manually first.');
throw new \Exception($message);
}
Updater::cleanUp();
if (!Updater::isClean()){
$message = App::$l10n->t('Upgrade is not possible. Your web server does not have permission to remove the following directory:');
$message .= '<br />' . Updater::getTempDir();
$message .= '<br />' . App::$l10n->t('Update permissions on this directory and its content or remove it manually first.');
throw new \Exception($message);
}
$backupPath = Backup::create($packageVersion);
\OCP\JSON::success(array(
'backup' => $backupPath,
'version' => $packageVersion,
'url' => $packageUrl
));
} catch (PermissionException $e){
//Something is not writable|readable
\OCP\JSON::error(array(
'message' => $e->getExtendedMessage()
));
} catch (FsException $e){
//Backup failed
App::log($e->getMessage());
\OCP\JSON::error(array(
'message' => $e->getMessage()
));
} catch (\Exception $e){
//Something went wrong. We don't know what
App::log($e->getMessage());
\OCP\JSON::error(array(
'message' => $e->getMessage()
));
}