source: extensions/skeleton/trunk/include/install.inc.php @ 24349

Revision 24349, 2.4 KB checked in by mistic100, 6 years ago (diff)

unset config param in plugin_uninstall

Line 
1<?php
2defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
3
4/**
5 * The installation function is called by main.inc.php and maintain.inc.php
6 * in order to install and/or update the plugin.
7 *
8 * That's why all operations must be conditionned :
9 *    - use "if empty" for configuration vars
10 *    - use "IF NOT EXISTS" for table creation
11 *
12 * Unlike the functions in maintain.inc.php, the name of this function must be unique
13 * and not enter in conflict with other plugins.
14 */
15
16function skeleton_install() 
17{
18  global $conf, $prefixeTable;
19 
20  // add config parameter
21  if (empty($conf['skeleton']))
22  {
23    $conf['skeleton'] = serialize(array(
24      'option1' => 10,
25      'option2' => true,
26      ));
27 
28    conf_update_param('skeleton', $conf['skeleton']);
29  }
30  else
31  {
32    // if you need to test the "old" configuration you must check if not yet unserialized
33    $old_conf = is_string($conf['skeleton']) ? unserialize($conf['skeleton']) : $conf['skeleton'];
34   
35    if (empty($old_conf['option3']))
36    {
37      $old_conf['option3'] = 'two';
38    }
39   
40    $conf['skeleton'] = serialize($old_conf);
41    conf_update_param('skeleton', $conf['skeleton']);
42  }
43 
44  // add a new table
45        pwg_query('
46CREATE TABLE IF NOT EXISTS `'. $prefixeTable .'skeleton` (
47  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
48  `field1` mediumint(8) DEFAULT NULL,
49  `field2` varchar(64) NOT NULL,
50  PRIMARY KEY (`id`)
51) ENGINE=MyISAM DEFAULT CHARSET=utf8
52;');
53
54  // add a new column to existing table
55  $result = pwg_query('SHOW COLUMNS FROM `'.IMAGES_TABLE.'` LIKE "skeleton";');
56  if (!pwg_db_num_rows($result))
57  {     
58    pwg_query('ALTER TABLE `' . IMAGES_TABLE . '` ADD `skeleton` TINYINT(1) NOT NULL DEFAULT 0;');
59  }
60
61  // create a local directory
62  if (!file_exists(PHPWG_ROOT_PATH . PWG_LOCAL_DIR . 'skeleton/')) 
63  {
64    mkdir(PHPWG_ROOT_PATH . PWG_LOCAL_DIR . 'skeleton/', 0755);
65  }
66
67}
68
69function skeleton_uninstall()
70{
71  global $prefixeTable, $conf;
72 
73  // delete configuration
74  pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param = "skeleton";');
75  unset($conf['skeleton']);
76 
77  // delete table
78  pwg_query('DROP TABLE `'. $prefixeTable .'skeleton`;');
79 
80  // delete field
81  pwg_query('ALTER TABLE `'. IMAGES_TABLE .'` DROP `skeleton`;');
82 
83  // delete local folder
84  $dir = PHPWG_ROOT_PATH . PWG_LOCAL_DIR . 'skeleton/';
85  foreach (scandir($dir) as $file)
86  {
87    if ($file == '.' or $file == '..') continue;
88    unlink($dir.$file);
89  }
90  rmdir($dir);
91}
Note: See TracBrowser for help on using the repository browser.