-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.install.php
More file actions
155 lines (135 loc) · 3.86 KB
/
script.install.php
File metadata and controls
155 lines (135 loc) · 3.86 KB
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
<?php
/**
* @package QuizKit
* @version 1.1.1
* @author Michelle Ermen
* @copyright Copyright © 2023 MSE Digital All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Error\Error;
/**
* Installer script
*
* Creates a new table on install
*
* Updates table on install
*
*/
class pkg_QuizKitInstallerScript
{
/**
* Method to install the extension
*
* @return void
*/
function install($parent)
{
$db = Factory::getDBO();
$query = "CREATE TABLE IF NOT EXISTS #__quizkit_submissions (
id int(11) NOT NULL AUTO_INCREMENT,
email varchar(50) NOT NULL,
params TEXT NOT NULL,
visitor_id int(11) NOT NULL DEFAULT 0,
score float NOT NULL,
submission_time datetime NOT NULL,
PRIMARY KEY (id)
)";
$db->setQuery($query);
try {
$db->execute();
echo '<p>The module has been installed.</p>';
} catch (Exception $e) {
Error::raiseWarning(500, $e->getMessage());
return false;
}
echo '<p>The module has been installed.</p>';
}
/**
* Method to uninstall the extension
* $parent is the class calling this method
*
* @return void
*/
function uninstall($parent)
{
$db = Factory::getDBO();
try {
$db->execute();
echo '<p>The module has been uninstalled and the table has been removed.</p>';
} catch (Exception $e) {
Error::raiseWarning(500, $e->getMessage());
return false;
}
}
/**
* Method to update the extension
* $parent is the class calling this method
*
* @return void
*/
function update($parent)
{
$db = Factory::getDBO();
// Check if 'params' column is not already TEXT and modify it if necessary
$query = $db->getQuery(true)
->select('COLUMN_TYPE')
->from('INFORMATION_SCHEMA.COLUMNS')
->where('TABLE_SCHEMA = DATABASE()')
->where('TABLE_NAME = ' . $db->quote($db->getPrefix() . 'quizkit_submissions'))
->where('COLUMN_NAME = ' . $db->quote('params'));
$db->setQuery($query);
$columnType = $db->loadResult();
if ($columnType !== 'text') {
$query = 'ALTER TABLE ' . $db->quoteName('#__quizkit_submissions') . ' MODIFY COLUMN ' . $db->quoteName('params') . ' TEXT';
$db->setQuery($query);
$db->execute();
}
// set default to 0 on column visitor_id
$query = 'ALTER TABLE ' . $db->quoteName('#__quizkit_submissions') . ' MODIFY COLUMN ' . $db->quoteName('visitor_id') . ' int(11) NOT NULL DEFAULT 0';
$db->setQuery($query);
$db->execute();
$query = "CREATE TABLE IF NOT EXISTS #__quizkit_submissions (
id int(11) NOT NULL AUTO_INCREMENT,
email varchar(50) NOT NULL,
params TEXT NOT NULL,
visitor_id int(11) NOT NULL DEFAULT 0,
score float NOT NULL,
submission_time datetime NOT NULL,
PRIMARY KEY (id)
)";
$db->setQuery($query);
$db->setQuery($query);
try {
$db->execute();
// Load the manifest file to get the version
$manifest = $parent->getParent()->manifest;
$version = (string) $manifest->version;
echo '<p>The module has been updated to version ' . $version . '.</p>';
} catch (Exception $e) {
Error::raiseWarning(500, $e->getMessage());
return false;
}
}
/**
* Method to run before an install/update/uninstall method
* $parent is the class calling this method
* $type is the type of change (install, update or discover_install)
*
* @return void
*/
function preflight($type, $parent)
{
}
/**
* Method to run after an install/update/uninstall method
* $parent is the class calling this method
* $type is the type of change (install, update or discover_install)
*
* @return void
*/
function postflight($type, $parent)
{
}
}