[18858] | 1 | <?php |
---|
| 2 | defined('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 | |
---|
| 16 | function skeleton_install() |
---|
| 17 | { |
---|
| 18 | global $conf, $prefixeTable; |
---|
| 19 | |
---|
| 20 | // add config parameter |
---|
| 21 | if (empty($conf['skeleton'])) |
---|
| 22 | { |
---|
[23395] | 23 | $conf['skeleton'] = serialize(array( |
---|
[18858] | 24 | 'option1' => 10, |
---|
| 25 | 'option2' => true, |
---|
| 26 | )); |
---|
| 27 | |
---|
[23395] | 28 | conf_update_param('skeleton', $conf['skeleton']); |
---|
[18858] | 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']; |
---|
[23395] | 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']); |
---|
[18858] | 42 | } |
---|
| 43 | |
---|
| 44 | // add a new table |
---|
| 45 | pwg_query(' |
---|
| 46 | CREATE 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 |
---|
[19842] | 62 | if (!file_exists(PHPWG_ROOT_PATH . PWG_LOCAL_DIR . 'skeleton/')) |
---|
[18858] | 63 | { |
---|
[19842] | 64 | mkdir(PHPWG_ROOT_PATH . PWG_LOCAL_DIR . 'skeleton/', 0755); |
---|
[18858] | 65 | } |
---|
| 66 | |
---|
| 67 | } |
---|