Changeset 28651
- Timestamp:
- Jun 9, 2014, 7:20:43 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/include/plugins.class.php
r28169 r28651 56 56 } 57 57 } 58 function update($old_version, $new_version, &$errors=array()) {} 58 59 } 59 60 … … 86 87 private static function build_maintain_class($plugin_id) 87 88 { 88 $file_to_include = PHPWG_PLUGINS_PATH . $plugin_id . '/maintain .inc.php';89 $file_to_include = PHPWG_PLUGINS_PATH . $plugin_id . '/maintain'; 89 90 $classname = $plugin_id.'_maintain'; 90 91 91 if (file_exists($file_to_include)) 92 { 93 include_once($file_to_include); 92 if (file_exists($file_to_include.'.class.php')) 93 { 94 include_once($file_to_include.'.class.php'); 95 return new $classname($plugin_id); 96 } 97 98 if (file_exists($file_to_include.'.inc.php')) 99 { 100 include_once($file_to_include.'.inc.php'); 94 101 95 102 if (class_exists($classname)) 96 103 { 97 $plugin_maintain = new $classname($plugin_id); 98 } 99 else 100 { 101 $plugin_maintain = new DummyPlugin_maintain($plugin_id); 102 } 103 } 104 else 105 { 106 $plugin_maintain = new DummyPlugin_maintain($plugin_id); 107 } 108 109 return $plugin_maintain; 104 return new $classname($plugin_id); 105 } 106 } 107 108 return new DummyPlugin_maintain($plugin_id); 110 109 } 111 110 … … 122 121 $crt_db_plugin = $this->db_plugins_by_id[$plugin_id]; 123 122 } 124 123 125 124 $plugin_maintain = self::build_maintain_class($plugin_id); 126 125 … … 188 187 ;'; 189 188 pwg_query($query); 190 189 191 190 $plugin_maintain->deactivate(); 192 191 break; … … 207 206 ;'; 208 207 pwg_query($query); 209 208 210 209 $plugin_maintain->uninstall(); 211 210 break; … … 236 235 /** 237 236 * Get plugins defined in the plugin directory 238 */ 237 */ 239 238 function get_fs_plugins() 240 239 { … … 257 256 'author'=>'', 258 257 ); 259 $plg_data = implode( '', file($path.'/main.inc.php'));258 $plg_data = file_get_contents($path.'/main.inc.php', null, null, 0, 2048); 260 259 261 260 if ( preg_match("|Plugin Name: (.*)|", $plg_data, $val) ) … … 327 326 { 328 327 global $conf; 329 328 330 329 $versions_to_check = array(); 331 330 $url = PEM_URL . '/api/get_version_list.php?category_id='. $conf['pem_plugins_category'] .'&format=php'; … … 424 423 return false; 425 424 } 426 425 427 426 global $conf; 428 427 … … 478 477 return false; 479 478 } 480 479 481 480 /** 482 481 * Sort $server_plugins -
trunk/admin/include/themes.class.php
r26998 r28651 87 87 if (class_exists($classname)) 88 88 { 89 $theme_maintain = new $classname($theme_id); 90 } 91 else 92 { 93 $theme_maintain = new DummyTheme_maintain($theme_id); 94 } 95 } 96 else 97 { 98 $theme_maintain = new DummyTheme_maintain($theme_id); 99 } 100 101 return $theme_maintain; 89 return new $classname($theme_id); 90 } 91 } 92 93 return new DummyTheme_maintain($theme_id); 102 94 } 103 95 -
trunk/include/functions_plugins.inc.php
r28587 r28651 36 36 * Used to declare maintenance methods of a plugin. 37 37 */ 38 class PluginMaintain 38 class PluginMaintain 39 39 { 40 40 /** @var string $plugin_id */ … … 66 66 67 67 /** 68 * Tests if the plugin needs to be updated and call an update function 69 * 70 * @param string $version version exposed by the plugin (potentially new) 71 * @param string $on_update name of a method to call when an update is needed 72 * it receives the previous version as first parameter 73 */ 74 function autoUpdate($version, $on_update=null) 75 { 76 global $pwg_loaded_plugins; 77 78 $current_version = $pwg_loaded_plugins[$this->plugin_id]['version']; 79 80 if ( $version == 'auto' or $current_version == 'auto' 81 or safe_version_compare($current_version, $version, '<') 82 ) 83 { 84 if (!empty($on_update)) 85 { 86 call_user_func(array(&$this, $on_update), $current_version); 87 } 88 89 if ($version != 'auto') 90 { 91 $query = ' 92 UPDATE '. PLUGINS_TABLE .' 93 SET version = "'. $version .'" 94 WHERE id = "'. $this->plugin_id .'" 95 ;'; 96 pwg_query($query); 97 98 $pwg_loaded_plugins[$this->plugin_id]['version'] = $version; 99 } 100 } 101 } 68 * @param string $old_version 69 * @param string $new_version 70 * @param array &$errors - used to return error messages 71 */ 72 function update($old_version, $new_version, &$errors=array()) {} 102 73 } 103 74 … … 105 76 * Used to declare maintenance methods of a theme. 106 77 */ 107 class ThemeMaintain 78 class ThemeMaintain 108 79 { 109 80 /** @var string $theme_id */ … … 127 98 128 99 function delete() {} 129 130 /**131 * Tests if the theme needs to be updated and call an update function132 *133 * @param string $version version exposed by the theme (potentially new)134 * @param string $on_update name of a method to call when an update is needed135 * it receives the previous version as first parameter136 */137 function autoUpdate($version, $on_update=null)138 {139 $query = '140 SELECT version141 FROM '. THEMES_TABLE .'142 WHERE id = "'. $this->theme_id .'"143 ;';144 list($current_version) = pwg_db_fetch_row(pwg_query($query));145 146 if ( $version == 'auto' or $current_version == 'auto'147 or safe_version_compare($current_version, $version, '<')148 )149 {150 if (!empty($on_update))151 {152 call_user_func(array(&$this, $on_update), $current_version);153 }154 155 if ($version != 'auto')156 {157 $query = '158 UPDATE '. THEMES_TABLE .'159 SET version = "'. $version .'"160 WHERE id = "'. $this->theme_id .'"161 ;';162 pwg_query($query);163 }164 }165 }166 100 } 167 101 … … 251 185 * @param mixed $data data to transmit to all handlers 252 186 * @param mixed $args,... optional arguments 253 * @return mixed $data 187 * @return mixed $data 254 188 */ 255 189 function trigger_change($event, $data=null) … … 400 334 WHERE '. implode(' AND ', $clauses); 401 335 } 402 336 403 337 return query2array($query); 404 338 } 405 339 406 340 /** 407 * Loads a plugin, it includes the main.inc.php file and updates _$pwg_loaded_plugins_. 341 * Loads a plugin in memory. 342 * It performs autoupdate, includes the main.inc.php file and updates *$pwg_loaded_plugins*. 408 343 * 409 344 * @param string $plugin … … 412 347 { 413 348 $file_name = PHPWG_PLUGINS_PATH.$plugin['id'].'/main.inc.php'; 414 if ( file_exists($file_name) ) 415 { 349 if (file_exists($file_name)) 350 { 351 autoupdate_plugin($plugin); 416 352 global $pwg_loaded_plugins; 417 353 $pwg_loaded_plugins[ $plugin['id'] ] = $plugin; 418 include_once( $file_name ); 354 include_once($file_name); 355 } 356 } 357 358 /** 359 * Performs update task of a plugin. 360 * Autoupdate is only performed if the plugin has a maintain.class.php file. 361 * 362 * @since 2.7 363 * 364 * @param array &$plugin (id, version, state) will be updated if version changes 365 */ 366 function autoupdate_plugin(&$plugin) 367 { 368 $maintain_file = PHPWG_PLUGINS_PATH.$plugin['id'].'/maintain.class.php'; 369 370 // autoupdate is applicable only to plugins with 2.7 architecture 371 if (file_exists($maintain_file)) 372 { 373 // try to find the filesystem version in lines 2 to 10 of main.inc.php 374 $fh = fopen(PHPWG_PLUGINS_PATH.$plugin['id'].'/main.inc.php', 'r'); 375 $fs_version = null; 376 $i = -1; 377 378 while (($line = fgets($fh))!==false && $fs_version==null && $i<10) 379 { 380 $i++; 381 if ($i < 2) continue; // first lines are typically "<?php" and "/*" 382 383 if (preg_match('#Version: ([\\w.-]+)#', $line, $matches)) 384 { 385 $fs_version = $matches[1]; 386 } 387 } 388 389 fclose($fh); 390 391 if ($fs_version != null) 392 { 393 global $pwg_loaded_plugins, $page; 394 395 // if version is auto (dev) or superior 396 if ( 397 $fs_version == 'auto' or $plugin['version'] == 'auto' 398 or safe_version_compare($plugin['version'], $fs_version, '<') 399 ) 400 { 401 // call update method 402 include_once($maintain_file); 403 404 $classname = $plugin['id'].'_maintain'; 405 $plugin_maintain = new $classname($plugin['id']); 406 $plugin_maintain->update($plugin['version'], $fs_version, $page['errors']); 407 408 $plugin['version'] = $fs_version; 409 410 // update database (only on production) 411 if ($plugin['version'] != 'auto') 412 { 413 $query = ' 414 UPDATE '. PLUGINS_TABLE .' 415 SET version = "'. $plugin['version'] .'" 416 WHERE id = "'. $plugin['id'] .'" 417 ;'; 418 pwg_query($query); 419 } 420 } 421 } 419 422 } 420 423 }
Note: See TracChangeset
for help on using the changeset viewer.