1 | <?php |
---|
2 | |
---|
3 | define('PHPWG_ROOT_PATH','../../../'); |
---|
4 | define('IN_ADMIN', true); |
---|
5 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
6 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
7 | |
---|
8 | if (!defined('AUTOUPDATE_PATH')) |
---|
9 | define('AUTOUPDATE_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(dirname(__FILE__))) . '/'); |
---|
10 | |
---|
11 | check_status(ACCESS_ADMINISTRATOR); |
---|
12 | check_pwg_token(); |
---|
13 | |
---|
14 | if (!is_webmaster()) |
---|
15 | { |
---|
16 | echo json_encode(array( |
---|
17 | 'result' => false, |
---|
18 | 'msg' => l10n('Webmaster status is required.'), |
---|
19 | ) |
---|
20 | ); |
---|
21 | exit; |
---|
22 | } |
---|
23 | |
---|
24 | include_once(PHPWG_ROOT_PATH.'admin/include/plugins.class.php'); |
---|
25 | $plugins = new plugins(); |
---|
26 | |
---|
27 | if (isset($_GET['upgradestatus']) and isset($_GET['id'])) |
---|
28 | { |
---|
29 | switch ($_GET['upgradestatus']) |
---|
30 | { |
---|
31 | case 'ok': |
---|
32 | $result = array( |
---|
33 | 'result' => true, |
---|
34 | 'msg' => sprintf(l10n('%s has been successfully upgraded.'), $plugins->fs_plugins[$_GET['id']]['name']) |
---|
35 | ); |
---|
36 | break; |
---|
37 | |
---|
38 | case 'temp_path_error': |
---|
39 | $result = array( |
---|
40 | 'result' => false, |
---|
41 | 'msg' => l10n('Can\'t create temporary file.') |
---|
42 | ); |
---|
43 | break; |
---|
44 | |
---|
45 | case 'dl_archive_error': |
---|
46 | $result = array( |
---|
47 | 'result' => false, |
---|
48 | 'msg' => l10n('Can\'t download archive.') |
---|
49 | ); |
---|
50 | break; |
---|
51 | |
---|
52 | case 'archive_error': |
---|
53 | $result = array( |
---|
54 | 'result' => false, |
---|
55 | 'msg' => l10n('Can\'t read or extract archive.') |
---|
56 | ); |
---|
57 | break; |
---|
58 | |
---|
59 | default: |
---|
60 | $result = array( |
---|
61 | 'result' => false, |
---|
62 | 'msg' => sprintf(l10n('An error occured during extraction (%s).'), $_GET['upgradestatus']) |
---|
63 | ); |
---|
64 | } |
---|
65 | echo json_encode($result); |
---|
66 | exit; |
---|
67 | } |
---|
68 | |
---|
69 | if (empty($_REQUEST['id']) or empty($_REQUEST['revision'])) |
---|
70 | { |
---|
71 | echo json_encode(array( |
---|
72 | 'result' => false, |
---|
73 | 'msg' => 'Wrong parameters', |
---|
74 | ) |
---|
75 | ); |
---|
76 | exit; |
---|
77 | } |
---|
78 | |
---|
79 | $plugin_id = $_REQUEST['id']; |
---|
80 | $revision = $_REQUEST['revision']; |
---|
81 | |
---|
82 | if (isset($plugins->db_plugins_by_id[$plugin_id]) |
---|
83 | and $plugins->db_plugins_by_id[$plugin_id]['state'] == 'active') |
---|
84 | { |
---|
85 | $plugins->perform_action('deactivate', $plugin_id); |
---|
86 | |
---|
87 | redirect(AUTOUPDATE_PATH |
---|
88 | . 'ajax/update_plugin.php' |
---|
89 | . '?revision=' . $revision |
---|
90 | . '&id=' . $plugin_id |
---|
91 | . '&reactivate=true' |
---|
92 | . '&pwg_token=' . get_pwg_token() |
---|
93 | ); |
---|
94 | } |
---|
95 | |
---|
96 | $upgrade_status = $plugins->extract_plugin_files('upgrade', $revision, $plugin_id); |
---|
97 | |
---|
98 | if (isset($_REQUEST['reactivate'])) |
---|
99 | { |
---|
100 | $plugins->perform_action('activate', $plugin_id); |
---|
101 | } |
---|
102 | |
---|
103 | $template->delete_compiled_templates(); |
---|
104 | |
---|
105 | redirect(AUTOUPDATE_PATH |
---|
106 | . 'ajax/update_plugin.php' |
---|
107 | . '?id=' . $plugin_id |
---|
108 | . '&upgradestatus='.$upgrade_status |
---|
109 | . '&pwg_token=' . get_pwg_token() |
---|
110 | ); |
---|
111 | |
---|
112 | ?> |
---|