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

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

Update language keys.
Code cleaning.

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