source: extensions/autoupdate/trunk/update_pwg.inc.php @ 30809

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

Don't deactivate autoupdate when update itself.
Check merged extensions.

File size: 4.3 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5include_once(AUTOUPDATE_PATH.'include/functions.inc.php');
6include_once(PHPWG_ROOT_PATH.'admin/include/pclzip.lib.php');
7
8/*
9STEP:
100 = check is needed. If version is latest or check fail, we stay on step 0
111 = new version on same branch AND new branch are available => user may choose upgrade.
122 = upgrade on same branch
133 = upgrade on different branch
14*/
15$step = isset($_GET['step']) ? $_GET['step'] : 0;
16$upgrade_to = isset($_GET['to']) ? $_GET['to'] : '';
17
18// +-----------------------------------------------------------------------+
19// |                                Step 0                                 |
20// +-----------------------------------------------------------------------+
21if ($step == 0)
22{
23  $template->assign(array(
24    'CHECK_VERSION' => false,
25    'DEV_VERSION' => false,
26    )
27  );
28
29  if (preg_match('/(\d+\.\d+)\.(\d+)/', PHPWG_VERSION, $matches))
30  {
31    $url = PHPWG_URL.'/download/all_versions.php';
32    $url .= '?rand='.md5(uniqid(rand(), true)); // Avoid server cache
33
34    if (@fetchRemote($url, $result)
35      and $all_versions = @explode("\n", $result)
36      and is_array($all_versions))
37    {
38      $template->assign('CHECK_VERSION', true);
39
40      $last_version = trim($all_versions[0]);
41      $upgrade_to = $last_version;
42
43      if (version_compare(PHPWG_VERSION, $last_version, '<'))
44      {
45        $new_branch = preg_replace('/(\d+\.\d+)\.\d+/', '$1', $last_version);
46        $actual_branch = $matches[1];
47
48        if ($new_branch == $actual_branch)
49        {
50          $step = 2;
51        }
52        else
53        {
54          $step = 3;
55
56          // Check if new version exists in same branch
57          foreach ($all_versions as $version)
58          {
59            $new_branch = preg_replace('/(\d+\.\d+)\.\d+/', '$1', $version);
60
61            if ($new_branch == $actual_branch)
62            {
63              if (version_compare(PHPWG_VERSION, $version, '<'))
64              {
65                $step = 1;
66              }
67              break;
68            }
69          }
70        }
71      }
72    }
73  }
74  else
75  {
76    $template->assign('DEV_VERSION', true);
77  }
78}
79
80// +-----------------------------------------------------------------------+
81// |                                Step 1                                 |
82// +-----------------------------------------------------------------------+
83if ($step == 1)
84{
85  $template->assign(array(
86    'MINOR_VERSION' => $version,
87    'MAJOR_VERSION' => $last_version,
88    )
89  );
90}
91
92// +-----------------------------------------------------------------------+
93// |                                Step 2                                 |
94// +-----------------------------------------------------------------------+
95if ($step == 2 and is_webmaster())
96{
97  if (isset($_POST['submit']) and isset($_POST['upgrade_to']))
98  {
99    autoupdate_upgrade_to($_POST['upgrade_to'], $step);
100  }
101}
102
103// +-----------------------------------------------------------------------+
104// |                                Step 3                                 |
105// +-----------------------------------------------------------------------+
106if ($step == 3 and is_webmaster())
107{
108  if (isset($_POST['dumpDatabase']))
109  {
110    autoupdate_dump_database();
111  }
112
113  if (isset($_POST['submit']) and isset($_POST['upgrade_to']))
114  {
115    autoupdate_upgrade_to($_POST['upgrade_to'], $step);
116  }
117
118  include_once(AUTOUPDATE_PATH.'include/autoupdate.class.php');
119  $autoupdate = new autoupdate();
120  $autoupdate->get_merged_extensions($upgrade_to);
121  $autoupdate->get_server_extensions($upgrade_to);
122  $template->assign('missing', $autoupdate->missing);
123}
124
125// +-----------------------------------------------------------------------+
126// |                        Process template                               |
127// +-----------------------------------------------------------------------+
128
129if (!is_webmaster())
130{
131  array_push($page['errors'], l10n('Webmaster status is required.'));
132}
133
134$template->assign(array(
135  'STEP'          => $step,
136  'AU_URL'        => get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__)),
137  'PHPWG_VERSION' => PHPWG_VERSION,
138  'UPGRADE_TO'    => $upgrade_to,
139  'RELEASE_URL'   => PHPWG_URL.'/releases/'.$upgrade_to,
140  )
141);
142
143$template->set_filename('plugin_admin_content', realpath(AUTOUPDATE_PATH.'template/update_pwg.tpl'));
144$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
145
146?>
Note: See TracBrowser for help on using the repository browser.