source: extensions/autoupdate/autoupdate.php @ 4711

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

[Plugin][Piwigo Auto Upgrade]
If gallery and plugins are up to date, display note on admin homepage only one time for each session.
Allow to disable notification for plugins you don't want to update.

File size: 3.8 KB
Line 
1<?php
2
3load_language('plugin.lang', dirname(__FILE__).'/');
4
5if (isset($_GET['action']) and 
6  ($_GET['action'] == 'check_autoupdate' or $_GET['action'] == 'check_upgrade' ))
7{
8  unset($_SESSION['need_update']);
9  unset($_SESSION['plugins_need_update']);
10}
11
12if (isset($_GET['autoupdate']))
13{
14  if ($_GET['autoupdate'] == 'success')
15  {
16    array_push($page['infos'], sprintf(l10n('autoupdate_success'), PHPWG_VERSION));
17  }
18  elseif ($file = $conf['local_data_dir'].'/autoupdate/'.$_GET['autoupdate'].'.zip' and file_exists($file))
19  {
20    include(dirname(__FILE__).'/class.inc.php');
21    include_once(PHPWG_ROOT_PATH.'admin/include/pclzip.lib.php');
22    $autoupdate = new autoupdate();
23    $zip = new PclZip($file);
24    if ($result = $zip->extract(PCLZIP_OPT_PATH, PHPWG_ROOT_PATH,
25                                PCLZIP_OPT_REMOVE_PATH, $_GET['autoupdate'],
26                                PCLZIP_OPT_SET_CHMOD, 0755,
27                                PCLZIP_OPT_REPLACE_NEWER))
28    {
29      //Check if all files were extracted
30      $error = '';
31      foreach($result as $extract)
32      {
33        if (!in_array($extract['status'], array('ok', 'filtered', 'already_a_directory')))
34        {
35          // Try to change chmod and extract
36          if (@chmod(PHPWG_ROOT_PATH.$extract['filename'], 0777)
37            and ($res = $zip->extract(PCLZIP_OPT_BY_NAME, $_GET['autoupdate'].'/'.$extract['filename'],
38                                      PCLZIP_OPT_PATH, PHPWG_ROOT_PATH,
39                                      PCLZIP_OPT_REMOVE_PATH, $_GET['autoupdate'],
40                                      PCLZIP_OPT_SET_CHMOD, 0755,
41                                      PCLZIP_OPT_REPLACE_NEWER))
42            and isset($res[0]['status'])
43            and $res[0]['status'] == 'ok')
44          {
45            continue;
46          }
47          else
48          {
49            $error .= $extract['filename'].': '.$extract['status']."\n";
50          }
51        }
52      }
53
54      if (empty($error))
55      {
56        if (file_exists(PHPWG_ROOT_PATH.'obsolete.list')
57          and $old_files = file(PHPWG_ROOT_PATH.'obsolete.list', FILE_IGNORE_NEW_LINES)
58          and !empty($old_files))
59        {
60          array_push($old_files, 'obsolete.list');
61          foreach($old_files as $old_file)
62          {
63            $path = PHPWG_ROOT_PATH.$old_file;
64            if (is_file($path))
65            {
66              @unlink($path);
67            }
68            elseif (is_dir($path))
69            {
70              $autoupdate->deltree($path);
71            }
72          }
73        }
74        if (preg_match('/\d+\.\d+\.\d+_to_(\d+\.\d+\.\d+)/', $_GET['autoupdate'], $matches))
75        {
76          unset($_SESSION['need_update']);
77          $autoupdate->check_version($matches[1]);
78        }
79        $autoupdate->deltree($conf['local_data_dir'].'/autoupdate');
80        invalidate_user_cache(true);
81        $template->delete_compiled_templates();
82        redirect('admin.php?autoupdate=success');
83      }
84      else
85      {
86        file_put_contents($conf['local_data_dir'].'/autoupdate/log_error.txt', $error);
87        $relative_path = trim(str_replace(dirname(dirname(dirname(__FILE__))), '', $conf['local_data_dir']), '/\\');
88        array_push($page['errors'], sprintf(l10n('autoupdate_extract_fail'), PHPWG_ROOT_PATH.$relative_path.'/autoupdate/log_error.txt'));
89      }
90    }
91    else
92    {
93      $autoupdate->deltree($conf['local_data_dir'].'/autoupdate');
94      array_push($page['errors'], l10n('autoupdate_fail'));
95    }
96  }
97  else
98  {
99    @unlink($file);
100    array_push($page['errors'], l10n('autoupdate_fail'));
101  }
102}
103
104if (!isset($_SESSION['need_update']) or !isset($_SESSION['plugins_need_update'])
105  or $_SESSION['need_update'] !== false or $_SESSION['plugins_need_update'] !== array())
106{
107  $template->set_filename('autoupdate_head', realpath(dirname(__FILE__).'/head.tpl'));
108  array_push($header_notes, $template->parse('autoupdate_head', true));
109}
110
111?>
Note: See TracBrowser for help on using the repository browser.