Changeset 25406 for trunk/include
- Timestamp:
- Nov 9, 2013, 12:29:38 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/functions_plugins.inc.php
r25018 r25406 32 32 33 33 define('PHPWG_PLUGINS_PATH', PHPWG_ROOT_PATH.'plugins/'); 34 35 34 define('EVENT_HANDLER_PRIORITY_NEUTRAL', 50); 35 36 37 /** 38 * class PluginMaintain 39 * used to declare maintenance methods of a plugin 40 */ 41 abstract class PluginMaintain 42 { 43 protected $plugin_id; 44 45 function __construct($id) 46 { 47 $this->plugin_id = $id; 48 } 49 50 abstract function install($plugin_version, &$errors=array()); 51 abstract function activate($plugin_version, &$errors=array()); 52 abstract function deactivate(); 53 abstract function uninstall(); 54 55 /* 56 * test if a plugin needs to be updated and call a update function 57 * @param: string $version, version exposed by the plugin 58 * @param: string $on_update, name of a method to call when an update is needed 59 * it receives the previous version as first parameter 60 */ 61 function autoUpdate($version, $on_update=null) 62 { 63 global $pwg_loaded_plugins; 64 65 $current_version = $pwg_loaded_plugins[$this->plugin_id]['version']; 66 67 if ( $version == 'auto' or $current_version == 'auto' 68 or version_compare($current_version, $version, '<') 69 ) 70 { 71 if (!empty($on_update)) 72 { 73 call_user_func(array(&$this, $on_update), $current_version); 74 } 75 76 if ($version != 'auto') 77 { 78 $query = ' 79 UPDATE '. PLUGINS_TABLE .' 80 SET version = "'. $version .'" 81 WHERE id = "'. $this->plugin_id .'" 82 ;'; 83 pwg_query($query); 84 85 $pwg_loaded_plugins[$this->plugin_id]['version'] = $version; 86 } 87 } 88 } 89 } 90 91 /** 92 * class ThemeMaintain 93 * used to declare maintenance methods of a theme 94 */ 95 abstract class ThemeMaintain 96 { 97 protected $theme_id; 98 99 function __construct($id) 100 { 101 $this->theme_id = $id; 102 } 103 104 abstract function activate($theme_version, &$errors=array()); 105 abstract function deactivate(); 106 abstract function delete(); 107 108 /* 109 * test if a theme needs to be updated and call a update function 110 * @param: string $version, version exposed by the theme 111 * @param: string $on_update, name of a method to call when an update is needed 112 * it receives the previous version as first parameter 113 */ 114 function autoUpdate($version, $on_update=null) 115 { 116 $query = ' 117 SELECT version 118 FROM '. THEMES_TABLE .' 119 WHERE id = "'. $this->theme_id .'" 120 ;'; 121 list($current_version) = pwg_db_fetch_row(pwg_query($query)); 122 123 if ( $version == 'auto' or $current_version == 'auto' 124 or version_compare($current_version, $version, '<') 125 ) 126 { 127 if (!empty($on_update)) 128 { 129 call_user_func(array(&$this, $on_update), $current_version); 130 } 131 132 if ($version != 'auto') 133 { 134 $query = ' 135 UPDATE '. THEMES_TABLE .' 136 SET version = "'. $version .'" 137 WHERE id = "'. $this->theme_id .'" 138 ;'; 139 pwg_query($query); 140 } 141 } 142 } 143 } 144 36 145 37 146 /* Register a event handler. … … 254 363 } 255 364 256 /*257 * test if a plugin needs to be updated and call a update function258 * @param: string $plugin_id, id of the plugin as seen in PLUGINS_TABLE and $pwg_loaded_plugins259 * @param: string $version, version exposed by the plugin260 * @param: callable $on_update, function to call when and update is needed261 * it receives the previous version as first parameter262 */263 function request_plugin_update($plugin_id, $version, $on_update)264 {265 global $pwg_loaded_plugins;266 267 if (268 $version == 'auto' or269 $pwg_loaded_plugins[$plugin_id]['version'] == 'auto' or270 version_compare($pwg_loaded_plugins[$plugin_id]['version'], $version, '<')271 )272 {273 // call update function274 if (!empty($on_update))275 {276 call_user_func($on_update, $pwg_loaded_plugins[$plugin_id]['version']);277 }278 279 // update plugin version in database280 if ($version != 'auto')281 {282 $query = '283 UPDATE '. PLUGINS_TABLE .'284 SET version = "'. $version .'"285 WHERE id = "'. $plugin_id .'"';286 pwg_query($query);287 288 $pwg_loaded_plugins[$plugin_id]['version'] = $version;289 }290 }291 }292 293 365 ?>
Note: See TracChangeset
for help on using the changeset viewer.