source: trunk/admin/updates_pwg.php @ 11803

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

feature:2271
Merge autoupdate plugin into piwigo core.

File size: 5.8 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2010      Pierrick LE GALL             http://piwigo.org |
6// +-----------------------------------------------------------------------+
7// | This program is free software; you can redistribute it and/or modify  |
8// | it under the terms of the GNU General Public License as published by  |
9// | the Free Software Foundation                                          |
10// |                                                                       |
11// | This program is distributed in the hope that it will be useful, but   |
12// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
13// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
14// | General Public License for more details.                              |
15// |                                                                       |
16// | You should have received a copy of the GNU General Public License     |
17// | along with this program; if not, write to the Free Software           |
18// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
19// | USA.                                                                  |
20// +-----------------------------------------------------------------------+
21
22if( !defined("PHPWG_ROOT_PATH") )
23{
24  die ("Hacking attempt!");
25}
26
27include_once(PHPWG_ROOT_PATH.'admin/include/updates.class.php');
28include_once(PHPWG_ROOT_PATH.'admin/include/pclzip.lib.php');
29
30/*
31STEP:
320 = check is needed. If version is latest or check fail, we stay on step 0
331 = new version on same branch AND new branch are available => user may choose upgrade.
342 = upgrade on same branch
353 = upgrade on different branch
36*/
37$step = isset($_GET['step']) ? $_GET['step'] : 0;
38$upgrade_to = isset($_GET['to']) ? $_GET['to'] : '';
39
40// +-----------------------------------------------------------------------+
41// |                                Step 0                                 |
42// +-----------------------------------------------------------------------+
43if ($step == 0)
44{
45  $template->assign(array(
46    'CHECK_VERSION' => false,
47    'DEV_VERSION' => false,
48    )
49  );
50
51  if (preg_match('/(\d+\.\d+)\.(\d+)/', PHPWG_VERSION, $matches))
52  {
53    $url = PHPWG_URL.'/download/all_versions.php';
54    $url .= '?rand='.md5(uniqid(rand(), true)); // Avoid server cache
55
56    if (@fetchRemote($url, $result)
57      and $all_versions = @explode("\n", $result)
58      and is_array($all_versions))
59    {
60      $template->assign('CHECK_VERSION', true);
61
62      $last_version = trim($all_versions[0]);
63      $upgrade_to = $last_version;
64
65      if (version_compare(PHPWG_VERSION, $last_version, '<'))
66      {
67        $new_branch = preg_replace('/(\d+\.\d+)\.\d+/', '$1', $last_version);
68        $actual_branch = $matches[1];
69
70        if ($new_branch == $actual_branch)
71        {
72          $step = 2;
73        }
74        else
75        {
76          $step = 3;
77
78          // Check if new version exists in same branch
79          foreach ($all_versions as $version)
80          {
81            $new_branch = preg_replace('/(\d+\.\d+)\.\d+/', '$1', $version);
82
83            if ($new_branch == $actual_branch)
84            {
85              if (version_compare(PHPWG_VERSION, $version, '<'))
86              {
87                $step = 1;
88              }
89              break;
90            }
91          }
92        }
93      }
94    }
95  }
96  else
97  {
98    $template->assign('DEV_VERSION', true);
99  }
100}
101
102// +-----------------------------------------------------------------------+
103// |                                Step 1                                 |
104// +-----------------------------------------------------------------------+
105if ($step == 1)
106{
107  $template->assign(array(
108    'MINOR_VERSION' => $version,
109    'MAJOR_VERSION' => $last_version,
110    )
111  );
112}
113
114// +-----------------------------------------------------------------------+
115// |                                Step 2                                 |
116// +-----------------------------------------------------------------------+
117if ($step == 2 and is_webmaster())
118{
119  if (isset($_POST['submit']) and isset($_POST['upgrade_to']))
120  {
121    updates::upgrade_to($_POST['upgrade_to'], $step);
122  }
123}
124
125// +-----------------------------------------------------------------------+
126// |                                Step 3                                 |
127// +-----------------------------------------------------------------------+
128if ($step == 3 and is_webmaster())
129{
130  if (isset($_POST['dumpDatabase']))
131  {
132    updates::dump_database(isset($_POST['includeHistory']));
133  }
134
135  if (isset($_POST['submit']) and isset($_POST['upgrade_to']))
136  {
137    updates::upgrade_to($_POST['upgrade_to'], $step);
138  }
139
140  $updates = new updates();
141  $updates->get_merged_extensions($upgrade_to);
142  $updates->get_server_extensions($upgrade_to);
143  $template->assign('missing', $updates->missing);
144}
145
146// +-----------------------------------------------------------------------+
147// |                        Process template                               |
148// +-----------------------------------------------------------------------+
149
150if (!is_webmaster())
151{
152  array_push($page['errors'], l10n('Webmaster status is required.'));
153}
154
155$template->assign(array(
156  'STEP'          => $step,
157  'PHPWG_VERSION' => PHPWG_VERSION,
158  'UPGRADE_TO'    => $upgrade_to,
159  'RELEASE_URL'   => PHPWG_URL.'/releases/'.$upgrade_to,
160  )
161);
162
163$template->set_filename('plugin_admin_content', 'updates_pwg.tpl');
164$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
165
166?>
Note: See TracBrowser for help on using the repository browser.