source: extensions/autoupdate/trunk/autoupdate.php @ 6168

Last change on this file since 6168 was 6168, checked in by patdenice, 14 years ago

Create branch 1.7

File size: 6.4 KB
Line 
1<?php
2
3load_language('plugin.lang', dirname(__FILE__).'/');
4include(AUTOUPDATE_PATH.'include/functions.inc.php');
5include(PHPWG_ROOT_PATH.'admin/include/pclzip.lib.php');
6
7/*
8STEP:
90 = check is needed. If version is latest or check fail, we stay on step 0
101 = new version on same branch AND new branch are available => user may choose upgrade.
112 = upgrade on same branch
123 = upgrade on different branch
13*/
14$step = isset($_GET['step']) ? $_GET['step'] : 0;
15
16// +-----------------------------------------------------------------------+
17// |                                Step 0                                 |
18// +-----------------------------------------------------------------------+
19if ($step == 0)
20{
21  if (preg_match('/(\d+\.\d+)\.(\d+)/', PHPWG_VERSION, $matches)
22    and @fetchRemote(PHPWG_URL.'/download/all_versions.php', $result)
23    and $all_versions = @explode("\n", $result)
24    and is_array($all_versions))
25  {
26    $template->assign('CHECK_VERSION', true);
27
28    $last_version = trim($all_versions[0]);
29
30    if (version_compare(PHPWG_VERSION, $last_version, '<'))
31    {
32      $new_branch = preg_replace('/(\d+\.\d+)\.\d+/', '$1', $last_version);
33      $actual_branch = $matches[1];
34
35      if ($new_branch == $actual_branch)
36      {
37        $step = 2;
38      }
39      else
40      {
41        $step = 3;
42
43        // Check if new version exists in same branch
44        foreach ($all_versions as $version)
45        {
46          $new_branch = preg_replace('/(\d+\.\d+)\.\d+/', '$1', $version);
47
48          if ($new_branch == $actual_branch)
49          {
50            if (version_compare(PHPWG_VERSION, $version, '<'))
51            {
52              $step = 1;
53            }
54            break;
55          }
56        }
57      }
58    }
59  }
60  else
61  {
62    $template->assign('CHECK_VERSION', false);
63  }
64}
65
66// +-----------------------------------------------------------------------+
67// |                                Step 1                                 |
68// +-----------------------------------------------------------------------+
69if ($step == 1)
70{
71  $new_versions = array($last_version, $version);
72  $template->assign('new_versions', $new_versions);
73}
74
75// +-----------------------------------------------------------------------+
76// |                                Step 2                                 |
77// +-----------------------------------------------------------------------+
78if ($step == 2)
79{
80  if (isset($_POST['submit']) and isset($_POST['upgrade_to']))
81  {
82    upgrade_to($_POST['upgrade_to'], $step);
83  }
84
85  $template->assign('UPGRADE_TO', isset($_GET['to']) ? $_GET['to'] : $last_version);
86}
87
88// +-----------------------------------------------------------------------+
89// |                                Step 3                                 |
90// +-----------------------------------------------------------------------+
91if ($step == 3)
92{
93  if (isset($_POST['saveTemplate']))
94  {
95    $path = $conf['local_data_dir'].'/autoupdate';
96
97    if (@mkgetdir($path)
98      and ($zip = tempnam($path, 'zip'))
99      and ($archive = new pclZip($zip))
100      and ($v_list = $archive->add(PHPWG_ROOT_PATH.'template', PCLZIP_OPT_REMOVE_PATH, PHPWG_ROOT_PATH))
101      and is_array($v_list)
102      and !empty($v_list))
103    {
104      $http_headers = array(
105        'Content-Length: '.@filesize($zip),
106        'Content-Type: application/zip',
107        'Content-Disposition: attachment; filename="template.zip";',
108        'Content-Transfer-Encoding: binary',
109        );
110
111      foreach ($http_headers as $header) {
112        header($header);
113      }
114
115      @readfile($zip);
116      autoupdate_deltree($conf['local_data_dir'].'/autoupdate');
117      exit();
118    }
119
120    array_push($page['errors'], l10n('Unable to send template directory.'));
121  }
122
123  if (isset($_POST['dumpDatabase']))
124  {
125    if (version_compare(PHPWG_VERSION, '2.1', '<'))
126    {
127      global $cfgBase;
128      $conf['db_base'] = $cfgBase;
129    }
130
131    include(AUTOUPDATE_PATH.'include/mysqldump.php');
132
133    $path = $conf['local_data_dir'].'/autoupdate';
134
135    if (@mkgetdir($path)
136      and ($backupFile = tempnam($path, 'sql'))
137      and ($dumper = new MySQLDump($conf['db_base'],$backupFile,false,false)))
138    {
139      $tablesStructure = array(
140        CATEGORIES_TABLE,
141        COMMENTS_TABLE,
142        CONFIG_TABLE,
143        FAVORITES_TABLE,
144        GROUP_ACCESS_TABLE,
145        GROUPS_TABLE,
146        HISTORY_TABLE,
147        HISTORY_SUMMARY_TABLE,
148        IMAGE_CATEGORY_TABLE,
149        IMAGES_TABLE,
150        SESSIONS_TABLE,
151        SITES_TABLE,
152        USER_ACCESS_TABLE,
153        USER_GROUP_TABLE,
154        USERS_TABLE,
155        USER_INFOS_TABLE,
156        USER_FEED_TABLE,
157        WAITING_TABLE,
158        RATE_TABLE,
159        USER_CACHE_TABLE,
160        USER_CACHE_CATEGORIES_TABLE,
161        CADDIE_TABLE,
162        UPGRADE_TABLE,
163        SEARCH_TABLE,
164        USER_MAIL_NOTIFICATION_TABLE,
165        TAGS_TABLE,
166        IMAGE_TAG_TABLE,
167        PLUGINS_TABLE,
168        OLD_PERMALINKS_TABLE,
169        );
170
171      $tablesData = $tablesStructure;
172
173      if (!isset($_POST['includeHistory']))
174      {
175        unset($tablesData[6]);
176      }
177
178      foreach ($tablesStructure as $table)
179      {
180        $dumper->getTableStructure($table); 
181      }
182      foreach ($tablesData as $table)
183      {
184        $dumper->getTableData($table); 
185      }
186    }
187
188    if (@filesize($backupFile))
189    {
190      $http_headers = array(
191        'Content-Length: '.@filesize($backupFile),
192        'Content-Type: text/x-sql',
193        'Content-Disposition: attachment; filename="database.sql";',
194        'Content-Transfer-Encoding: binary',
195        );
196
197      foreach ($http_headers as $header) {
198        header($header);
199      }
200
201      @readfile($backupFile);
202      autoupdate_deltree($conf['local_data_dir'].'/autoupdate');
203      exit();
204    }
205
206    array_push($page['errors'], l10n('Unable to dump database.'));
207  }
208
209  if (isset($_POST['submit']) and isset($_POST['upgrade_to']))
210  {
211    upgrade_to($_POST['upgrade_to'], $step);
212  }
213
214  $template->assign('UPGRADE_TO', isset($_GET['to']) ? $_GET['to'] : $last_version);
215}
216
217// +-----------------------------------------------------------------------+
218// |                        Process template                               |
219// +-----------------------------------------------------------------------+
220
221$template->assign(array(
222  'STEP' => $step,
223  'AU_URL' => get_admin_plugin_menu_link(AUTOUPDATE_PATH . '/autoupdate.php'),
224  )
225);
226
227$template->set_filename('plugin_admin_content', realpath(AUTOUPDATE_PATH.'template/autoupdate.tpl'));
228$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
229
230?>
Note: See TracBrowser for help on using the repository browser.