source: extensions/skeleton/include/install.inc.php @ 18408

Last change on this file since 18408 was 18408, checked in by mistic100, 12 years ago

Plugin URI filled by PEM, add warning about unserialized config in install.inc.php

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    $skeleton_default_config = serialize(array(
24      'option1' => 10,
25      'option2' => true,
26      ));
27 
28    conf_update_param('skeleton', $skeleton_default_config);
29    $conf['skeleton'] = $skeleton_default_config;
30  }
31  else
32  {
33    // if you need to test "old" configuration you must check is not yet unserialized
34    $old_conf = is_string($conf['skeleton']) ? unserialize($conf['skeleton']) : $conf['skeleton'];
35  }
36 
37  // add a new table
38        pwg_query('
39CREATE TABLE IF NOT EXISTS `'. $prefixeTable .'skeleton` (
40  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
41  `field1` mediumint(8) DEFAULT NULL,
42  `field2` varchar(64) NOT NULL,
43  PRIMARY KEY (`id`)
44) ENGINE=MyISAM DEFAULT CHARSET=utf8
45;');
46
47  // add a new column to existing table
48  $result = pwg_query('SHOW COLUMNS FROM `'.IMAGES_TABLE.'` LIKE "skeleton";');
49  if (!pwg_db_num_rows($result))
50  {     
51    pwg_query('ALTER TABLE `' . IMAGES_TABLE . '` ADD `skeleton` TINYINT(1) NOT NULL DEFAULT 0;');
52  }
53
54  // create a local directory
55  if ( file_exists(PWG_LOCAL_DIR) and !file_exists(PWG_LOCAL_DIR . 'skeleton/') ) 
56  {
57    mkdir(PWG_LOCAL_DIR . 'skeleton/', 0755);
58  }
59
60}
61
62?>
Note: See TracBrowser for help on using the repository browser.