source: extensions/autoupdate/branches/1.7/autoupdate.php @ 14966

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

Piwigo AutoUpgrade ready for 1.7.x versions.

File size: 4.7 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5include(get_language_filepath('plugin.lang.php', AUTOUPDATE_PATH));
6include(AUTOUPDATE_PATH.'include/functions.inc.php');
7include(AUTOUPDATE_PATH.'include/pclzip.lib.php');
8
9$conf['local_data_dir'] = dirname(dirname(dirname(__FILE__))).'/_data';
10
11/*
12STEP:
130 = check is needed. If version is latest or check fail, we stay on step 0
141 = new version on same branch AND new branch are available => user may choose upgrade.
152 = upgrade on same branch
163 = upgrade on different branch
17*/
18$step = isset($_GET['step']) ? $_GET['step'] : 0;
19$upgrade_to = isset($_GET['to']) ? $_GET['to'] : '';
20
21// +-----------------------------------------------------------------------+
22// |                                Step 0                                 |
23// +-----------------------------------------------------------------------+
24if ($step == 0)
25{
26  if (preg_match('/(\d+\.\d+)\.(\d+)/', PHPWG_VERSION, $matches))
27  {
28    $url = 'http://piwigo.org/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      $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}
70
71// +-----------------------------------------------------------------------+
72// |                                Step 1                                 |
73// +-----------------------------------------------------------------------+
74if ($step == 1)
75{
76  $template->assign_vars(array(
77    'MINOR_VERSION' => $version,
78    'MAJOR_VERSION' => $last_version,
79    'UPGRADE_TO_MINOR_VERSION' => sprintf(l10n('Upgrade to Piwigo %s'), $version),
80    'UPGRADE_TO_MAJOR_VERSION' => sprintf(l10n('Upgrade to Piwigo %s'), $last_version),
81    'UPGRADE_DESC' => sprintf(l10n('You can upgrade to Piwigo %s directly, without upgrading to Piwigo %s (recommended).'), $last_version, $version),
82    )
83  );
84}
85
86// +-----------------------------------------------------------------------+
87// |                                Step 2                                 |
88// +-----------------------------------------------------------------------+
89if ($step == 2 and is_webmaster())
90{
91  if (isset($_POST['submit']) and isset($_POST['upgrade_to']))
92  {
93    autoupdate_upgrade_to($_POST['upgrade_to'], $step);
94  }
95}
96
97// +-----------------------------------------------------------------------+
98// |                                Step 3                                 |
99// +-----------------------------------------------------------------------+
100if ($step == 3 and is_webmaster())
101{
102  if (isset($_POST['saveTemplate']) and version_compare(PHPWG_VERSION, '2.1', '<'))
103  {
104    autoupdate_save_template_dir();
105  }
106
107  if (isset($_POST['dumpDatabase']))
108  {
109    autoupdate_dump_database();
110  }
111
112  if (isset($_POST['submit']) and isset($_POST['upgrade_to']))
113  {
114    autoupdate_upgrade_to($_POST['upgrade_to'], $step);
115  }
116}
117
118// +-----------------------------------------------------------------------+
119// |                        Process template                               |
120// +-----------------------------------------------------------------------+
121
122if (!is_webmaster())
123{
124  array_push($page['errors'], l10n('Webmaster status is required.'));
125}
126
127$template->assign_vars(array(
128  'AU_URL'         => get_admin_plugin_menu_link(AUTOUPDATE_PATH . '/autoupdate.php'),
129  'UPGRADE_TO'     => $upgrade_to,
130  'UPGRADE_TO_VER' => sprintf(l10n('Upgrade to Piwigo %s'), $upgrade_to),
131  'MINOR_UPGRADE_DESC' => l10n('This is a minor upgrade, with only bug corrections.'),
132  'MAJOR_UPGRADE_DESC' => sprintf(l10n('This is a major upgrade, with <a href="%s">new exciting features</a>.'), 'http://piwigo.org/releases/'.$upgrade_to),
133  'RELEASE_URL'    => PHPWG_URL.'/releases/'.$upgrade_to,
134  )
135);
136
137$template->assign_block_vars('step_'.$step, array());
138
139$template->set_filename('plugin_admin_content', 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.