[11017] | 1 | <?php |
---|
| 2 | /** |
---|
| 3 | * @author Eric@piwigo.org |
---|
| 4 | * |
---|
| 5 | * Upgrade processes for old plugin version |
---|
| 6 | * Called from maintain.inc.php on plugin activation |
---|
| 7 | * |
---|
| 8 | */ |
---|
| 9 | |
---|
| 10 | if(!defined('CM_PATH')) |
---|
| 11 | { |
---|
| 12 | define('CM_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
| 13 | } |
---|
| 14 | |
---|
| 15 | include_once (CM_PATH.'include/functions.inc.php'); |
---|
| 16 | |
---|
| 17 | // +----------------------------------------------------------+ |
---|
| 18 | // | Upgrading database from old plugin versions | |
---|
| 19 | // +----------------------------------------------------------+ |
---|
| 20 | |
---|
| 21 | |
---|
| 22 | /* *************************************** */ |
---|
| 23 | /* Update plugin version in conf table */ |
---|
| 24 | /* Used everytime a new version is updated */ |
---|
| 25 | /* even if no database upgrade is needed */ |
---|
| 26 | /* *************************************** */ |
---|
| 27 | function CM_version_update() |
---|
| 28 | { |
---|
| 29 | global $conf; |
---|
| 30 | |
---|
| 31 | // Get current plugin version |
---|
| 32 | $plugin = CM_Infos(CM_PATH); |
---|
| 33 | $version = $plugin['version']; |
---|
| 34 | |
---|
| 35 | // Upgrading options |
---|
| 36 | $query = ' |
---|
| 37 | SELECT value |
---|
| 38 | FROM '.CONFIG_TABLE.' |
---|
| 39 | WHERE param = "CommentsManager" |
---|
| 40 | ;'; |
---|
| 41 | |
---|
| 42 | $result = pwg_query($query); |
---|
| 43 | $conf_CM = pwg_db_fetch_assoc($result); |
---|
| 44 | |
---|
| 45 | $Newconf_CM = unserialize($conf_CM['value']); |
---|
| 46 | |
---|
| 47 | $Newconf_CM[0] = $version; |
---|
| 48 | |
---|
| 49 | $update_conf = serialize($Newconf_CM); |
---|
| 50 | |
---|
| 51 | conf_update_param('CommentsManager', pwg_db_real_escape_string($update_conf)); |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | // Check #_plugin table consistency |
---|
| 55 | // Only useful if a previous version upgrade has not worked correctly (rare case) |
---|
| 56 | $query = ' |
---|
| 57 | SELECT version |
---|
| 58 | FROM '.PLUGINS_TABLE.' |
---|
| 59 | WHERE id = "CommentsManager" |
---|
| 60 | ;'; |
---|
| 61 | |
---|
| 62 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 63 | |
---|
| 64 | if (empty($data['version']) or $data['version'] <> $version) |
---|
| 65 | { |
---|
| 66 | $query = ' |
---|
| 67 | UPDATE '.PLUGINS_TABLE.' |
---|
| 68 | SET version="'.$version.'" |
---|
| 69 | WHERE id = "CommentsManager" |
---|
| 70 | LIMIT 1 |
---|
| 71 | ;'; |
---|
| 72 | |
---|
| 73 | pwg_query($query); |
---|
| 74 | } |
---|
| 75 | } |
---|
| 76 | ?> |
---|