source: extensions/ContactForm/include/install.inc.php @ 18649

Last change on this file since 18649 was 18649, checked in by mistic100, 12 years ago

correct upgrade procedure

File size: 3.0 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4function contact_form_install()
5{
6  global $conf, $prefixeTable;
7 
8  // email table
9  $query = '
10CREATE TABLE IF NOT EXISTS `'. $prefixeTable .'contact_form` (
11  `id` smallint(5) NOT NULL AUTO_INCREMENT,
12  `name` varchar(128) NOT NULL,
13  `email` varchar(128) NOT NULL,
14  `active` enum("true","false") NOT NULL DEFAULT "true",
15  `group_name` varchar(128) DEFAULT NULL,
16  PRIMARY KEY (`id`),
17  UNIQUE KEY `UNIQUE` (`email`,`group_name`)
18) ENGINE=MyISAM DEFAULT CHARSET=utf8;';
19  pwg_query($query);
20
21  // configuration
22  if (empty($conf['ContactForm']))
23  {
24    $contact_form_default_config = serialize(array(
25      'cf_must_initialize' => true,
26      'cf_menu_link' => true,
27      'cf_subject_prefix' => '%gallery_title%',
28      'cf_default_subject' => 'A comment on your site',
29      'cf_allow_guest' => true,
30      'cf_mandatory_mail' => true,
31      'cf_mandatory_name' => true,
32      'cf_mail_type' => 'text/html',
33      'cf_redirect_url' => null,
34      ));
35   
36    conf_update_param('ContactForm', $contact_form_default_config);
37    conf_update_param('ContactForm_before', null);
38    conf_update_param('ContactForm_after', null);
39   
40    $conf['ContactForm'] = $contact_form_default_config;
41    $conf['ContactForm_before'] = null;
42    $conf['ContactForm_after'] = null;
43  }
44  else
45  {
46    $new_conf = is_string($conf['ContactForm']) ? unserialize($conf['ContactForm']) : $conf['ContactForm'];
47   
48    // migration 2.4 -> 2.5
49    if (!isset($new_conf['cf_must_initialize']))
50    {
51      // new params
52      $new_conf['cf_must_initialize'] = false;
53      $new_conf['cf_default_subject'] = 'A comment on your site';
54      $new_conf['cf_mail_type'] = 'text/html';
55      $new_conf['cf_redirect_url'] = null;
56     
57      // move emails to database
58      $emails = array();
59      foreach ($new_conf['cf_admin_mails'] as $email => $data)
60      {
61        array_push($emails, array(
62          'email' => $email,
63          'name' => $data['NAME'],
64          'active' => boolean_to_string($data['ACTIVE']),
65          ));
66      }
67     
68      mass_inserts(
69        $prefixeTable .'contact_form',
70        array('name','email','active'),
71        $emails
72        );
73     
74      // old params
75      unset(
76        $new_conf['comment'], $new_conf['cf_redirect_delay'], 
77        $new_conf['cf_separator'], $new_conf['cf_separator_length'], 
78        $new_conf['cf_admin_mails']
79        );
80     
81      // save config
82      $conf['ContactForm'] = serialize($new_conf);
83      $conf['ContactForm_before'] = stripslashes(@$conf['persoformtop']);
84      $conf['ContactForm_after'] = stripslashes(@$conf['persoformbottom']);
85     
86      conf_update_param('ContactForm', $conf['ContactForm']);
87      conf_update_param('ContactForm_before', $conf['ContactForm_before']);
88      conf_update_param('ContactForm_after', $conf['ContactForm_after']);
89     
90      pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param IN("persoformtop", "persoformbottom") LIMIT 2;');
91    }
92  }
93}
94
95?>
Note: See TracBrowser for help on using the repository browser.