Ignore:
Timestamp:
Jun 13, 2013, 2:01:34 PM (11 years ago)
Author:
mistic100
Message:

use serialized array for config + custom upgrade process

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/Back2Front/maintain.inc.php

    r12648 r23177  
    22if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    33
    4 include_once(PHPWG_PLUGINS_PATH.'Back2Front/functions.inc.php');
     4defined('B2F_ID') or define('B2F_ID', basename(dirname(__FILE__)));
     5include_once(PHPWG_PLUGINS_PATH . B2F_ID . '/include/install.inc.php');
     6include_once(PHPWG_PLUGINS_PATH . B2F_ID . '/include/functions.inc.php');
    57
    68function plugin_install()
    79{
    8   global $prefixeTable;
    9 
    10   /* create table for recto/verso pairs | stores original verso categories */
    11   pwg_query("CREATE TABLE IF NOT EXISTS `" . $prefixeTable . "image_verso` (
    12     `image_id` mediumint(8) unsigned NOT NULL DEFAULT '0',
    13     `verso_id` mediumint(8) unsigned NOT NULL DEFAULT '0',
    14     `categories` varchar(128) NULL,
    15     PRIMARY KEY (`image_id`),
    16     UNIQUE KEY (`verso_id`)
    17   ) DEFAULT CHARSET=utf8;");
     10  back2front_install();
    1811 
    19   /* create a virtual category to store versos */
    20   $versos_cat = create_virtual_category('Back2Front private album');
    21   $versos_cat = array(
    22     'id' => $versos_cat['id'],
    23     'comment' => 'Used by Back2Front to store backsides.',
    24     'status'  => 'private',
    25     'visible' => 'false',
    26     'commentable' => 'false',
    27     );
    28   mass_updates(
    29     CATEGORIES_TABLE,
    30     array(
    31       'primary' => array('id'),
    32       'update' => array_diff(array_keys($versos_cat), array('id'))
    33       ),
    34     array($versos_cat)
    35     );
    36    
    37   /* config parameter */
    38   pwg_query("INSERT INTO `" . CONFIG_TABLE . "`
    39     VALUES ('back2front', '".$versos_cat['id'].",click,none,top,".serialize(array('default'=>null)).",1', 'Configuration for Back2Front plugin');");
     12  define('back2front_installed', true);
    4013}
    4114
    4215function plugin_activate()
    4316{
    44   global $conf;
    45 
    46 
    47   $conf['back2front'] = explode(',', $conf['back2front']);
    48  
    49   if (!isset($conf['back2front'][3]))
     17  if (!defined('back2front_installed'))
    5018  {
    51     $conf['back2front'][3] = 'top';
    52     $conf['back2front'][4] = serialize(array('default'=>null));
     19    back2front_install();
    5320  }
    54   if (!isset($conf['back2front'][5]))
    55   {
    56     $conf['back2front'][5] = true;
    57   }
    58  
    59   conf_update_param('back2front', implode (',', $conf['back2front']));
    6021}
    6122
    6223
    63 function plugin_uninstall() {
     24function plugin_uninstall()
     25{
    6426  global $conf, $prefixeTable;
    6527 
    66   $conf['back2front'] = explode(',',$conf['back2front']);
     28  $conf['back2front'] = unserialize($conf['back2front']);
    6729 
    68   /* versos must be restored to their original categories
    69    criterias :
    70     - verso € 'versos' cat only => restore verso to original categories
    71     - otherwise nothing is changed
    72   */
    73 
    7430  $query = "SELECT * FROM `" . $prefixeTable . "image_verso`;";
    7531  $images_versos = pwg_query($query);
     
    8238  pwg_query("DROP TABLE `" . $prefixeTable . "image_verso`;");
    8339  pwg_query("DELETE FROM `" . CONFIG_TABLE . "` WHERE param = 'back2front';");
    84   pwg_query("DELETE FROM `" . CATEGORIES_TABLE ."`WHERE id = ".$conf['back2front'][0].";");
     40  pwg_query("DELETE FROM `" . CATEGORIES_TABLE ."`WHERE id = ".$conf['back2front']['versos_cat'].";");
    8541 
    86   /* rebuild categories cache */
     42  // rebuild categories cache
    8743  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
    8844  invalidate_user_cache(true);
Note: See TracChangeset for help on using the changeset viewer.