-
Notifications
You must be signed in to change notification settings - Fork 6
/
script.php
199 lines (175 loc) · 7.7 KB
/
script.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php
/**
* $Id:$.
*
* @copyright (C) 2007 - 2020 Manuel Kaspar and Theophilix
* @license GNU/GPL, see LICENSE.php in the installation package
* This file is part of Event Table Edit
*
* Event Table Edit is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Event Table Edit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with Event Table Edit. If not, see <http://www.gnu.org/licenses/>.
*/
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
class com_eventtableeditInstallerScript
{
public function install($parent)
{
echo '<p>'.JText::_('COM_EVENTTABLEEDIT_POSTFLIGHT_INSTALL_TEXT').'</p>';
$parent->getParent()->setRedirectURL('index.php?option=com_eventtableedit');
}
public function uninstall($parent)
{
// Uninstall the _rows tables
$db = JFactory::getDBO();
$query = 'SELECT id FROM #__eventtableedit_details';
$db->setQuery($query);
$rows = $db->loadColumn();
for ($a = 0; $a < count($rows); ++$a) {
$query = 'DROP TABLE IF EXISTS #__eventtableedit_rows_'.$rows[$a];
$db->setQuery($query);
$db->query();
}
$extensions = [
['type' => 'plugin', 'name' => 'loadete'],
];
foreach ($extensions as $key => $extension) {
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName(['extension_id']));
$query->from($db->quoteName('#__extensions'));
$query->where($db->quoteName('type').' = '.$db->quote($extension['type']));
$query->where($db->quoteName('element').' = '.$db->quote($extension['name']));
$db->setQuery($query);
$id = $db->loadResult();
if (isset($id) && $id) {
$installer = new JInstaller();
$result = $installer->uninstall($extension['type'], $id);
}
}
echo '<p>'.JText::_('COM_EVENTTABLEEDIT_UNINSTALL_TEXT').'</p>';
}
public function update($parent)
{
$db = JFactory::getDBO();
$query = 'SELECT id FROM #__eventtableedit_details';
$db->setQuery($query);
$rows = $db->loadColumn();
if (!empty($rows)) {
for ($a = 0; $a < count($rows); ++$a) {
$query = 'SELECT * FROM #__eventtableedit_rows_'.$rows[$a];
$db->setQuery($query);
$data = $db->loadObject();
if (!isset($data->timestamp)) {
$query = 'ALTER TABLE `#__eventtableedit_rows_'.$rows[$a].'` ADD `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `created_by`, COMMENT=""';
$db->setQuery($query);
$db->query();
}
}
}
$query = "SHOW COLUMNS FROM `#__eventtableedit_details` LIKE 'rowdelete'";
$db->setQuery($query);
$data = $db->loadObject();
if (empty($data)) {
$query = 'ALTER TABLE `#__eventtableedit_details` ADD `rowdelete` tinyint(4) NOT NULL AFTER `rowsort`, COMMENT=""';
$db->setQuery($query);
$db->query();
}
$app = JFactory::getApplication();
$prefix = $app->getCfg('dbprefix');
$query = "SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '".$prefix."eventtableedit_details' AND COLUMN_NAME = 'scroll_table' ";
$db->setQuery($query);
$data = $db->loadObject();
if (empty($data)) {
$query = 'ALTER TABLE `#__eventtableedit_details`
ADD `scroll_table` varchar(255) COLLATE "utf8_general_ci" NOT NULL,
COMMENT=""';
$db->setQuery($query);
$db->query();
}
$query = "SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '".$prefix."eventtableedit_details' AND COLUMN_NAME = 'scroll_table_height'";
$db->setQuery($query);
$data = $db->loadObject();
if (empty($data)) {
$query = 'ALTER TABLE `#__eventtableedit_details`
ADD `scroll_table_height` varchar(255) COLLATE "utf8_general_ci" NOT NULL AFTER `scroll_table`,
COMMENT=""';
$db->setQuery($query);
$db->query();
}
$query = "SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '".$prefix."eventtableedit_details' AND COLUMN_NAME = 'add_option_list'";
$db->setQuery($query);
$data = $db->loadObject();
if (empty($data)) {
$query = 'ALTER TABLE `#__eventtableedit_details`
ADD `add_option_list` tinyint(1) NOT NULL,
COMMENT=""';
$db->setQuery($query);
$db->query();
}
$query = "SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '".$prefix."eventtableedit_details' AND COLUMN_NAME = 'corresptable'";
$db->setQuery($query);
$data = $db->loadObject();
if (empty($data)) {
$query = 'ALTER TABLE `#__eventtableedit_details`
ADD `corresptable` text COLLATE "utf8_general_ci" NOT NULL AFTER `add_option_list`,
COMMENT=""';
$db->setQuery($query);
$db->query();
}
$query = "SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '".$prefix."eventtableedit_details' AND COLUMN_NAME = 'standardlayout'";
$db->setQuery($query);
$data = $db->loadObject();
if (empty($data)) {
$query = 'ALTER TABLE `#__eventtableedit_details` ADD `standardlayout` varchar(255) NOT NULL;';
$db->setQuery($query);
$db->query();
}
echo '<p>'.JText::_('COM_EVENTTABLEEDIT_UPDATE_TEXT').'</p>';
}
/**
* method to run before an install/update/uninstall method.
*/
public function preflight($type, $parent)
{
// $type is the type of change (install, update or discover_install)
echo '<p>'.JText::_('COM_EVENTTABLEEDIT_PREFLIGHT_'.$type.'_TEXT').'</p>';
}
/**
* method to run after an install/update/uninstall method.
*/
public function postflight($type, $parent)
{
$extensions = [
['type' => 'plugin', 'name' => 'loadete', 'group' => 'content'],
];
foreach ($extensions as $key => $extension) {
$ext = $parent->getParent()->getPath('source').'/'.$extension['type'].'s/'.$extension['group'].'/'.$extension['name'];
$installer = new JInstaller();
$installer->install($ext);
if ('plugin' === $extension['type']) {
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$fields = [$db->quoteName('enabled').' = 1'];
$conditions = [
$db->quoteName('type').' = '.$db->quote($extension['type']),
$db->quoteName('element').' = '.$db->quote($extension['name']),
$db->quoteName('folder').' = '.$db->quote($extension['group']),
];
$query->update($db->quoteName('#__extensions'))->set($fields)->where($conditions);
$db->setQuery($query);
$db->execute();
}
}
// $type is the type of change (install, update or discover_install)
echo '<p>'.JText::_('COM_EVENTTABLEEDIT_POSTFLIGHT_'.$type.'_TEXT').'</p>';
}
}