source: extensions/Subscribe_to_comments/maintain.class.php @ 28861

Last change on this file since 28861 was 28851, checked in by mistic100, 10 years ago

use new maintain class

File size: 3.2 KB
Line 
1<?php
2defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
3
4class Subscribe_to_Comments_maintain extends PluginMaintain
5{
6  private $default_conf = array(
7    'notify_admin_on_subscribe' => false,
8    'allow_global_subscriptions' => true,
9    );
10
11  private $table;
12
13  function __construct($plugin_id)
14  {
15    parent::__construct($plugin_id);
16
17    global $prefixeTable;
18    $this->table = $prefixeTable . 'subscribe_to_comments';
19  }
20
21  function install($plugin_version, &$errors=array())
22  {
23    global $conf;
24
25    // config parameter
26    if (empty($conf['Subscribe_to_Comments']))
27    {
28      conf_update_param('Subscribe_to_Comments', $this->default_config, true);
29    }
30
31    // subscriptions table
32    pwg_query('
33CREATE TABLE IF NOT EXISTS `'. $this->table .'` (
34  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
35  `type` enum("image","album-images","album","all-images","all-albums") NOT NULL DEFAULT "image",
36  `element_id` mediumint(8) DEFAULT NULL,
37  `language` varchar(64) NOT NULL,
38  `email` varchar(255) NOT NULL,
39  `registration_date` datetime NOT NULL,
40  `validated` enum("true","false") NOT NULL DEFAULT "false",
41  PRIMARY KEY (`id`),
42  UNIQUE KEY `UNIQUE` (`email` , `type` , `element_id`)
43) DEFAULT CHARSET=utf8
44;');
45
46    // table structure upgrade in 1.1
47    $result = pwg_query('SHOW COLUMNS FROM `'. $this->table .'` LIKE "element_id";');
48    if (!pwg_db_num_rows($result))
49    {
50      // backup subscriptions
51      $query = 'SELECT * FROM `'. $this->table .'` ORDER BY registration_date;';
52      $subscriptions = query2array($query, 'id');
53
54      // upgrade the table
55      pwg_query('TRUNCATE TABLE `'. $this->table .'`;');
56      pwg_query('ALTER TABLE `'. $this->table .'` DROP `image_id`, DROP `category_id`;');
57      pwg_query('ALTER TABLE `'. $this->table .'` AUTO_INCREMENT = 1;');
58
59      $query = '
60ALTER TABLE `'. $this->table .'`
61  ADD `type` enum("image", "album-images", "album", "all-images", "all-albums") NOT NULL DEFAULT "image" AFTER `id`,
62  ADD `element_id` mediumint(8) NULL AFTER `type`,
63  ADD `language` varchar(64) NOT NULL AFTER `element_id`
64;';
65      pwg_query($query);
66
67      pwg_query('ALTER TABLE `'. $this->table .'`  DROP INDEX `UNIQUE`, ADD UNIQUE `UNIQUE` (`email`, `type`, `element_id`);');
68
69      // convert datas and fill the table
70      $inserts = array();
71
72      foreach ($subscriptions as $row)
73      {
74        if (!empty($row['category_id']))
75        {
76          $row['type'] = 'album';
77          $row['element_id'] = $row['category_id'];
78        }
79        else if (!empty($row['image_id']))
80        {
81          $row['type'] = 'image';
82          $row['element_id'] = $row['image_id'];
83        }
84        else
85        {
86          continue;
87        }
88
89        unset($row['id'], $row['image_id'], $row['category_id']);
90        $row['language'] = 'en_UK';
91
92        array_push($inserts, $row);
93      }
94
95      if (count($inserts) > 0)
96      {
97        $dbfields = array('type', 'element_id', 'language', 'email', 'registration_date', 'validated');
98        mass_inserts($this->table, $dbfields, $inserts);
99      }
100    }
101  }
102
103  function update($old_version, $new_version, &$errors=array())
104  {
105    $this->install($new_version, $errors);
106  }
107
108  function uninstall()
109  {
110    conf_delete_param('Subscribe_to_Comments');
111
112    pwg_query('DROP TABLE `'. $this->table .'`;');
113  }
114}
Note: See TracBrowser for help on using the repository browser.