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

Last change on this file since 23395 was 23395, checked in by mistic100, 11 years ago

corrections and example of {html_style}, {html_options}, API info

File size: 1.8 KB
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
69?>
Note: See TracBrowser for help on using the repository browser.