source: extensions/autoupdate/autoupdate.php @ 4699

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

[Plugin][Piwigo Auto Upgrade]
Check upgrade with ajax (avoid timeout)
Check also plugins upgrades

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