Ignore:
Timestamp:
Jun 30, 2009, 11:38:31 PM (15 years ago)
Author:
Criss
Message:

Fix bug on plugin update

Location:
extensions/CommentEditor/classes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • extensions/CommentEditor/classes/ce_config.class.php

    r3475 r3480  
    99  var $config_values;
    1010  var $default_config;
    11   var $db_key;
    12   var $db_comment;
     11  var $db_key = null;
     12  var $db_comment = null;
    1313
    1414  /* ************************ */
     
    1818  function CE_Config($default_config = array()) {
    1919    $this->default_config = $default_config;
    20     $this->db_key = CE_CFG_DB_KEY;
    21     $this->db_comment = CE_CFG_DB_COMMENT;
    2220  }
    2321
     
    3331  }
    3432
     33  function setValue($key, $value) {
     34      $this->config_values[$key] = $value;
     35  }
     36
     37  function getVersion() {
     38    if (isset($this->config_values[CE_CFG_VERSION])) {
     39      return $this->config_values[CE_CFG_VERSION];
     40    }
     41    return CE_VERSION;
     42  }
     43
    3544  function setDBKey($key) {
    3645    $this->db_key = $key;
    37   }
    38 
    39   function setDBComment($comment) {
    40     $this->db_comment = $comment;
    41   }
    42 
    43   function setValue($key, $value) {
    44       $this->config_values[$key] = $value;
    4546  }
    4647
     
    5051
    5152  function loadConfig() {
    52     $query = '
    53         SELECT value
    54         FROM '.CONFIG_TABLE.'
    55         WHERE param = \''.CE_CFG_DB_KEY.'\'
    56         ;';
    57     $result = pwg_query($query);
    58     if($result) {
    59       $row = mysql_fetch_row($result);
    60       if(is_string($row[0])) {
    61         $this->config_values = unserialize($row[0]);
     53    if (null != $this->db_key) {
     54      $query = '
     55          SELECT value
     56          FROM '.CONFIG_TABLE.'
     57          WHERE param = \''. $this->db_key .'\'
     58          ;';
     59      $result = pwg_query($query);
     60      if($result) {
     61        $row = mysql_fetch_row($result);
     62        if(is_string($row[0])) {
     63          $this->config_values = unserialize($row[0]);
     64        }
    6265      }
    6366    }
     
    7881
    7982  function saveConfig() {
     83    if (null == $this->db_key) {
     84      return false;
     85    }
     86    $db_comment = sprintf($this->config_values[CE_CFG_COMMENT],
     87                          $this->db_key,
     88                          $this->getVersion());
    8089    $query = '
    8190        REPLACE INTO '.CONFIG_TABLE.'
     
    8392          \''. $this->db_key .'\',
    8493          \''.serialize($this->config_values).'\',
    85           \''. $this->db_comment . '\')
     94          \''. $db_comment . '\')
    8695        ;';
    8796    $result = pwg_query($query);
     
    99108  static function install($plugin_id, $default_config = array()) {
    100109    $config = new CE_Config($default_config);
    101     $config->setDBComment('Factory settings for '. $plugin_id);
    102110    $config->setDBKey($plugin_id);
    103111    $config->loadConfig();
     112    if (isset($default_config[CE_CFG_VERSION])) {
     113      // Override version
     114      $config->config_values[CE_CFG_VERSION] = $default_config[CE_CFG_VERSION];
     115    }
     116    if (isset($default_config[CE_CFG_COMMENT])) {
     117      // Override comment
     118      $config->config_values[CE_CFG_COMMENT] = $default_config[CE_CFG_COMMENT];
     119    }
    104120    $result = $config->saveConfig();
    105121    return $result;
  • extensions/CommentEditor/classes/ce_plugin.class.php

    r3475 r3480  
    11<?php
    2 /* $Id: ce_plugin.class.php,v 1.13 2009/06/30 19:01:50 Criss Exp $ */
     2/* $Id: ce_plugin.class.php,v 1.14 2009/06/30 21:36:20 Criss Exp $ */
    33if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    44
     
    2020    $this->config = $config;
    2121    if (null != $this->config) {
     22      $this->config->setDBKey(CE_CFG_DB_KEY);
    2223      $this->config->loadConfig();
     24      $this->config->setValue(CE_CFG_COMMENT, CE_CFG_DB_COMMENT);
    2325    }
    2426  }
     
    118120
    119121  function getVersion() {
    120     if (isset($this->config->config_values[CE_CFG_VERSION])) {
    121       return $this->config->config_values[CE_CFG_VERSION];
    122     }
    123     return CE_VERSION;
     122    return $this->config->getVersion();
    124123  }
    125124
Note: See TracChangeset for help on using the changeset viewer.