Changeset 31883


Ignore:
Timestamp:
Jul 25, 2017, 11:26:37 AM (7 years ago)
Author:
plg
Message:

implement the auto-update mechanism

Location:
extensions/MenuRandomPhoto
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • extensions/MenuRandomPhoto/main.inc.php

    r31881 r31883  
    2323        global $conf, $user;
    2424
    25     $conf['MRP'] = unserialize($conf['MRP']);
     25    $conf['MRP'] = safe_unserialize($conf['MRP']);
    2626
    2727    if (defined('IN_ADMIN'))
  • extensions/MenuRandomPhoto/maintain.class.php

    r31882 r31883  
    2727                if (empty($conf['MRP']))
    2828                {
    29                         $conf['MRP'] = serialize($this->default_conf);
    30                         conf_update_param('MRP', $conf['MRP']);
     29                        conf_update_param('MRP', $this->default_conf, true);
    3130                }
    3231                else
    3332                {
    34                         $new_conf = is_string($conf['MRP']) ? unserialize($conf['MRP']) : $conf['MRP'];
    35                
    36                         $conf['MRP'] = serialize($new_conf);
    37                         conf_update_param('MRP', $conf['MRP']);
     33                        $old_conf = safe_unserialize($conf['MRP']);
     34
     35                        $new_param = 'apply_to_albums';
     36                        if (empty($old_conf[$new_param]))
     37                        { // use case: this parameter was added in a new version
     38                                $old_conf[$new_param] = $this->default_conf[$new_param];
     39                        }
     40
     41                        conf_update_param('MRP', $old_conf, true);
    3842                }
    3943
     
    5963        {
    6064        }
    61        
     65
     66        /**
     67        * Plugin (auto)update
     68        *
     69        * This function is called when Piwigo detects that the registered version of
     70        * the plugin is older than the version exposed in main.inc.php
     71        * Thus it's called after a plugin update from admin panel or a manual update by FTP
     72        */
     73        function update($old_version, $new_version, &$errors=array())
     74        {
     75                $this->install($new_version, $errors);
     76        }
     77
    6278        function uninstall()
    6379        {
Note: See TracChangeset for help on using the changeset viewer.