Changeset 24160


Ignore:
Timestamp:
08/14/13 23:30:28 (6 years ago)
Author:
mistic100
Message:

feature:2950 add function request_plugin_update()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/functions_plugins.inc.php

    r19703 r24160  
    253253  } 
    254254} 
     255 
     256/* 
     257 * test if a plugin needs to be updated and call a update function 
     258 * @param: string $plugin_id, id of the plugin as seen in PLUGINS_TABLE and $pwg_loaded_plugins 
     259 * @param: string $version, version exposed by the plugin 
     260 * @param: callable $on_update, function to call when and update is needed 
     261 *          it receives the previous version as first parameter 
     262 */ 
     263function request_plugin_update($plugin_id, $version, $on_update) 
     264{ 
     265  global $pwg_loaded_plugins; 
     266   
     267  if ( 
     268    $version == 'auto' or 
     269    $pwg_loaded_plugins[$plugin_id]['version'] == 'auto' or 
     270    version_compare($pwg_loaded_plugins[$plugin_id]['version'], $version, '<') 
     271  ) 
     272  { 
     273    // call update function 
     274    if (!empty($on_update)) 
     275    { 
     276      call_user_func($on_update, $pwg_loaded_plugins[$plugin_id]['version']); 
     277    } 
     278     
     279    // update plugin version in database 
     280    if ($version != 'auto') 
     281    { 
     282      $query = ' 
     283UPDATE '. PLUGINS_TABLE .' 
     284SET version = "'. $version .'" 
     285WHERE id = "'. $plugin_id .'"'; 
     286      pwg_query($query); 
     287       
     288      $pwg_loaded_plugins[$plugin_id]['version'] = $version; 
     289    } 
     290  } 
     291} 
     292 
    255293?> 
Note: See TracChangeset for help on using the changeset viewer.