Changeset 9729


Ignore:
Timestamp:
03/16/11 19:27:11 (9 years ago)
Author:
patdenice
Message:

Only one request to PEM server for plugins, themes and languages.

Location:
extensions/autoupdate/trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • extensions/autoupdate/trunk/ajax/check_updates.php

    r9712 r9729  
    55include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); 
    66include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); 
     7include_once(AUTOUPDATE_PATH.'include/autoupdate.class.php'); 
     8$autoupdate = new autoupdate(); 
    79 
    810check_status(ACCESS_ADMINISTRATOR); 
     
    1214header('Content-Type: text/html; charset=UTF-8'); 
    1315 
     16function autoupdate_error() 
     17{ 
     18  unset($_SESSION['extensions_need_update']); 
     19  echo 'error'; 
     20  exit; 
     21} 
     22 
    1423if (!isset($_SESSION['need_update'])) 
    1524{ 
    16   $_SESSION['need_update'] = null; 
    17  
    18   if (preg_match('/(\d+\.\d+)\.(\d+)/', PHPWG_VERSION, $matches) 
    19     and @fetchRemote(PHPWG_URL.'/download/all_versions.php', $result)) 
    20   { 
    21     $all_versions = @explode("\n", $result); 
    22     $new_version = trim($all_versions[0]); 
    23     $_SESSION['need_update'] = version_compare(PHPWG_VERSION, $new_version, '<'); 
    24   } 
     25  $autoupdate->check_piwigo_upgrade(); 
    2526} 
    2627 
     
    3132else 
    3233{ 
    33   // Gallery is up to date 
    34   // Check plugins upgrade 
    35   include_once(PHPWG_ROOT_PATH.'admin/include/plugins.class.php'); 
    36   include_once(PHPWG_ROOT_PATH.'admin/include/themes.class.php'); 
    37   include_once(PHPWG_ROOT_PATH.'admin/include/languages.class.php'); 
    38   $plugins = new plugins(); 
    39   $themes = new themes(); 
    40   $languages = new languages(); 
    41  
     34  // Gallery is up to date -> check extensions 
    4235  if (!isset($_SESSION['extensions_need_update'])) 
    4336  { 
    44     $_SESSION['extensions_need_update'] = array(); 
    45     autoupdate_check_plugins_upgrade($plugins); 
    46     autoupdate_check_themes_upgrade($themes); 
    47     autoupdate_check_languages_upgrade($languages); 
     37    $autoupdate->check_extensions(); 
    4838  } 
    4939  else 
    5040  { 
    51     if (!empty($_SESSION['extensions_need_update']['plugins'])) 
    52     { 
    53       // Check if plugins have been upgraded since last check 
    54       foreach($plugins->fs_plugins as $plugin_id => $fs_plugin) 
    55       { 
    56         if (isset($_SESSION['extensions_need_update']['plugins'][$plugin_id]) 
    57           and $plugins->plugin_version_compare($fs_plugin['version'], $_SESSION['extensions_need_update']['plugins'][$plugin_id])) 
    58         { 
    59           // Plugin have been updated 
    60           autoupdate_check_plugins_upgrade($plugins); 
    61         } 
    62       } 
    63     } 
    64     if (!empty($_SESSION['extensions_need_update']['themes'])) 
    65     { 
    66       // Check if themes have been upgraded since last check 
    67       foreach($themes->fs_themes as $theme_id => $fs_theme) 
    68       { 
    69         if (isset($_SESSION['extensions_need_update']['themes'][$theme_id]) 
    70           and $themes->theme_version_compare($fs_theme['version'], $_SESSION['extensions_need_update']['themes'][$theme_id])) 
    71         { 
    72           // theme have been updated 
    73           autoupdate_check_themes_upgrade($themes); 
    74         } 
    75       } 
    76     } 
    77     if (!empty($_SESSION['extensions_need_update']['languages'])) 
    78     { 
    79       // Check if languages have been upgraded since last check 
    80       foreach($languages->fs_languages as $language_id => $fs_language) 
    81       { 
    82         if (isset($_SESSION['extensions_need_update']['languages'][$language_id]) 
    83           and $languages->language_version_compare($fs_language['version'], $_SESSION['extensions_need_update']['languages'][$language_id])) 
    84         { 
    85           // language have been updated 
    86           autoupdate_check_languages_upgrade($languages); 
    87         } 
    88       } 
    89     } 
    90   } 
    91  
    92   if (!empty($_SESSION['extensions_need_update'])) 
    93   { 
    94     echo 'ext_upgrade'; exit; 
     41    $autoupdate->check_updated_extensions(); 
    9542  } 
    9643} 
    9744 
    98 if ($_SESSION['need_update'] === false and $_SESSION['extensions_need_update'] === array()) 
     45if (!empty($_SESSION['extensions_need_update'])) 
     46{ 
     47  echo 'ext_upgrade'; exit; 
     48} 
     49elseif ($_SESSION['need_update'] === false and $_SESSION['extensions_need_update'] === array()) 
    9950{ 
    10051  echo 'up_to_date'; exit; 
     
    10556} 
    10657 
    107 function autoupdate_check_plugins_upgrade($plugins) 
    108 { 
    109   global $conf; 
    110  
    111   if (!$plugins->get_server_plugins()) 
    112   { 
    113     autoupdate_error(); 
    114   } 
    115  
    116   $plugins_ignore_list = array(); 
    117   $need_upgrade = array(); 
    118  
    119   foreach($plugins->fs_plugins as $plugin_id => $fs_plugin) 
    120   { 
    121     if (isset($fs_plugin['extension']) and isset($plugins->server_plugins[$fs_plugin['extension']])) 
    122     { 
    123       $plugin_info = $plugins->server_plugins[$fs_plugin['extension']]; 
    124  
    125       if (!$plugins->plugin_version_compare($fs_plugin['version'], $plugin_info['revision_name'])) 
    126       { 
    127         if (in_array($plugin_id, $conf['AU_ignore']['plugins'])) 
    128         { 
    129           array_push($plugins_ignore_list, $plugin_id); 
    130         } 
    131         else 
    132         { 
    133           $_SESSION['extensions_need_update']['plugins'][$plugin_id] = $plugin_info['revision_name']; 
    134         } 
    135       } 
    136     } 
    137   } 
    138  
    139   $conf['AU_ignore']['plugins'] = $plugins_ignore_list; 
    140   conf_update_param('autoupdate_ignore_list', pwg_db_real_escape_string(serialize($conf['AU_ignore']))); 
    141 } 
    142  
    143 function autoupdate_check_themes_upgrade($themes) 
    144 { 
    145   global $conf; 
    146  
    147   if (!$themes->get_server_themes()) 
    148   { 
    149     autoupdate_error(); 
    150   } 
    151    
    152   $themes_ignore_list = array(); 
    153   $need_upgrade = array(); 
    154  
    155   foreach($themes->fs_themes as $theme_id => $fs_theme) 
    156   { 
    157     if (isset($fs_theme['extension']) and isset($themes->server_themes[$fs_theme['extension']])) 
    158     { 
    159       $theme_info = $themes->server_themes[$fs_theme['extension']]; 
    160  
    161       if (!$themes->theme_version_compare($fs_theme['version'], $theme_info['revision_name'])) 
    162       { 
    163         if (in_array($theme_id, $conf['AU_ignore']['theme'])) 
    164         { 
    165           array_push($themes_ignore_list, $theme_id); 
    166         } 
    167         else 
    168         { 
    169           $_SESSION['extensions_need_update']['themes'][$theme_id] = $theme_info['revision_name']; 
    170         } 
    171       } 
    172     } 
    173   } 
    174  
    175   $conf['AU_ignore']['themes'] = $themes_ignore_list; 
    176   conf_update_param('autoupdate_ignore_list', pwg_db_real_escape_string(serialize($conf['AU_ignore']))); 
    177 } 
    178  
    179 function autoupdate_check_languages_upgrade($languages) 
    180 { 
    181   global $conf; 
    182  
    183   if (!$languages->get_server_languages()) 
    184   { 
    185     autoupdate_error(); 
    186   } 
    187  
    188   $languages_ignore_list = array(); 
    189   $need_upgrade = array(); 
    190  
    191   foreach($languages->fs_languages as $language_id => $fs_language) 
    192   { 
    193     if (isset($fs_language['extension']) and isset($languages->server_languages[$fs_language['extension']])) 
    194     { 
    195       $language_info = $languages->server_languages[$fs_language['extension']]; 
    196  
    197       if (!$languages->language_version_compare($fs_language['version'], $language_info['revision_name'])) 
    198       { 
    199         if (in_array($language_id, $conf['AU_ignore']['languages'])) 
    200         { 
    201           array_push($languages_ignore_list, $language_id); 
    202         } 
    203         else 
    204         { 
    205           $_SESSION['extensions_need_update']['languages'][$language_id] = $language_info['revision_name']; 
    206         } 
    207       } 
    208     } 
    209   } 
    210  
    211   $conf['AU_ignore']['languages'] = $languages_ignore_list; 
    212   conf_update_param('autoupdate_ignore_list', pwg_db_real_escape_string(serialize($conf['AU_ignore']))); 
    213 } 
    214  
    215 function autoupdate_error() 
    216 { 
    217   $_SESSION['extensions_need_update'] = null; 
    218    
    219   echo 'error'; exit; 
    220 } 
    221  
    22258?> 
  • extensions/autoupdate/trunk/template/update_ext.tpl

    r9723 r9729  
    4646<legend>{'Plugins which need upgrade'|@translate}</legend> 
    4747{foreach from=$update_plugins item=plugin name=plugins_loop} 
    48 <div class="pluginBox" id="plugin_{$plugin.PLUGIN_ID}" {if $plugin.IGNORED}style="display:none;"{/if}> 
     48<div class="pluginBox" id="plugin_{$plugin.EXT_ID}" {if $plugin.IGNORED}style="display:none;"{/if}> 
    4949  <table> 
    5050    <tr> 
     
    5353      </td> 
    5454      <td> 
    55         <a href="#" onClick="upgradeExtension('plugin', '{$plugin.PLUGIN_ID}', {$plugin.REVISION_ID});" class="updateExtension">{'Install'|@translate}</a> 
     55        <a href="#" onClick="upgradeExtension('plugin', '{$plugin.EXT_ID}', {$plugin.REVISION_ID});" class="updateExtension">{'Install'|@translate}</a> 
    5656        | <a href="{$plugin.URL_DOWNLOAD}">{'Download'|@translate}</a> 
    57         | <a href="#" onClick="ignoreExtension('plugin', '{$plugin.PLUGIN_ID}');">{'autoupdate_ignore'|@translate}</a> 
     57        | <a href="#" onClick="ignoreExtension('plugin', '{$plugin.EXT_ID}');">{'autoupdate_ignore'|@translate}</a> 
    5858      </td> 
    5959    </tr> 
     
    8888<legend>{'Themes which need upgrade'|@translate}</legend> 
    8989{foreach from=$update_themes item=theme name=themes_loop} 
    90 <div class="pluginBox" id="theme_{$theme.THEME_ID}" {if $theme.IGNORED}style="display:none;"{/if}> 
     90<div class="pluginBox" id="theme_{$theme.EXT_ID}" {if $theme.IGNORED}style="display:none;"{/if}> 
    9191  <table> 
    9292    <tr> 
     
    9595      </td> 
    9696      <td> 
    97         <a href="#" onClick="upgradeExtension('theme', '{$theme.THEME_ID}', {$theme.REVISION_ID});" class="updateExtension">{'Install'|@translate}</a> 
     97        <a href="#" onClick="upgradeExtension('theme', '{$theme.EXT_ID}', {$theme.REVISION_ID});" class="updateExtension">{'Install'|@translate}</a> 
    9898        | <a href="{$theme.URL_DOWNLOAD}">{'Download'|@translate}</a> 
    99         | <a href="#" onClick="ignoreExtension('theme', '{$theme.THEME_ID}');">{'autoupdate_ignore'|@translate}</a> 
     99        | <a href="#" onClick="ignoreExtension('theme', '{$theme.EXT_ID}');">{'autoupdate_ignore'|@translate}</a> 
    100100      </td> 
    101101    </tr> 
     
    130130<legend>{'Languages which need upgrade'|@translate}</legend> 
    131131{foreach from=$update_languages item=language name=languages_loop} 
    132 <div class="pluginBox" id="language_{$language.LANGUAGE_ID}" {if $language.IGNORED}style="display:none;"{/if}> 
     132<div class="pluginBox" id="language_{$language.EXT_ID}" {if $language.IGNORED}style="display:none;"{/if}> 
    133133  <table> 
    134134    <tr> 
     
    137137      </td> 
    138138      <td> 
    139         <a href="#" onClick="upgradeExtension('language', '{$language.LANGUAGE_ID}', {$language.REVISION_ID});" class="updateExtension">{'Install'|@translate}</a> 
     139        <a href="#" onClick="upgradeExtension('language', '{$language.EXT_ID}', {$language.REVISION_ID});" class="updateExtension">{'Install'|@translate}</a> 
    140140        | <a href="{$language.URL_DOWNLOAD}">{'Download'|@translate}</a> 
    141         | <a href="#" onClick="ignoreExtension('language', '{$language.LANGUAGE_ID}');">{'autoupdate_ignore'|@translate}</a> 
     141        | <a href="#" onClick="ignoreExtension('language', '{$language.EXT_ID}');">{'autoupdate_ignore'|@translate}</a> 
    142142      </td> 
    143143    </tr> 
  • extensions/autoupdate/trunk/update_ext.inc.php

    r9723 r9729  
    33if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 
    44 
    5 // Plugins 
    6 include_once(PHPWG_ROOT_PATH.'admin/include/plugins.class.php'); 
    7 $plugins = new plugins(); 
    8 $update_plugins = array(); 
    9 if ($plugins->get_server_plugins()) 
     5include_once(AUTOUPDATE_PATH.'include/autoupdate.class.php'); 
     6$autoupdate = new autoupdate(); 
     7 
     8if (!$autoupdate->get_server_extensions()) 
    109{ 
    11   foreach($plugins->fs_plugins as $plugin_id => $fs_plugin) 
     10  array_push($page['errors'], l10n('Can\'t connect to server.')); 
     11  return; 
     12} 
     13 
     14foreach ($autoupdate->types as $type) 
     15{ 
     16  $fs = 'fs_'.$type; 
     17  $server = 'server_'.$type; 
     18  $server_ext = $autoupdate->$type->$server; 
     19  $fs_ext = $autoupdate->$type->$fs; 
     20 
     21  if (!empty($server_ext)) 
    1222  { 
    13     if (isset($fs_plugin['extension']) 
    14       and isset($plugins->server_plugins[$fs_plugin['extension']])) 
     23    foreach($fs_ext as $ext_id => $fs_ext) 
    1524    { 
    16       $plugin_info = $plugins->server_plugins[$fs_plugin['extension']]; 
     25      if (isset($fs_ext['extension']) and isset($server_ext[$fs_ext['extension']])) 
     26      { 
     27        $ext_info = $server_ext[$fs_ext['extension']]; 
    1728 
    18       if (!$plugins->plugin_version_compare($fs_plugin['version'], $plugin_info['revision_name'])) 
    19       { 
    20         $update_plugins[] = array( 
    21           'ID' => $plugin_info['extension_id'], 
    22           'PLUGIN_ID' => $plugin_id, 
    23           'REVISION_ID' => $plugin_info['revision_id'], 
    24           'EXT_NAME' => $fs_plugin['name'], 
    25           'EXT_URL' => PEM_URL.'/extension_view.php?eid='.$plugin_info['extension_id'], 
    26           'EXT_DESC' => trim($plugin_info['extension_description'], " \n\r"), 
    27           'REV_DESC' => trim($plugin_info['revision_description'], " \n\r"), 
    28           'CURRENT_VERSION' => $fs_plugin['version'], 
    29           'NEW_VERSION' => $plugin_info['revision_name'], 
    30           'AUTHOR' => $plugin_info['author_name'], 
    31           'DOWNLOADS' => $plugin_info['extension_nb_downloads'], 
    32           'URL_DOWNLOAD' => $plugin_info['download_url'] . '&amp;origin=piwigo_download', 
    33           'IGNORED' => in_array($plugin_id, $conf['AU_ignore']['plugins']), 
    34         ); 
     29        if (!$autoupdate->version_compare($fs_ext['version'], $ext_info['revision_name'], $type)) 
     30        { 
     31          $template->append('update_'.$type, array( 
     32            'ID' => $ext_info['extension_id'], 
     33            'REVISION_ID' => $ext_info['revision_id'], 
     34            'EXT_ID' => $ext_id, 
     35            'EXT_NAME' => $fs_ext['name'], 
     36            'EXT_URL' => PEM_URL.'/extension_view.php?eid='.$ext_info['extension_id'], 
     37            'EXT_DESC' => trim($ext_info['extension_description'], " \n\r"), 
     38            'REV_DESC' => trim($ext_info['revision_description'], " \n\r"), 
     39            'CURRENT_VERSION' => $fs_ext['version'], 
     40            'NEW_VERSION' => $ext_info['revision_name'], 
     41            'AUTHOR' => $ext_info['author_name'], 
     42            'DOWNLOADS' => $ext_info['extension_nb_downloads'], 
     43            'URL_DOWNLOAD' => $ext_info['download_url'] . '&amp;origin=piwigo_download', 
     44            'IGNORED' => in_array($ext_id, $conf['AU_ignore']['plugins']), 
     45            ) 
     46          ); 
     47        } 
    3548      } 
    3649    } 
     
    3851} 
    3952 
    40 // Themes 
    41 include_once(PHPWG_ROOT_PATH.'admin/include/themes.class.php'); 
    42 $themes = new themes(); 
    43 $update_themes = array(); 
    44 if ($themes->get_server_themes()) 
    45 { 
    46   foreach($themes->fs_themes as $theme_id => $fs_theme) 
    47   { 
    48     if (isset($fs_theme['extension']) 
    49       and isset($themes->server_themes[$fs_theme['extension']])) 
    50     { 
    51       $theme_info = $themes->server_themes[$fs_theme['extension']]; 
    52  
    53       if (!$themes->theme_version_compare($fs_theme['version'], $theme_info['revision_name'])) 
    54       { 
    55         $update_themes[] = array( 
    56           'ID' => $theme_info['extension_id'], 
    57           'THEME_ID' => $theme_id, 
    58           'REVISION_ID' => $theme_info['revision_id'], 
    59           'EXT_NAME' => $fs_theme['name'], 
    60           'EXT_URL' => PEM_URL.'/extension_view.php?eid='.$theme_info['extension_id'], 
    61           'EXT_DESC' => trim($theme_info['extension_description'], " \n\r"), 
    62           'REV_DESC' => trim($theme_info['revision_description'], " \n\r"), 
    63           'CURRENT_VERSION' => $fs_theme['version'], 
    64           'NEW_VERSION' => $theme_info['revision_name'], 
    65           'AUTHOR' => $theme_info['author_name'], 
    66           'DOWNLOADS' => $theme_info['extension_nb_downloads'], 
    67           'URL_DOWNLOAD' => $theme_info['download_url'] . '&amp;origin=piwigo_download', 
    68           'IGNORED' => in_array($theme_id, $conf['AU_ignore']['themes']), 
    69         ); 
    70       } 
    71     } 
    72   } 
    73 } 
    74  
    75 // Languages 
    76 include_once(PHPWG_ROOT_PATH.'admin/include/languages.class.php'); 
    77 $languages = new languages(); 
    78 $update_languages = array(); 
    79 if ($languages->get_server_languages()) 
    80 { 
    81   foreach($languages->fs_languages as $language_id => $fs_language) 
    82   { 
    83     if (isset($fs_language['extension']) 
    84       and isset($languages->server_languages[$fs_language['extension']])) 
    85     { 
    86       $language_info = $languages->server_languages[$fs_language['extension']]; 
    87  
    88       if (!$languages->language_version_compare($fs_language['version'], $language_info['revision_name'])) 
    89       { 
    90         $update_languages[] = array( 
    91           'ID' => $language_info['extension_id'], 
    92           'LANGUAGE_ID' => $language_id, 
    93           'REVISION_ID' => $language_info['revision_id'], 
    94           'EXT_NAME' => $fs_language['name'], 
    95           'EXT_URL' => PEM_URL.'/extension_view.php?eid='.$language_info['extension_id'], 
    96           'EXT_DESC' => trim($language_info['extension_description'], " \n\r"), 
    97           'REV_DESC' => trim($language_info['revision_description'], " \n\r"), 
    98           'CURRENT_VERSION' => $fs_language['version'], 
    99           'NEW_VERSION' => $language_info['revision_name'], 
    100           'AUTHOR' => $language_info['author_name'], 
    101           'DOWNLOADS' => $language_info['extension_nb_downloads'], 
    102           'URL_DOWNLOAD' => $language_info['download_url'] . '&amp;origin=piwigo_download', 
    103           'IGNORED' => in_array($language_id, $conf['AU_ignore']['languages']), 
    104         ); 
    105       } 
    106     } 
    107   } 
    108 } 
    109  
    110 $template->assign('update_plugins', $update_plugins); 
    111 $template->assign('update_themes', $update_themes); 
    112 $template->assign('update_languages', $update_languages); 
    11353$template->assign('SHOW_RESET', (!empty($conf['AU_ignore']['plugins']) or !empty($conf['AU_ignore']['themes']) or !empty($conf['AU_ignore']['languages']))); 
    11454$template->assign('PWG_TOKEN', get_pwg_token()); 
Note: See TracChangeset for help on using the changeset viewer.