Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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