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

Last change on this file since 9707 was 9707, checked in by patdenice, 13 years ago

New version 2.2

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