source: extensions/autoupdate/include/functions_remote.inc.php @ 6167

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

Upgrade work for 2.1.
Language keys have not been inserted yet.

File size: 3.2 KB
Line 
1<?php
2
3function autoupdate_check_version($version=PHPWG_VERSION)
4{
5  global $conf;
6
7  if (!isset($_SESSION['need_update']))
8  {
9    $_SESSION['need_update'] = null;
10
11    if (preg_match('/(\d+\.\d+)\.(\d+)/', $version, $matches)
12      and @fetchRemote(PHPWG_URL.'/download/all_versions.php', $result))
13    {
14      $all_versions = @explode("\n", $result);
15      $new_version = trim($all_versions[0]);
16      $_SESSION['need_update'] = version_compare($version, $new_version, '<');
17    }
18  }
19
20  if ($_SESSION['need_update'])
21  {
22    return l10n('A new version of Piwigo is available.').'<br>'
23          . '<a href="admin.php?page=plugin&amp;section=autoupdate%2Fautoupdate.php">'.l10n('Click here to upgrade automatically').'</a>';
24  }
25  else
26  {
27    // Gallery is up to date
28    // Check plugins upgrade
29    include_once(PHPWG_ROOT_PATH.'admin/include/plugins.class.php');
30    $plugins = new plugins();
31    $ignore_list = unserialize($conf['autoupdate_ignore_list']);
32
33    if (!isset($_SESSION['plugins_need_update']))
34    {
35      $_SESSION['plugins_need_update'] = null;
36      autoupdate_check_plugins_upgrade($plugins, $ignore_list);
37    }
38    elseif (!empty($_SESSION['plugins_need_update']))
39    {
40      // Check if plugins have been upgraded since last check
41      foreach($plugins->fs_plugins as $plugin_id => $fs_plugin)
42      {
43        if (isset($_SESSION['plugins_need_update'][$plugin_id])
44          and $plugins->plugin_version_compare($fs_plugin['version'], $_SESSION['plugins_need_update'][$plugin_id]))
45        {
46          // Plugin have been updated
47          autoupdate_check_plugins_upgrade($plugins, $ignore_list);
48        }
49      }
50    }
51
52    if (!empty($_SESSION['plugins_need_update']))
53    {
54      return l10n('Some upgrades are available for you plugins').'<br>'
55        . '<a href="admin.php?page=plugins_update">'.l10n('Click here see upgrade plugins page').'</a>';
56    }
57  }
58
59  if ($_SESSION['need_update'] === false and $_SESSION['plugins_need_update'] === array())
60  {
61    return l10n('Gallery and plugins are up to date');
62  }
63  else
64  {
65    return l10n('Unable to check upgrades...')
66      . '<br><a href="admin.php?action=check_autoupdate">'
67      . l10n('Click here to check upgrades now') . '</a>';
68  }
69}
70
71function autoupdate_check_plugins_upgrade($plugins, $ignore_list)
72{
73  if ($plugins->get_server_plugins())
74  {
75    $new_ignore_list = array();
76    $_SESSION['plugins_need_update'] = array();
77
78    foreach($plugins->fs_plugins as $plugin_id => $fs_plugin)
79    {
80      if (isset($fs_plugin['extension']) and isset($plugins->server_plugins[$fs_plugin['extension']]))
81      {
82        $plugin_info = $plugins->server_plugins[$fs_plugin['extension']];
83
84        if (!$plugins->plugin_version_compare($fs_plugin['version'], $plugin_info['revision_name']))
85        {
86          if (in_array($fs_plugin['name'], $ignore_list))
87          {
88            array_push($new_ignore_list, $fs_plugin['name']);
89          }
90          else
91          {
92            $_SESSION['plugins_need_update'][$plugin_id] = $plugin_info['revision_name'];
93          }
94        }
95      }
96    }
97
98    // Update ignore list in database
99    $query = '
100UPDATE '.CONFIG_TABLE.'
101SET value = "'.addslashes(serialize($new_ignore_list)).'"
102WHERE param = "autoupdate_ignore_list"
103;';
104    pwg_query($query);
105  }
106}
107
108?>
Note: See TracBrowser for help on using the repository browser.