forked from techjoomla/com_hierarchy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.hierarchy.php
executable file
·203 lines (174 loc) · 4.34 KB
/
script.hierarchy.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
200
201
202
203
<?php
/**
* @version SVN: <svn_id>
* @package Com_Tjlms
* @copyright Copyright (C) 2005 - 2014. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* Shika is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
*/
// No direct access
defined('_JEXEC') or die;
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.file');
/**
* Hierarchy Installer
*
* @since 1.0.0
*/
class Com_HierarchyInstallerScript
{
/** @var array The list of extra modules and plugins to install */
private $oldversion = "";
/**
* method to run before an install/update/uninstall method
*
* @param JInstaller $type type
* @param JInstaller $parent parent
*
* @return void
*/
public function preflight($type, $parent)
{
}
/**
* method to install the component
*
* @param JInstaller $parent parent
*
* @return void
*/
public function install($parent)
{
}
/**
* method to update the component
*
* @param JInstaller $parent Parent
*
* @return void
*/
public function update($parent)
{
$this->installSqlFiles($parent);
$this->fixDbOnUpdate();
$this->deleteUnexistingFiles();
}
/**
* installSqlFiles
*
* @param JInstaller $parent parent
*
* @return void
*/
public function installSqlFiles($parent)
{
$db = JFactory::getDBO();
// Obviously you may have to change the path and name if your installation SQL file ;)
if (method_exists($parent, 'extension_root'))
{
$sqlfile = $parent->getPath('extension_root') . DS . 'admin' . DS . 'sql' . DS . 'install.mysql.utf8.sql';
}
else
{
$sqlfile = $parent->getParent()->getPath('extension_root') . DS . 'sql' . DS . 'install.mysql.utf8.sql';
}
// Don't modify below this line
$buffer = file_get_contents($sqlfile);
if ($buffer !== false)
{
jimport('joomla.installer.helper');
$queries = JInstallerHelper::splitSql($buffer);
if (count($queries) != 0)
{
foreach ($queries as $query)
{
$query = trim($query);
if ($query != '' && $query{0} != '#')
{
$db->setQuery($query);
if (!$db->query())
{
JError::raiseWarning(1, JText::sprintf('JLIB_INSTALLER_ERROR_SQL_ERROR', $db->stderr(true)));
return false;
}
}
}
}
}
}
/**
* function to make necessary changes on update
*
* @return void
*
* @since 1.0.0
*/
protected function fixDbOnUpdate()
{
$db = JFactory::getDBO();
$query = "SHOW COLUMNS FROM #__hierarchy_users";
$db->setQuery($query);
$res = $db->loadColumn();
if (!in_array('subuser_id', $res))
{
$query = "ALTER TABLE #__hierarchy_users add column subuser_id int(11);";
$db->setQuery($query);
$db->execute();
}
if (!in_array('client', $res))
{
$query = "ALTER TABLE #__hierarchy_users add column client VARCHAR(255);";
$db->setQuery($query);
$db->execute();
}
if (!in_array('client_id', $res))
{
$query = "ALTER TABLE #__hierarchy_users add column client_id INT(11);";
$db->setQuery($query);
$db->execute();
}
if (!in_array('state', $res))
{
$query = "ALTER TABLE #__hierarchy_users add column state INT(11);";
$db->setQuery($query);
$db->execute();
}
if (!in_array('note', $res))
{
$query = "ALTER TABLE #__hierarchy_users add column note TEXT;";
$db->setQuery($query);
$db->execute();
}
$query = "ALTER TABLE #__hierarchy_users modify subuser_id int(11);";
$db->setQuery($query);
$db->execute();
}
/**
* Delete files that should not exist
*
* @return void
*/
public function deleteUnexistingFiles()
{
include JPATH_ADMINISTRATOR . '/components/com_hierarchy/deletelist.php';
jimport('joomla.filesystem.file');
foreach ($files as $file)
{
if (JFile::exists(JPATH_ROOT . $file) && !JFile::delete(JPATH_ROOT . $file))
{
$app->enqueueMessage(JText::sprintf('FILES_JOOMLA_ERROR_FILE_FOLDER', $file));
}
}
jimport('joomla.filesystem.folder');
foreach ($folders as $folder)
{
if (JFolder::exists(JPATH_ROOT . $folder) && !JFolder::delete(JPATH_ROOT . $folder))
{
$app->enqueueMessage(JText::sprintf('FILES_JOOMLA_ERROR_FILE_FOLDER', $folder));
}
}
}
}