Ignore:
Timestamp:
Nov 27, 2018, 4:55:02 PM (5 years ago)
Author:
plg
Message:

cleaner configuration manager on install/update

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/AntiAspi/maintain.class.php

    r31370 r31952  
    44class AntiAspi_maintain extends PluginMaintain
    55{
     6  private $default_conf = array(
     7    'diff' => '20 pages in 00:00:10',
     8    'same' => '15 pages in 00:00:30',
     9    'banned during' => '23:59:59',
     10    'only guest' => true,
     11    'only picture' => false,
     12    'allowed ip' => array('123.123.123.123','122.122.122.122'),
     13    );
     14
    615  function install($plugin_version, &$errors=array())
    716  {
    8     global $prefixeTable;
     17    global $prefixeTable, $conf;
     18
     19    // add config parameter
     20    if (empty($conf['antiaspi']))
     21    {
     22      conf_update_param('antiaspi', $this->default_conf, true);
     23    }
     24    else
     25    {
     26      $old_conf = safe_unserialize($conf['antiaspi']);
     27
     28      foreach (array_keys($this->default_conf) as $conf_key)
     29      {
     30        if (!isset($old_conf[$conf_key]))
     31        {
     32          $old_conf[$conf_key] = $this->default_conf[$conf_key];
     33        }
     34      }
     35
     36      conf_update_param('antiaspi', $old_conf, true);
     37    }
    938
    1039    // table antiaspi_ip_ban to store list of banned IP addresses
     
    4372  function update($old_version, $new_version, &$errors=array())
    4473  {
    45         global $conf; 
    46          
    47         if (!isset($conf['antiaspi']))
    48       {
    49                 $conf['antiaspi'] = array(
    50                   'diff' => '20 pages in 00:00:10' ,
    51                   'same' => '15 pages in 00:00:30' ,
    52                   'banned during' => '23:59:59' ,
    53                   'only guest' => true ,
    54                   'only picture' => false ,
    55                   'allowed ip' => array('123.123.123.123','122.122.122.122'),
    56                 );
    57                 conf_update_param('antiaspi', $conf['antiaspi']);
    58       } 
    59          
    6074    $this->install($new_version, $errors);
    6175  }
     
    6781    pwg_query('DROP TABLE '.$prefixeTable.'antiaspi_ip_ban;');
    6882    pwg_query('DROP TABLE '.$prefixeTable.'antiaspi_log;');
     83
     84    // delete configuration
     85    pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param IN ("antiaspi");');
    6986  }
    7087}
Note: See TracChangeset for help on using the changeset viewer.