-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestimonials_setup.php
178 lines (148 loc) · 3.62 KB
/
testimonials_setup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
/**
* Testimonials plugin for e107 v2.
*
* @file
* Custom install/uninstall/update routines.
*/
if(!defined('e107_INIT'))
{
exit;
}
/**
* Class testimonials_setup.
*/
class testimonials_setup
{
/**
* This function is called before plugin table has been created
* by the testimonials_sql.php file.
*
* @param array $var
*/
function install_pre($var)
{
$db = e107::getDb('testimonials');
// Check old database tables exist.
if($db->gen("SELECT * FROM #testimonials_conf WHERE 1"))
{
// Retrieve testimonial items from old table.
$db->gen("SELECT * FROM #testimonials WHERE 1");
$old_records = array();
while($row = $db->fetch())
{
$old_records[] = $row;
}
if(!empty($old_records))
{
$_SESSION['OLD_TESTIMONIALS'] = $old_records;
}
$db->gen("DROP TABLE #testimonials");
$db->gen("DROP TABLE #testimonials_conf");
}
}
/**
* This function is called after plugin table has been created
* by the testimonials_sql.php file.
*
* @param array $var
*/
function install_post($var)
{
if(isset($_SESSION['OLD_TESTIMONIALS']))
{
$db = e107::getDb('testimonials');
$old_records = $_SESSION['OLD_TESTIMONIALS'];
$order = 0;
foreach($old_records as $old_record)
{
$insert = array(
'tm_id' => 0,
'tm_name' => '0.' . $old_record['name'],
'tm_url' => $old_record['homepage'],
'tm_message' => $old_record['text'],
'tm_datestamp' => time(),
'tm_blocked' => ($old_record['allowed'] == 'yes' ? 0 : 1),
'tm_ip' => '',
'tm_order' => $order,
);
$db->insert("testimonials", $insert);
$order++;
}
unset($_SESSION['OLD_TESTIMONIALS']);
}
}
function uninstall_options()
{
}
function uninstall_post($var)
{
}
/**
* Trigger an upgrade alert or not.
*
* @param array $var
*
* @return bool
* True to trigger an upgrade alert, and false to not.
*/
function upgrade_required($var)
{
$db = e107::getDb('testimonials');
// Check old database tables exist.
if($db->gen("SELECT * FROM #testimonials_conf WHERE 1"))
{
return true;
}
}
function upgrade_pre($var)
{
$db = e107::getDb('testimonials');
// Check old database tables exist.
if($db->gen("SELECT * FROM #testimonials_conf WHERE 1"))
{
// Retrieve testimonial items from old table.
$db->gen("SELECT * FROM #testimonials WHERE 1");
$old_records = array();
while($row = $db->fetch())
{
$old_records[] = $row;
}
// Drop old tables.
$db->gen("DROP TABLE #testimonials");
$db->gen("DROP TABLE #testimonials_conf");
// Create new table.
$db->gen("CREATE TABLE #testimonials (
tm_id int(11) unsigned NOT NULL auto_increment,
tm_name varchar(50) NOT NULL DEFAULT '',
tm_url varchar(255) NOT NULL DEFAULT '',
tm_message text NOT NULL,
tm_datestamp int(10) unsigned NOT NULL DEFAULT '0',
tm_blocked tinyint(3) unsigned NOT NULL DEFAULT '0',
tm_ip varchar(45) NOT NULL DEFAULT '',
tm_order tinyint(3) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (tm_id)
) ENGINE=MyISAM;");
// Insert testimonial items into new table.
$order = 0;
foreach($old_records as $old_record)
{
$insert = array(
'tm_id' => 0,
'tm_name' => '0.' . $old_record['name'],
'tm_url' => $old_record['homepage'],
'tm_message' => $old_record['text'],
'tm_datestamp' => time(),
'tm_blocked' => ($old_record['allowed'] == 'yes' ? 0 : 1),
'tm_ip' => '',
'tm_order' => $order,
);
$db->insert("testimonials", $insert);
$order++;
}
}
}
function upgrade_post($var)
{
}
}