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
RevLine 
[3604]1<?php
2
[6167]3include(AUTOUPDATE_PATH.'include/functions.inc.php');
4include(PHPWG_ROOT_PATH.'admin/include/pclzip.lib.php');
[4032]5
[6167]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;
[6181]14$upgrade_to = isset($_GET['to']) ? $_GET['to'] : '';
[3604]15
[6167]16// +-----------------------------------------------------------------------+
17// |                                Step 0                                 |
18// +-----------------------------------------------------------------------+
19if ($step == 0)
[3604]20{
[6181]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))
[3604]28  {
[6181]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);
[6167]34
[6181]35      $last_version = trim($all_versions[0]);
36      $upgrade_to = $last_version;
[6167]37
[6181]38      if (version_compare(PHPWG_VERSION, $last_version, '<'))
[3604]39      {
[6181]40        $new_branch = preg_replace('/(\d+\.\d+)\.\d+/', '$1', $last_version);
41        $actual_branch = $matches[1];
[4007]42
[6181]43        if ($new_branch == $actual_branch)
[4007]44        {
[6181]45          $step = 2;
46        }
47        else
48        {
49          $step = 3;
[6167]50
[6181]51          // Check if new version exists in same branch
52          foreach ($all_versions as $version)
[4007]53          {
[6181]54            $new_branch = preg_replace('/(\d+\.\d+)\.\d+/', '$1', $version);
55
56            if ($new_branch == $actual_branch)
[4007]57            {
[6181]58              if (version_compare(PHPWG_VERSION, $version, '<'))
59              {
60                $step = 1;
61              }
62              break;
[4007]63            }
64          }
65        }
[3898]66      }
[6167]67    }
68  }
69  else
70  {
[6181]71    $template->assign('DEV_VERSION', true);
[6167]72  }
73}
74
75// +-----------------------------------------------------------------------+
76// |                                Step 1                                 |
77// +-----------------------------------------------------------------------+
78if ($step == 1)
79{
[6181]80  $template->assign(array(
81    'MINOR_VERSION' => $version,
82    'MAJOR_VERSION' => $last_version,
83    )
84  );
[6167]85}
86
87// +-----------------------------------------------------------------------+
88// |                                Step 2                                 |
89// +-----------------------------------------------------------------------+
90if ($step == 2)
91{
92  if (isset($_POST['submit']) and isset($_POST['upgrade_to']))
93  {
[6181]94    autoupdate_upgrade_to($_POST['upgrade_to'], $step);
[6167]95  }
96}
97
98// +-----------------------------------------------------------------------+
99// |                                Step 3                                 |
100// +-----------------------------------------------------------------------+
101if ($step == 3)
102{
103  if (isset($_POST['saveTemplate']))
104  {
[6181]105    autoupdate_save_template_dir();
[6167]106  }
107
108  if (isset($_POST['dumpDatabase']))
109  {
[6181]110    autoupdate_dump_database();
[3604]111  }
[6167]112
113  if (isset($_POST['submit']) and isset($_POST['upgrade_to']))
[3604]114  {
[6181]115    autoupdate_upgrade_to($_POST['upgrade_to'], $step);
[3604]116  }
[4711]117}
[4699]118
[6167]119// +-----------------------------------------------------------------------+
120// |                        Process template                               |
121// +-----------------------------------------------------------------------+
122
123$template->assign(array(
[6181]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,
[6167]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
[3575]134?>
Note: See TracBrowser for help on using the repository browser.