1 | <?php |
---|
2 | |
---|
3 | defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); |
---|
4 | |
---|
5 | class MenuRandomPhoto_maintain extends PluginMaintain |
---|
6 | { |
---|
7 | private $installed = false; |
---|
8 | |
---|
9 | private $default_conf = array( |
---|
10 | 'height' => 150, |
---|
11 | 'square' => true, |
---|
12 | 'randompicture_preload' => 25, // number preloaded random pictures |
---|
13 | 'title' => 'A random photo', |
---|
14 | 'delay' => 4000, |
---|
15 | 'apply_to_albums' => 'all', |
---|
16 | ); |
---|
17 | |
---|
18 | function __construct($plugin_id) |
---|
19 | { |
---|
20 | parent::__construct($plugin_id); |
---|
21 | } |
---|
22 | |
---|
23 | function install($plugin_version, &$errors=array()) |
---|
24 | { |
---|
25 | global $conf; |
---|
26 | |
---|
27 | if (empty($conf['MRP'])) |
---|
28 | { |
---|
29 | conf_update_param('MRP', $this->default_conf, true); |
---|
30 | } |
---|
31 | else |
---|
32 | { |
---|
33 | $old_conf = safe_unserialize($conf['MRP']); |
---|
34 | |
---|
35 | $new_param = 'apply_to_albums'; |
---|
36 | if (empty($old_conf[$new_param])) |
---|
37 | { // use case: this parameter was added in a new version |
---|
38 | $old_conf[$new_param] = $this->default_conf[$new_param]; |
---|
39 | } |
---|
40 | |
---|
41 | conf_update_param('MRP', $old_conf, true); |
---|
42 | } |
---|
43 | |
---|
44 | // add a new column to existing CATEGORIES table, if it doesn't already exist |
---|
45 | $result = pwg_query('SHOW COLUMNS FROM `'.CATEGORIES_TABLE.'` LIKE "menurandomphoto_active";'); |
---|
46 | if (!pwg_db_num_rows($result)) |
---|
47 | { |
---|
48 | pwg_query('ALTER TABLE `'.CATEGORIES_TABLE.'` ADD `menurandomphoto_active` enum(\'true\', \'false\') default \'false\';'); |
---|
49 | } |
---|
50 | |
---|
51 | $this->installed = true; |
---|
52 | } |
---|
53 | |
---|
54 | function activate($plugin_version, &$errors=array()) |
---|
55 | { |
---|
56 | if (!$this->installed) |
---|
57 | { |
---|
58 | $this->install($plugin_version, $errors); |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | function deactivate() |
---|
63 | { |
---|
64 | } |
---|
65 | |
---|
66 | /** |
---|
67 | * Plugin (auto)update |
---|
68 | * |
---|
69 | * This function is called when Piwigo detects that the registered version of |
---|
70 | * the plugin is older than the version exposed in main.inc.php |
---|
71 | * Thus it's called after a plugin update from admin panel or a manual update by FTP |
---|
72 | */ |
---|
73 | function update($old_version, $new_version, &$errors=array()) |
---|
74 | { |
---|
75 | $this->install($new_version, $errors); |
---|
76 | } |
---|
77 | |
---|
78 | function uninstall() |
---|
79 | { |
---|
80 | conf_delete_param('MRP'); |
---|
81 | // delete field |
---|
82 | pwg_query('ALTER TABLE `'. CATEGORIES_TABLE .'` DROP COLUMN `menurandomphoto_active`;'); |
---|
83 | } |
---|
84 | } |
---|
85 | |
---|
86 | ?> |
---|