1 | <?php |
---|
2 | defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); |
---|
3 | |
---|
4 | class PayPalShoppingCart_maintain extends PluginMaintain |
---|
5 | { |
---|
6 | private $installed = false; |
---|
7 | |
---|
8 | function __construct($plugin_id) |
---|
9 | { |
---|
10 | parent::__construct($plugin_id); |
---|
11 | } |
---|
12 | |
---|
13 | function install($plugin_version, &$errors=array()) |
---|
14 | { |
---|
15 | global $conf, $prefixeTable, $template; |
---|
16 | |
---|
17 | $query = " |
---|
18 | CREATE TABLE IF NOT EXISTS ".$prefixeTable."ppppp_size ( |
---|
19 | id tinyint(4) NOT NULL AUTO_INCREMENT, |
---|
20 | size varchar(40) NOT NULL, |
---|
21 | price float NOT NULL, |
---|
22 | PRIMARY KEY (id), |
---|
23 | UNIQUE KEY size (size) |
---|
24 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
---|
25 | ;"; |
---|
26 | pwg_query($query); |
---|
27 | |
---|
28 | $query = ' |
---|
29 | SELECT COUNT(*) |
---|
30 | FROM '.$prefixeTable.'ppppp_size |
---|
31 | ;'; |
---|
32 | list($counter) = pwg_db_fetch_row(pwg_query($query)); |
---|
33 | |
---|
34 | if (0 == $counter) |
---|
35 | { |
---|
36 | single_insert( |
---|
37 | $prefixeTable."ppppp_size", |
---|
38 | array( |
---|
39 | 'size' => 'Classic', |
---|
40 | 'price' => 40, |
---|
41 | ) |
---|
42 | ); |
---|
43 | } |
---|
44 | |
---|
45 | // add a new column to existing table |
---|
46 | $result = pwg_query('SHOW COLUMNS FROM `'.CATEGORIES_TABLE.'` LIKE "paypal_active";'); |
---|
47 | if (!pwg_db_num_rows($result)) |
---|
48 | { |
---|
49 | pwg_query('ALTER TABLE `'.CATEGORIES_TABLE.'` ADD `paypal_active` enum(\'true\', \'false\') default \'false\';'); |
---|
50 | } |
---|
51 | |
---|
52 | $ppppp_config = array( |
---|
53 | 'fixed_shipping' => 0, |
---|
54 | 'currency' => 'EUR', |
---|
55 | 'apply_to_albums' => 'all', |
---|
56 | ); |
---|
57 | |
---|
58 | // move the content of table ppppp_config into $conf['PayPalShoppingCart'], serialized |
---|
59 | $result = pwg_query('SHOW TABLES LIKE "'.$prefixeTable.'ppppp_config";'); |
---|
60 | if (pwg_db_num_rows($result)) |
---|
61 | { |
---|
62 | $query = ' |
---|
63 | SELECT |
---|
64 | * |
---|
65 | FROM '.$prefixeTable.'ppppp_config |
---|
66 | ;'; |
---|
67 | $result = pwg_query($query); |
---|
68 | while ($row = pwg_db_fetch_assoc($result)) |
---|
69 | { |
---|
70 | if (isset($ppppp_config[ $row['param'] ])) |
---|
71 | { |
---|
72 | $ppppp_config[ $row['param'] ] = $row['value']; |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | pwg_query('DROP TABLE '.$prefixeTable.'ppppp_config;'); |
---|
77 | } |
---|
78 | |
---|
79 | // load existing config parameters |
---|
80 | if (!empty($conf['PayPalShoppingCart'])) |
---|
81 | { |
---|
82 | $conf['PayPalShoppingCart'] = safe_unserialize($conf['PayPalShoppingCart']); |
---|
83 | |
---|
84 | foreach ($conf['PayPalShoppingCart'] as $key => $value) |
---|
85 | { |
---|
86 | $ppppp_config[$key] = $value; |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | conf_update_param('PayPalShoppingCart', $ppppp_config, true); |
---|
91 | |
---|
92 | $this->installed = true; |
---|
93 | } |
---|
94 | |
---|
95 | function activate($plugin_version, &$errors=array()) |
---|
96 | { |
---|
97 | global $prefixeTable; |
---|
98 | |
---|
99 | if (!$this->installed) |
---|
100 | { |
---|
101 | $this->install($plugin_version, $errors); |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | function update($old_version, $new_version, &$errors=array()) |
---|
106 | { |
---|
107 | $this->install($new_version, $errors); |
---|
108 | } |
---|
109 | |
---|
110 | function deactivate() |
---|
111 | { |
---|
112 | } |
---|
113 | |
---|
114 | function uninstall() |
---|
115 | { |
---|
116 | global $prefixeTable; |
---|
117 | |
---|
118 | $query = "DROP TABLE ".$prefixeTable."ppppp_size;"; |
---|
119 | pwg_query($query); |
---|
120 | |
---|
121 | $result = pwg_query('SHOW TABLES LIKE "'.$prefixeTable.'ppppp_config";'); |
---|
122 | if (pwg_db_num_rows($result)) |
---|
123 | { |
---|
124 | $query = "DROP TABLE ".$prefixeTable."ppppp_config;"; |
---|
125 | pwg_query($query); |
---|
126 | } |
---|
127 | |
---|
128 | // delete configuration |
---|
129 | pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param = "PayPalShoppingCart";'); |
---|
130 | |
---|
131 | // delete field |
---|
132 | pwg_query('ALTER TABLE `'. CATEGORIES_TABLE .'` DROP COLUMN paypal_active;'); |
---|
133 | } |
---|
134 | } |
---|
135 | ?> |
---|