Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 573 lines (491 sloc) 17.277 kB
f73b659 Imported the new trunk.
Rob Schley authored
1 <?php
2 /**
89e3d3a @LouisLandry Fixed up file headers.
LouisLandry authored
3 * @package Joomla.Platform
4 * @subpackage Installer
0a72863 @LouisLandry Fixing file headers for both unit test and library files.
LouisLandry authored
5 *
4329ba0 @chdemko Tagging 11.4
chdemko authored
6 * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
0a72863 @LouisLandry Fixing file headers for both unit test and library files.
LouisLandry authored
7 * @license GNU General Public License version 2 or later; see LICENSE
f73b659 Imported the new trunk.
Rob Schley authored
8 */
9
fc5a10c @realityking Unify the style of the JPATH_PLATFORM check.
realityking authored
10 defined('JPATH_PLATFORM') or die;
eefdefd @eddieajau Code formatting.
eddieajau authored
11
78828a1 @pasamio Updates to installer subsystem
pasamio authored
12 jimport('joomla.installer.extension');
13 jimport('joomla.base.adapterinstance');
f73b659 Imported the new trunk.
Rob Schley authored
14
15 /**
16 * Template installer
17 *
53daea8 @eddieajau Code cleaning.
eddieajau authored
18 * @package Joomla.Platform
19 * @subpackage Installer
20 * @since 11.1
f73b659 Imported the new trunk.
Rob Schley authored
21 */
78828a1 @pasamio Updates to installer subsystem
pasamio authored
22 class JInstallerTemplate extends JAdapterInstance
f73b659 Imported the new trunk.
Rob Schley authored
23 {
78828a1 @pasamio Updates to installer subsystem
pasamio authored
24 protected $name = null;
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
25
78828a1 @pasamio Updates to installer subsystem
pasamio authored
26 protected $element = null;
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
27
d5b0bdf @dextercowley [#22957] Upgrading a template that uses method="upgrade" removes manu…
dextercowley authored
28 protected $route = 'install';
f73b659 Imported the new trunk.
Rob Schley authored
29
30 /**
34b5d64 @chdemko Changing the way languages are loaded at install and update phase
chdemko authored
31 * Custom loadLanguage method
32 *
a820fcd @eddieajau Code cleaning.
eddieajau authored
33 * @param string $path The path where to find language files.
34 *
35 * @return JInstallerTemplate
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
36 *
53daea8 @eddieajau Code cleaning.
eddieajau authored
37 * @since 11.1
34b5d64 @chdemko Changing the way languages are loaded at install and update phase
chdemko authored
38 */
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
39 public function loadLanguage($path = null)
34b5d64 @chdemko Changing the way languages are loaded at install and update phase
chdemko authored
40 {
fcbb17a @chdemko Merging the admintranslate branch back to the trunk
chdemko authored
41 $source = $this->parent->getPath('source');
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
42
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
43 if (!$source)
44 {
a820fcd @eddieajau Code cleaning.
eddieajau authored
45 $this->parent
46 ->setPath(
54509a7 @realityking Use an autoformatter for the indentation.
realityking authored
47 'source',
48 ($this->parent->extension->client_id ? JPATH_ADMINISTRATOR : JPATH_SITE) . '/templates/' . $this->parent->extension->element
49 );
fcbb17a @chdemko Merging the admintranslate branch back to the trunk
chdemko authored
50 }
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
51
d5b0bdf @dextercowley [#22957] Upgrading a template that uses method="upgrade" removes manu…
dextercowley authored
52 $clientId = isset($this->parent->extension) ? $this->parent->extension->client_id : 0;
aa5891a @eddieajau Fixed issue [#20907] Making Joomla more compliant to PHP strict standard
eddieajau authored
53 $this->manifest = $this->parent->getManifest();
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
54 $name = strtolower(JFilterInput::getInstance()->clean((string) $this->manifest->name, 'cmd'));
55 $client = (string) $this->manifest->attributes()->client;
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
56
c2a4952 @pasamio # Applied [#20263] E_WARNING Error in JInstallerTemplate::loadLanguag…
pasamio authored
57 // Load administrator language if not set.
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
58 if (!$client)
59 {
c2a4952 @pasamio # Applied [#20263] E_WARNING Error in JInstallerTemplate::loadLanguag…
pasamio authored
60 $client = 'ADMINISTRATOR';
61 }
62
34b5d64 @chdemko Changing the way languages are loaded at install and update phase
chdemko authored
63 $extension = "tpl_$name";
aa5891a @eddieajau Fixed issue [#20907] Making Joomla more compliant to PHP strict standard
eddieajau authored
64 $lang = JFactory::getLanguage();
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
65 $source = $path ? $path : ($this->parent->extension->client_id ? JPATH_ADMINISTRATOR : JPATH_SITE) . '/templates/' . $name;
a820fcd @eddieajau Code cleaning.
eddieajau authored
66 $lang->load($extension . '.sys', $source, null, false, false)
67 || $lang->load($extension . '.sys', constant('JPATH_' . strtoupper($client)), null, false, false)
68 || $lang->load($extension . '.sys', $source, $lang->getDefault(), false, false)
69 || $lang->load($extension . '.sys', constant('JPATH_' . strtoupper($client)), $lang->getDefault(), false, false);
34b5d64 @chdemko Changing the way languages are loaded at install and update phase
chdemko authored
70 }
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
71
34b5d64 @chdemko Changing the way languages are loaded at install and update phase
chdemko authored
72 /**
f73b659 Imported the new trunk.
Rob Schley authored
73 * Custom install method
74 *
53daea8 @eddieajau Code cleaning.
eddieajau authored
75 * @return boolean True on success
ccb71ca @LouisLandry Code cleaning.
LouisLandry authored
76 *
53daea8 @eddieajau Code cleaning.
eddieajau authored
77 * @since 11.1
f73b659 Imported the new trunk.
Rob Schley authored
78 */
78828a1 @pasamio Updates to installer subsystem
pasamio authored
79 public function install()
f73b659 Imported the new trunk.
Rob Schley authored
80 {
f2eefd8 @hieblmedia The template install adapter never return an existing extension id (s…
hieblmedia authored
81 // Get a database connector object
82 $db = $this->parent->getDbo();
9e7df98 @hieblmedia Code Style
hieblmedia authored
83
a028a77 @chdemko $ Storing the default style name without ** when language debug is on…
chdemko authored
84 $lang = JFactory::getLanguage();
9d3bd0a @Hackwar ^ Using PHPs built in SimpleXML instead of JSimpleXML to read XML fil…
Hackwar authored
85 $xml = $this->parent->getManifest();
f73b659 Imported the new trunk.
Rob Schley authored
86
87 // Get the client application target
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
88 if ($cname = (string) $xml->attributes()->client)
89 {
f73b659 Imported the new trunk.
Rob Schley authored
90 // Attempt to map the client to a base path
aa5891a @eddieajau Fixed issue [#20907] Making Joomla more compliant to PHP strict standard
eddieajau authored
91 $client = JApplicationHelper::getClientInfo($cname, true);
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
92 if ($client === false)
93 {
6f82ea6 $ Refactoring ini/keys in libraries/J/Installer/template + helper
Jean-Marie Simonet authored
94 $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_TPL_INSTALL_UNKNOWN_CLIENT', $cname));
f73b659 Imported the new trunk.
Rob Schley authored
95 return false;
96 }
97 $basePath = $client->path;
98 $clientId = $client->id;
eefdefd @eddieajau Code formatting.
eddieajau authored
99 }
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
100 else
101 {
f73b659 Imported the new trunk.
Rob Schley authored
102 // No client attribute was found so we assume the site as the client
103 $cname = 'site';
104 $basePath = JPATH_SITE;
105 $clientId = 0;
106 }
107
703224e @elinw installer
elinw authored
108 // Set the extension's name
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
109 $name = JFilterInput::getInstance()->clean((string) $xml->name, 'cmd');
eefdefd @eddieajau Code formatting.
eddieajau authored
110
78828a1 @pasamio Updates to installer subsystem
pasamio authored
111 $element = strtolower(str_replace(" ", "_", $name));
f73b659 Imported the new trunk.
Rob Schley authored
112 $this->set('name', $name);
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
113 $this->set('element', $element);
eefdefd @eddieajau Code formatting.
eddieajau authored
114
f2eefd8 @hieblmedia The template install adapter never return an existing extension id (s…
hieblmedia authored
115 // Check to see if a template by the same name is already installed.
b29aa16 @mbabker Remove DB specific quoting, add AS statement
mbabker authored
116 $query = $db->getQuery(true);
f2eefd8 @hieblmedia The template install adapter never return an existing extension id (s…
hieblmedia authored
117 $query->select($query->qn('extension_id'))->from($query->qn('#__extensions'));
118 $query->where($query->qn('type') . ' = ' . $query->q('template'));
119 $query->where($query->qn('element') . ' = ' . $query->q($element));
9e7df98 @hieblmedia Code Style
hieblmedia authored
120 $db->setQuery($query);
f2eefd8 @hieblmedia The template install adapter never return an existing extension id (s…
hieblmedia authored
121
122 try
123 {
5e9db80 @hieblmedia Add: Legacy error handling
hieblmedia authored
124 $id = $db->loadResult();
f2eefd8 @hieblmedia The template install adapter never return an existing extension id (s…
hieblmedia authored
125 }
17119eb @LouisLandry Fixing up all references to legacy JDatabase classes so that they work
LouisLandry authored
126 catch (RuntimeException $e)
f2eefd8 @hieblmedia The template install adapter never return an existing extension id (s…
hieblmedia authored
127 {
128 // Install failed, roll back changes
5e9db80 @hieblmedia Add: Legacy error handling
hieblmedia authored
129 $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_TPL_INSTALL_ROLLBACK'), $e->getMessage());
130 return false;
131 }
132
d5b0bdf @dextercowley [#22957] Upgrading a template that uses method="upgrade" removes manu…
dextercowley authored
133 // Set the template root path
a5a8f75 @eddieajau Merging uncaught changes from Joomla SVN trunk.
eddieajau authored
134 $this->parent->setPath('extension_root', $basePath . '/templates/' . $element);
d5b0bdf @dextercowley [#22957] Upgrading a template that uses method="upgrade" removes manu…
dextercowley authored
135
9e9d4d9 @elkuku Code style: Single comments fix
elkuku authored
136 // If it's on the fs...
a2b9d04 @mbabker Remove deprecated code in Installer package
mbabker authored
137 if (file_exists($this->parent->getPath('extension_root')) && (!$this->parent->isOverwrite() || $this->parent->isUpgrade()))
d5b0bdf @dextercowley [#22957] Upgrading a template that uses method="upgrade" removes manu…
dextercowley authored
138 {
139 $updateElement = $xml->update;
f9434c6 @elkuku Code style: fix single comments
elkuku authored
140
a3600e9 @mbabker Cleanup in installer adapters
mbabker authored
141 // Upgrade manually set or update tag detected
142 if ($this->parent->isUpgrade() || $updateElement)
a820fcd @eddieajau Code cleaning.
eddieajau authored
143 {
144 // Force this one
145 $this->parent->setOverwrite(true);
146 $this->parent->setUpgrade(true);
147 if ($id)
7515b81 @realityking Fix stuff the autoformatter didn't do nicely.
realityking authored
148 {
f9434c6 @elkuku Code style: fix single comments
elkuku authored
149 // If there is a matching extension mark this as an update; semantics really
a820fcd @eddieajau Code cleaning.
eddieajau authored
150 $this->route = 'update';
d5b0bdf @dextercowley [#22957] Upgrading a template that uses method="upgrade" removes manu…
dextercowley authored
151 }
eefdefd @eddieajau Code formatting.
eddieajau authored
152 }
a2b9d04 @mbabker Remove deprecated code in Installer package
mbabker authored
153 elseif (!$this->parent->isOverwrite())
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
154 {
a820fcd @eddieajau Code cleaning.
eddieajau authored
155 // Overwrite is not set
311faf5 @mbabker Spelling & doc block
mbabker authored
156 // If we didn't have overwrite set, find an update function or find an update tag so let's call it safe
a820fcd @eddieajau Code cleaning.
eddieajau authored
157 $this->parent
158 ->abort(
54509a7 @realityking Use an autoformatter for the indentation.
realityking authored
159 JText::sprintf(
ccecb84 @hieblmedia Fixed wrong lang tag
hieblmedia authored
160 'JLIB_INSTALLER_ABORT_TPL_INSTALL_ANOTHER_TEMPLATE_USING_DIRECTORY', JText::_('JLIB_INSTALLER_' . $this->route),
54509a7 @realityking Use an autoformatter for the indentation.
realityking authored
161 $this->parent->getPath('extension_root')
162 )
a820fcd @eddieajau Code cleaning.
eddieajau authored
163 );
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
164 return false;
165 }
a820fcd @eddieajau Code cleaning.
eddieajau authored
166 }
f73b659 Imported the new trunk.
Rob Schley authored
167
a820fcd @eddieajau Code cleaning.
eddieajau authored
168 /*
169 * If the template directory already exists, then we will assume that the template is already
170 * installed or another template is using that directory.
171 */
a2b9d04 @mbabker Remove deprecated code in Installer package
mbabker authored
172 if (file_exists($this->parent->getPath('extension_root')) && !$this->parent->isOverwrite())
a820fcd @eddieajau Code cleaning.
eddieajau authored
173 {
595a6e2 JError to JLog
Amy Stephen authored
174 JLog::add(JText::sprintf('JLIB_INSTALLER_ABORT_TPL_INSTALL_ANOTHER_TEMPLATE_USING_DIRECTORY', $this->parent->getPath('extension_root')), JLog::WARNING, 'jerror');
a820fcd @eddieajau Code cleaning.
eddieajau authored
175 return false;
176 }
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
177
a820fcd @eddieajau Code cleaning.
eddieajau authored
178 // If the template directory does not exist, let's create it
179 $created = false;
180 if (!file_exists($this->parent->getPath('extension_root')))
181 {
182 if (!$created = JFolder::create($this->parent->getPath('extension_root')))
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
183 {
a820fcd @eddieajau Code cleaning.
eddieajau authored
184 $this->parent
185 ->abort(JText::sprintf('JLIB_INSTALLER_ABORT_TPL_INSTALL_FAILED_CREATE_DIRECTORY', $this->parent->getPath('extension_root')));
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
186
f73b659 Imported the new trunk.
Rob Schley authored
187 return false;
188 }
a820fcd @eddieajau Code cleaning.
eddieajau authored
189 }
f73b659 Imported the new trunk.
Rob Schley authored
190
a820fcd @eddieajau Code cleaning.
eddieajau authored
191 // If we created the template directory and will want to remove it if we have to roll back
192 // the installation, let's add it to the installation step stack
193 if ($created)
194 {
195 $this->parent->pushStep(array('type' => 'folder', 'path' => $this->parent->getPath('extension_root')));
196 }
f73b659 Imported the new trunk.
Rob Schley authored
197
a820fcd @eddieajau Code cleaning.
eddieajau authored
198 // Copy all the necessary files
199 if ($this->parent->parseFiles($xml->files, -1) === false)
200 {
201 // Install failed, rollback changes
202 $this->parent->abort();
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
203
a820fcd @eddieajau Code cleaning.
eddieajau authored
204 return false;
205 }
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
206
a820fcd @eddieajau Code cleaning.
eddieajau authored
207 if ($this->parent->parseFiles($xml->images, -1) === false)
208 {
209 // Install failed, rollback changes
210 $this->parent->abort();
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
211
a820fcd @eddieajau Code cleaning.
eddieajau authored
212 return false;
213 }
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
214
a820fcd @eddieajau Code cleaning.
eddieajau authored
215 if ($this->parent->parseFiles($xml->css, -1) === false)
216 {
217 // Install failed, rollback changes
218 $this->parent->abort();
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
219
a820fcd @eddieajau Code cleaning.
eddieajau authored
220 return false;
221 }
f73b659 Imported the new trunk.
Rob Schley authored
222
a820fcd @eddieajau Code cleaning.
eddieajau authored
223 // Parse optional tags
224 $this->parent->parseMedia($xml->media);
225 $this->parent->parseLanguages($xml->languages, $clientId);
f73b659 Imported the new trunk.
Rob Schley authored
226
a820fcd @eddieajau Code cleaning.
eddieajau authored
227 // Get the template description
228 $this->parent->set('message', JText::_((string) $xml->description));
f73b659 Imported the new trunk.
Rob Schley authored
229
a820fcd @eddieajau Code cleaning.
eddieajau authored
230 // Lastly, we will copy the manifest file to its appropriate place.
231 if (!$this->parent->copyManifest(-1))
232 {
233 // Install failed, rollback changes
234 $this->parent->abort(JText::_('JLIB_INSTALLER_ABORT_TPL_INSTALL_COPY_SETUP'));
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
235
a820fcd @eddieajau Code cleaning.
eddieajau authored
236 return false;
237 }
f73b659 Imported the new trunk.
Rob Schley authored
238
a3600e9 @mbabker Cleanup in installer adapters
mbabker authored
239 /**
240 * ---------------------------------------------------------------------------------------------
241 * Extension Registration
242 * ---------------------------------------------------------------------------------------------
243 */
703224e @elinw installer
elinw authored
244
a820fcd @eddieajau Code cleaning.
eddieajau authored
245 $row = JTable::getInstance('extension');
d5b0bdf @dextercowley [#22957] Upgrading a template that uses method="upgrade" removes manu…
dextercowley authored
246
a820fcd @eddieajau Code cleaning.
eddieajau authored
247 if ($this->route == 'update' && $id)
248 {
249 $row->load($id);
78828a1 @pasamio Updates to installer subsystem
pasamio authored
250 }
a820fcd @eddieajau Code cleaning.
eddieajau authored
251 else
d5b0bdf @dextercowley [#22957] Upgrading a template that uses method="upgrade" removes manu…
dextercowley authored
252 {
a820fcd @eddieajau Code cleaning.
eddieajau authored
253 $row->type = 'template';
254 $row->element = $this->get('element');
f9434c6 @elkuku Code style: fix single comments
elkuku authored
255
a820fcd @eddieajau Code cleaning.
eddieajau authored
256 // There is no folder for templates
257 $row->folder = '';
258 $row->enabled = 1;
259 $row->protected = 0;
260 $row->access = 1;
261 $row->client_id = $clientId;
262 $row->params = $this->parent->getParams();
f9434c6 @elkuku Code style: fix single comments
elkuku authored
263
264 // Custom data
265 $row->custom_data = '';
d5b0bdf @dextercowley [#22957] Upgrading a template that uses method="upgrade" removes manu…
dextercowley authored
266 }
f9434c6 @elkuku Code style: fix single comments
elkuku authored
267
268 // Name might change in an update
269 $row->name = $this->get('name');
a820fcd @eddieajau Code cleaning.
eddieajau authored
270 $row->manifest_cache = $this->parent->generateManifestCache();
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
271
a820fcd @eddieajau Code cleaning.
eddieajau authored
272 if (!$row->store())
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
273 {
a820fcd @eddieajau Code cleaning.
eddieajau authored
274 // Install failed, roll back changes
275 $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_TPL_INSTALL_ROLLBACK', $db->stderr(true)));
89e3d3a @LouisLandry Fixed up file headers.
LouisLandry authored
276
a820fcd @eddieajau Code cleaning.
eddieajau authored
277 return false;
278 }
f73b659 Imported the new trunk.
Rob Schley authored
279
a820fcd @eddieajau Code cleaning.
eddieajau authored
280 if ($this->route == 'install')
281 {
f9434c6 @elkuku Code style: fix single comments
elkuku authored
282 // Insert record in #__template_styles
a820fcd @eddieajau Code cleaning.
eddieajau authored
283 $query = $db->getQuery(true);
284 $query->insert('#__template_styles');
285 $query->set('template=' . $db->Quote($row->element));
286 $query->set('client_id=' . $db->Quote($clientId));
287 $query->set('home=0');
288 $debug = $lang->setDebug(false);
289 $query->set('title=' . $db->Quote(JText::sprintf('JLIB_INSTALLER_DEFAULT_STYLE', JText::_($this->get('name')))));
290 $lang->setDebug($debug);
291 $query->set('params=' . $db->Quote($row->params));
292 $db->setQuery($query);
f9434c6 @elkuku Code style: fix single comments
elkuku authored
293
a820fcd @eddieajau Code cleaning.
eddieajau authored
294 // There is a chance this could fail but we don't care...
17119eb @LouisLandry Fixing up all references to legacy JDatabase classes so that they work
LouisLandry authored
295 $db->execute();
a820fcd @eddieajau Code cleaning.
eddieajau authored
296 }
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
297
a820fcd @eddieajau Code cleaning.
eddieajau authored
298 return $row->get('extension_id');
299 }
78828a1 @pasamio Updates to installer subsystem
pasamio authored
300
a820fcd @eddieajau Code cleaning.
eddieajau authored
301 /**
302 * Custom update method for components
303 *
304 * @return boolean True on success
305 *
306 * @since 11.1
307 */
308 public function update()
309 {
310 return $this->install();
311 }
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
312
a820fcd @eddieajau Code cleaning.
eddieajau authored
313 /**
314 * Custom uninstall method
315 *
316 * @param integer $id The extension ID
317 *
318 * @return boolean True on success
319 *
320 * @since 11.1
321 */
322 public function uninstall($id)
323 {
324 // Initialise variables.
325 $retval = true;
78828a1 @pasamio Updates to installer subsystem
pasamio authored
326
a820fcd @eddieajau Code cleaning.
eddieajau authored
327 // First order of business will be to load the template object table from the database.
328 // This should give us the necessary information to proceed.
329 $row = JTable::getInstance('extension');
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
330
a820fcd @eddieajau Code cleaning.
eddieajau authored
331 if (!$row->load((int) $id) || !strlen($row->element))
332 {
595a6e2 JError to JLog
Amy Stephen authored
333 JLog::add(JText::_('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_ERRORUNKOWNEXTENSION'), JLog::WARNING, 'jerror');
a820fcd @eddieajau Code cleaning.
eddieajau authored
334 return false;
335 }
f73b659 Imported the new trunk.
Rob Schley authored
336
a820fcd @eddieajau Code cleaning.
eddieajau authored
337 // Is the template we are trying to uninstall a core one?
338 // Because that is not a good idea...
339 if ($row->protected)
340 {
595a6e2 JError to JLog
Amy Stephen authored
341 JLog::add(JText::sprintf('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_WARNCORETEMPLATE', $row->name), JLog::WARNING, 'jerror');
a820fcd @eddieajau Code cleaning.
eddieajau authored
342 return false;
343 }
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
344
a820fcd @eddieajau Code cleaning.
eddieajau authored
345 $name = $row->element;
346 $clientId = $row->client_id;
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
347
a820fcd @eddieajau Code cleaning.
eddieajau authored
348 // For a template the id will be the template name which represents the subfolder of the templates folder that the template resides in.
349 if (!$name)
350 {
595a6e2 JError to JLog
Amy Stephen authored
351 JLog::add(JText::_('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_TEMPLATE_ID_EMPTY'), JLog::WARNING, 'jerror');
a820fcd @eddieajau Code cleaning.
eddieajau authored
352 return false;
353 }
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
354
a820fcd @eddieajau Code cleaning.
eddieajau authored
355 // Deny remove default template
356 $db = $this->parent->getDbo();
357 $query = 'SELECT COUNT(*) FROM #__template_styles' . ' WHERE home = 1 AND template = ' . $db->Quote($name);
358 $db->setQuery($query);
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
359
a820fcd @eddieajau Code cleaning.
eddieajau authored
360 if ($db->loadResult() != 0)
361 {
595a6e2 JError to JLog
Amy Stephen authored
362 JLog::add(JText::_('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_TEMPLATE_DEFAULT'), JLog::WARNING, 'jerror');
a820fcd @eddieajau Code cleaning.
eddieajau authored
363 return false;
364 }
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
365
a820fcd @eddieajau Code cleaning.
eddieajau authored
366 // Get the template root path
367 $client = JApplicationHelper::getClientInfo($clientId);
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
368
a820fcd @eddieajau Code cleaning.
eddieajau authored
369 if (!$client)
370 {
595a6e2 JError to JLog
Amy Stephen authored
371 JLog::add(JText::_('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_INVALID_CLIENT'), JLog::WARNING, 'jerror');
a820fcd @eddieajau Code cleaning.
eddieajau authored
372 return false;
373 }
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
374
a820fcd @eddieajau Code cleaning.
eddieajau authored
375 $this->parent->setPath('extension_root', $client->path . '/templates/' . strtolower($name));
376 $this->parent->setPath('source', $this->parent->getPath('extension_root'));
f73b659 Imported the new trunk.
Rob Schley authored
377
a820fcd @eddieajau Code cleaning.
eddieajau authored
378 // We do findManifest to avoid problem when uninstalling a list of extensions: getManifest cache its manifest file
379 $this->parent->findManifest();
380 $manifest = $this->parent->getManifest();
381 if (!($manifest instanceof JXMLElement))
382 {
383 // Kill the extension entry
78828a1 @pasamio Updates to installer subsystem
pasamio authored
384 $row->delete($row->extension_id);
385 unset($row);
f9434c6 @elkuku Code style: fix single comments
elkuku authored
386
a820fcd @eddieajau Code cleaning.
eddieajau authored
387 // Make sure we delete the folders
388 JFolder::delete($this->parent->getPath('extension_root'));
595a6e2 JError to JLog
Amy Stephen authored
389 JLog::add(JText::_('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_INVALID_NOTFOUND_MANIFEST'), JLog::WARNING, 'jerror');
a820fcd @eddieajau Code cleaning.
eddieajau authored
390 return false;
f73b659 Imported the new trunk.
Rob Schley authored
391 }
392
a820fcd @eddieajau Code cleaning.
eddieajau authored
393 // Remove files
394 $this->parent->removeFiles($manifest->media);
395 $this->parent->removeFiles($manifest->languages, $clientId);
396
397 // Delete the template directory
398 if (JFolder::exists($this->parent->getPath('extension_root')))
399 {
400 $retval = JFolder::delete($this->parent->getPath('extension_root'));
401 }
402 else
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
403 {
595a6e2 JError to JLog
Amy Stephen authored
404 JLog::add(JText::_('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_TEMPLATE_DIRECTORY'), JLog::WARNING, 'jerror');
a820fcd @eddieajau Code cleaning.
eddieajau authored
405 $retval = false;
406 }
407
408 // Set menu that assigned to the template back to default template
409 $query = 'UPDATE #__menu INNER JOIN #__template_styles' . ' ON #__template_styles.id = #__menu.template_style_id'
410 . ' SET #__menu.template_style_id = 0' . ' WHERE #__template_styles.template = ' . $db->Quote(strtolower($name))
411 . ' AND #__template_styles.client_id = ' . $db->Quote($clientId);
412 $db->setQuery($query);
17119eb @LouisLandry Fixing up all references to legacy JDatabase classes so that they work
LouisLandry authored
413 $db->execute();
f73b659 Imported the new trunk.
Rob Schley authored
414
a820fcd @eddieajau Code cleaning.
eddieajau authored
415 $query = 'DELETE FROM #__template_styles' . ' WHERE template = ' . $db->Quote($name) . ' AND client_id = ' . $db->Quote($clientId);
416 $db->setQuery($query);
17119eb @LouisLandry Fixing up all references to legacy JDatabase classes so that they work
LouisLandry authored
417 $db->execute();
a820fcd @eddieajau Code cleaning.
eddieajau authored
418
419 $row->delete($row->extension_id);
420 unset($row);
421
422 return $retval;
423 }
424
425 /**
426 * Discover existing but uninstalled templates
427 *
428 * @return array JExtensionTable list
429 */
f7db975 @eddieajau Fix up missing method scope declarations.
eddieajau authored
430 public function discover()
a820fcd @eddieajau Code cleaning.
eddieajau authored
431 {
9f10f39 @realityking Make all PHP keywords (but not built-in functions) lowercase.
realityking authored
432 $results = array();
a820fcd @eddieajau Code cleaning.
eddieajau authored
433 $site_list = JFolder::folders(JPATH_SITE . '/templates');
434 $admin_list = JFolder::folders(JPATH_ADMINISTRATOR . '/templates');
435 $site_info = JApplicationHelper::getClientInfo('site', true);
436 $admin_info = JApplicationHelper::getClientInfo('administrator', true);
437
438 foreach ($site_list as $template)
439 {
440 if ($template == 'system')
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
441 {
a820fcd @eddieajau Code cleaning.
eddieajau authored
442 // Ignore special system template
a3600e9 @mbabker Cleanup in installer adapters
mbabker authored
443 continue;
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
444 }
f970d7a @jonnsl Deprecate JApplicationHelper::parseXMLInstallFile and move to JInstaller
jonnsl authored
445 $manifest_details = JInstaller::parseXMLInstallFile(JPATH_SITE . "/templates/$template/templateDetails.xml");
a820fcd @eddieajau Code cleaning.
eddieajau authored
446 $extension = JTable::getInstance('extension');
447 $extension->set('type', 'template');
448 $extension->set('client_id', $site_info->id);
449 $extension->set('element', $template);
450 $extension->set('name', $template);
451 $extension->set('state', -1);
452 $extension->set('manifest_cache', json_encode($manifest_details));
453 $results[] = $extension;
454 }
78828a1 @pasamio Updates to installer subsystem
pasamio authored
455
a820fcd @eddieajau Code cleaning.
eddieajau authored
456 foreach ($admin_list as $template)
457 {
458 if ($template == 'system')
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
459 {
a820fcd @eddieajau Code cleaning.
eddieajau authored
460 // Ignore special system template
a3600e9 @mbabker Cleanup in installer adapters
mbabker authored
461 continue;
eefdefd @eddieajau Code formatting.
eddieajau authored
462 }
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
463
f970d7a @jonnsl Deprecate JApplicationHelper::parseXMLInstallFile and move to JInstaller
jonnsl authored
464 $manifest_details = JInstaller::parseXMLInstallFile(JPATH_ADMINISTRATOR . "/templates/$template/templateDetails.xml");
a820fcd @eddieajau Code cleaning.
eddieajau authored
465 $extension = JTable::getInstance('extension');
466 $extension->set('type', 'template');
467 $extension->set('client_id', $admin_info->id);
468 $extension->set('element', $template);
469 $extension->set('name', $template);
470 $extension->set('state', -1);
471 $extension->set('manifest_cache', json_encode($manifest_details));
472 $results[] = $extension;
78828a1 @pasamio Updates to installer subsystem
pasamio authored
473 }
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
474
a820fcd @eddieajau Code cleaning.
eddieajau authored
475 return $results;
476 }
477
478 /**
479 * Discover_install
480 * Perform an install for a discovered extension
481 *
482 * @return boolean
483 *
484 * @since 11.1
485 */
f7db975 @eddieajau Fix up missing method scope declarations.
eddieajau authored
486 public function discover_install()
a820fcd @eddieajau Code cleaning.
eddieajau authored
487 {
488 // Templates are one of the easiest
489 // If its not in the extensions table we just add it
490 $client = JApplicationHelper::getClientInfo($this->parent->extension->client_id);
491 $manifestPath = $client->path . '/templates/' . $this->parent->extension->element . '/templateDetails.xml';
492 $this->parent->manifest = $this->parent->isManifest($manifestPath);
493 $description = (string) $this->parent->manifest->description;
494
495 if ($description)
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
496 {
a820fcd @eddieajau Code cleaning.
eddieajau authored
497 $this->parent->set('message', JText::_($description));
498 }
499 else
500 {
501 $this->parent->set('message', '');
502 }
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
503
a820fcd @eddieajau Code cleaning.
eddieajau authored
504 $this->parent->setPath('manifest', $manifestPath);
f970d7a @jonnsl Deprecate JApplicationHelper::parseXMLInstallFile and move to JInstaller
jonnsl authored
505 $manifest_details = JInstaller::parseXMLInstallFile($this->parent->getPath('manifest'));
a820fcd @eddieajau Code cleaning.
eddieajau authored
506 $this->parent->extension->manifest_cache = json_encode($manifest_details);
507 $this->parent->extension->state = 0;
508 $this->parent->extension->name = $manifest_details['name'];
509 $this->parent->extension->enabled = 1;
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
510
9005bd1 @elkuku Removing unnecessary empty braces when instancing classes
elkuku authored
511 $data = new JObject;
668b9a5 @chdemko Fixed [#20232] Discovery method of installing templates doesn't inser…
chdemko authored
512
a820fcd @eddieajau Code cleaning.
eddieajau authored
513 foreach ($manifest_details as $key => $value)
514 {
515 $data->set($key, $value);
516 }
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
517
a820fcd @eddieajau Code cleaning.
eddieajau authored
518 $this->parent->extension->params = $this->parent->getParams();
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
519
a820fcd @eddieajau Code cleaning.
eddieajau authored
520 if ($this->parent->extension->store())
521 {
f9434c6 @elkuku Code style: fix single comments
elkuku authored
522 // Insert record in #__template_styles
a820fcd @eddieajau Code cleaning.
eddieajau authored
523 $db = $this->parent->getDbo();
524 $query = $db->getQuery(true);
525 $query->insert('#__template_styles');
8e64310 @chdemko Update libraries/joomla/installer/adapters/template.php
chdemko authored
526 $query->set('template=' . $db->Quote($this->parent->extension->element));
a820fcd @eddieajau Code cleaning.
eddieajau authored
527 $query->set('client_id=' . $db->Quote($this->parent->extension->client_id));
528 $query->set('home=0');
529 $query->set('title=' . $db->Quote(JText::sprintf('JLIB_INSTALLER_DEFAULT_STYLE', $this->parent->extension->name)));
530 $query->set('params=' . $db->Quote($this->parent->extension->params));
531 $db->setQuery($query);
17119eb @LouisLandry Fixing up all references to legacy JDatabase classes so that they work
LouisLandry authored
532 $db->execute();
eefdefd @eddieajau Code formatting.
eddieajau authored
533
a820fcd @eddieajau Code cleaning.
eddieajau authored
534 return $this->parent->extension->get('extension_id');
535 }
536 else
537 {
595a6e2 JError to JLog
Amy Stephen authored
538 JLog::add(JText::_('JLIB_INSTALLER_ERROR_TPL_DISCOVER_STORE_DETAILS'), JLog::WARNING, 'jerror');
a820fcd @eddieajau Code cleaning.
eddieajau authored
539 return false;
eefdefd @eddieajau Code formatting.
eddieajau authored
540 }
a820fcd @eddieajau Code cleaning.
eddieajau authored
541 }
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
542
a820fcd @eddieajau Code cleaning.
eddieajau authored
543 /**
544 * Refreshes the extension table cache
545 *
546 * @return boolean Result of operation, true if updated, false on failure
547 *
548 * @since 11.1
549 */
550 public function refreshManifestCache()
551 {
552 // Need to find to find where the XML file is since we don't store this normally.
553 $client = JApplicationHelper::getClientInfo($this->parent->extension->client_id);
554 $manifestPath = $client->path . '/templates/' . $this->parent->extension->element . '/templateDetails.xml';
555 $this->parent->manifest = $this->parent->isManifest($manifestPath);
556 $this->parent->setPath('manifest', $manifestPath);
89e3d3a @LouisLandry Fixed up file headers.
LouisLandry authored
557
f970d7a @jonnsl Deprecate JApplicationHelper::parseXMLInstallFile and move to JInstaller
jonnsl authored
558 $manifest_details = JInstaller::parseXMLInstallFile($this->parent->getPath('manifest'));
a820fcd @eddieajau Code cleaning.
eddieajau authored
559 $this->parent->extension->manifest_cache = json_encode($manifest_details);
560 $this->parent->extension->name = $manifest_details['name'];
9589e50 @chdemko [#23837] *Installation unexpectedly terminated: Method not supported …
chdemko authored
561
a820fcd @eddieajau Code cleaning.
eddieajau authored
562 try
563 {
564 return $this->parent->extension->store();
9589e50 @chdemko [#23837] *Installation unexpectedly terminated: Method not supported …
chdemko authored
565 }
17119eb @LouisLandry Fixing up all references to legacy JDatabase classes so that they work
LouisLandry authored
566 catch (RuntimeException $e)
a820fcd @eddieajau Code cleaning.
eddieajau authored
567 {
595a6e2 JError to JLog
Amy Stephen authored
568 JLog::add(JText::_('JLIB_INSTALLER_ERROR_TPL_REFRESH_MANIFEST_CACHE'), JLog::WARNING, 'jerror');
a820fcd @eddieajau Code cleaning.
eddieajau authored
569 return false;
570 }
571 }
572 }
Something went wrong with that request. Please try again.