source: extensions/PayPalShoppingCart/include/install.inc.php @ 19464

Last change on this file since 19464 was 19464, checked in by plg, 11 years ago

Ability to filter the PayPal form on a list of albums

Implements the "automatic update" mechanism from Skeleton plugin.

File size: 2.4 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 ppppp_install() 
17{
18  global $conf, $prefixeTable;
19
20  $tables = ppppp_get_tables();
21
22  if (!in_array($prefixeTable.'ppppp_size', $tables))
23  {
24    $query = "
25CREATE TABLE IF NOT EXISTS ".$prefixeTable."ppppp_size (
26  id tinyint(4) NOT NULL AUTO_INCREMENT,
27  size varchar(40) NOT NULL,
28  price float NOT NULL,
29  PRIMARY KEY (id),
30  UNIQUE KEY size (size)
31  )
32;";
33    pwg_query($query);
34
35    single_insert(
36      $prefixeTable."ppppp_size",
37      array(
38        'size' => 'Classique',
39        'price' => 40,
40        )
41      );
42  }
43
44  if (!in_array($prefixeTable.'ppppp_config', $tables))
45  {
46    $query = "
47CREATE TABLE IF NOT EXISTS ".$prefixeTable."ppppp_config (
48  param varchar(40) NOT NULL,
49  value text NOT NULL,
50  PRIMARY KEY (param)
51  )
52;";
53    pwg_query($query);
54
55    mass_inserts(
56      $prefixeTable."ppppp_config",
57      array('param', 'value'),
58      array(
59        array('param' => 'fixed_shipping', 'value' => '0'),
60        array('param' => 'currency', 'value' => 'EUR'),
61        )
62      );
63  }
64
65  // add a new column to existing table
66  $result = pwg_query('SHOW COLUMNS FROM `'.CATEGORIES_TABLE.'` LIKE "paypal_active";');
67  if (!pwg_db_num_rows($result))
68  {
69    pwg_query('ALTER TABLE `'.CATEGORIES_TABLE.'` ADD `paypal_active` enum(\'true\', \'false\') default \'false\';');
70  }
71 
72  // add config parameter
73  if (empty($conf['PayPalShoppingCart']))
74  {
75    $default_config = serialize(array(
76      'apply_to_albums' => 'all',
77      ));
78 
79    conf_update_param('PayPalShoppingCart', $default_config);
80    $conf['PayPalShoppingCart'] = $default_config;
81  }
82}
83
84/**
85 * list all tables in an array
86 *
87 * @return array
88 */
89function ppppp_get_tables()
90{
91  global $prefixeTable;
92 
93  $tables = array();
94
95  $query = '
96SHOW TABLES
97;';
98  $result = pwg_query($query);
99
100  while ($row = pwg_db_fetch_row($result))
101  {
102    if (preg_match('/^'.$prefixeTable.'/', $row[0]))
103    {
104      array_push($tables, $row[0]);
105    }
106  }
107
108  return $tables;
109}
110?>
Note: See TracBrowser for help on using the repository browser.