PageRenderTime 54ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/joomla/installer/adapters/module.php

https://github.com/cosmocommerce/joomla
PHP | 735 lines | 459 code | 58 blank | 218 comment | 60 complexity | 5c826050e9719390ee7f6055ff5feb51 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
  5. * @license GNU General Public License version 2 or later; see LICENSE.txt
  6. */
  7. // No direct access
  8. defined('JPATH_BASE') or die;
  9. jimport('joomla.base.adapterinstance');
  10. /**
  11. * Module installer
  12. *
  13. * @package Joomla.Framework
  14. * @subpackage Installer
  15. * @since 1.5
  16. */
  17. class JInstallerModule extends JAdapterInstance
  18. {
  19. /**
  20. * @var string install function routing
  21. */
  22. protected $route = 'Install';
  23. protected $manifest = null;
  24. protected $manifest_script = null;
  25. protected $name = null;
  26. protected $element = null;
  27. protected $scriptElement = null;
  28. /**
  29. * Custom loadLanguage method
  30. *
  31. * @access public
  32. * @param string $path the path where to find language files
  33. * @since 1.6
  34. */
  35. public function loadLanguage($path)
  36. {
  37. $this->manifest = &$this->parent->getManifest();
  38. if ($this->manifest->files)
  39. {
  40. $element = $this->manifest->files;
  41. $extension = '';
  42. if (count($element->children()))
  43. {
  44. foreach ($element->children() as $file)
  45. {
  46. if ((string)$file->attributes()->module)
  47. {
  48. $extension = strtolower((string)$file->attributes()->module);
  49. break;
  50. }
  51. }
  52. }
  53. if ($extension)
  54. {
  55. $lang =& JFactory::getLanguage();
  56. $source = $path;
  57. $folder = (string)$element->attributes()->folder;
  58. if ($folder && file_exists("$path/$folder"))
  59. {
  60. $source = "$path/$folder";
  61. }
  62. $client = (string)$this->manifest->attributes()->client;
  63. $lang->load($extension . '.manage', $source, null, false, false)
  64. || $lang->load($extension, $source, null, false, false)
  65. || $lang->load($extension . '.manage', constant('JPATH_' . strtoupper($client)), null, false, false)
  66. || $lang->load($extension, constant('JPATH_' . strtoupper($client)), null, false, false)
  67. || $lang->load($extension . '.manage', $source, $lang->getDefault(), false, false)
  68. || $lang->load($extension, $source, $lang->getDefault(), false, false)
  69. || $lang->load($extension . '.manage', constant('JPATH_' . strtoupper($client)), $lang->getDefault(), false, false)
  70. || $lang->load($extension, constant('JPATH_' . strtoupper($client)), $lang->getDefault(), false, false);
  71. }
  72. }
  73. }
  74. /**
  75. * Custom install method
  76. *
  77. * @access public
  78. * @return boolean True on success
  79. * @since 1.5
  80. */
  81. public function install()
  82. {
  83. // if this is an update, set the route accordingly
  84. /*if ($this->parent->getUpgrade()) {
  85. $this->route = 'Update';
  86. }*/
  87. // Get a database connector object
  88. $db = &$this->parent->getDbo();
  89. // Get the extension manifest object
  90. $this->manifest = $this->parent->getManifest();
  91. /**
  92. * ---------------------------------------------------------------------------------------------
  93. * Manifest Document Setup Section
  94. * ---------------------------------------------------------------------------------------------
  95. */
  96. // Set the extensions name
  97. $name = (string)$this->manifest->name;
  98. $name = JFilterInput::getInstance()->clean($name, 'string');
  99. $this->set('name', $name);
  100. // Get the component description
  101. $description = (string)$this->manifest->description;
  102. if ($description) {
  103. $this->parent->set('message', JText::_($description));
  104. }
  105. else {
  106. $this->parent->set('message', '');
  107. }
  108. /**
  109. * ---------------------------------------------------------------------------------------------
  110. * Target Application Section
  111. * ---------------------------------------------------------------------------------------------
  112. */
  113. // Get the target application
  114. if ($cname = (string)$this->manifest->attributes()->client)
  115. {
  116. // Attempt to map the client to a base path
  117. jimport('joomla.application.helper');
  118. $client = &JApplicationHelper::getClientInfo($cname, true);
  119. if ($client === false)
  120. {
  121. $this->parent->abort(JText::_('Module').' '.JText::_($this->route).': '.JText::_('Unknown client type').' ['.$client->name.']');
  122. return false;
  123. }
  124. $basePath = $client->path;
  125. $clientId = $client->id;
  126. }
  127. else
  128. {
  129. // No client attribute was found so we assume the site as the client
  130. $cname = 'site';
  131. $basePath = JPATH_SITE;
  132. $clientId = 0;
  133. }
  134. // Set the installation path
  135. $element = '';
  136. if (count($this->manifest->files->children()))
  137. {
  138. foreach ($this->manifest->files->children() as $file)
  139. {
  140. if ((string)$file->attributes()->module)
  141. {
  142. $element = (string)$file->attributes()->module;
  143. $this->set('element',$element);
  144. break;
  145. }
  146. }
  147. }
  148. if (!empty ($element)) {
  149. $this->parent->setPath('extension_root', $basePath.DS.'modules'.DS.$element);
  150. }
  151. else {
  152. $this->parent->abort(JText::_('Module').' '.JText::_($this->route).': '.JText::_('No module file specified'));
  153. return false;
  154. }
  155. // Check to see if a module by the same name is already installed
  156. // If it is, then update the table because if the files aren't there
  157. // we can assume that it was (badly) uninstalled
  158. // If it isn't, add an entry to extensions
  159. $query = 'SELECT `extension_id`' .
  160. ' FROM `#__extensions` ' .
  161. ' WHERE element = '.$db->Quote($element) .
  162. ' AND client_id = '.(int)$clientId;
  163. $db->setQuery($query);
  164. try {
  165. $db->Query();
  166. }
  167. catch(JException $e)
  168. {
  169. // Install failed, roll back changes
  170. $this->parent->abort(JText::_('Module').' '.JText::_($this->route).': '.$db->stderr(true));
  171. return false;
  172. }
  173. $id = $db->loadResult();
  174. /*
  175. * If the module directory already exists, then we will assume that the
  176. * module is already installed or another module is using that
  177. * directory.
  178. * Check that this is either an issue where its not overwriting or it is
  179. * set to upgrade anyway
  180. */
  181. if (file_exists($this->parent->getPath('extension_root')) && (!$this->parent->getOverwrite() || $this->parent->getUpgrade()))
  182. {
  183. // look for an update function or update tag
  184. $updateElement = $this->manifest->update;
  185. // upgrade manually set
  186. // update function available
  187. // update tag detected
  188. if ($this->parent->getUpgrade() || ($this->parent->manifestClass && method_exists($this->parent->manifestClass,'update')) || is_a($updateElement, 'JXMLElement'))
  189. {
  190. // force these one
  191. $this->parent->setOverwrite(true);
  192. $this->parent->setUpgrade(true);
  193. if ($id) { // if there is a matching extension mark this as an update; semantics really
  194. $this->route = 'Update';
  195. }
  196. }
  197. else if (!$this->parent->getOverwrite())
  198. {
  199. // overwrite is set
  200. // we didn't have overwrite set, find an udpate function or find an update tag so lets call it safe
  201. $this->parent->abort(JText::_('Module').' '.JText::_($this->route).': '.JText::_('Another module is already using directory').': "'.$this->parent->getPath('extension_root').'"');
  202. return false;
  203. }
  204. }
  205. /**
  206. * ---------------------------------------------------------------------------------------------
  207. * Installer Trigger Loading
  208. * ---------------------------------------------------------------------------------------------
  209. */
  210. // If there is an manifest class file, lets load it; we'll copy it later (don't have dest yet)
  211. $this->scriptElement = $this->manifest->scriptfile;
  212. $manifestScript = (string)$this->manifest->scriptfile;
  213. if ($manifestScript)
  214. {
  215. $manifestScriptFile = $this->parent->getPath('source').DS.$manifestScript;
  216. if (is_file($manifestScriptFile))
  217. {
  218. // load the file
  219. include_once $manifestScriptFile;
  220. }
  221. // Set the class name
  222. $classname = $element.'InstallerScript';
  223. if (class_exists($classname))
  224. {
  225. // create a new instance
  226. $this->parent->manifestClass = new $classname($this);
  227. // and set this so we can copy it later
  228. $this->set('manifest_script', $manifestScript);
  229. // Note: if we don't find the class, don't bother to copy the file
  230. }
  231. }
  232. // run preflight if possible (since we know we're not an update)
  233. ob_start();
  234. ob_implicit_flush(false);
  235. if ($this->parent->manifestClass && method_exists($this->parent->manifestClass,'preflight')) {
  236. $this->parent->manifestClass->preflight($this->route, $this);
  237. }
  238. $msg = ob_get_contents(); // create msg object; first use here
  239. ob_end_clean();
  240. /**
  241. * ---------------------------------------------------------------------------------------------
  242. * Filesystem Processing Section
  243. * ---------------------------------------------------------------------------------------------
  244. */
  245. // If the module directory does not exist, lets create it
  246. $created = false;
  247. if (!file_exists($this->parent->getPath('extension_root')))
  248. {
  249. if (!$created = JFolder::create($this->parent->getPath('extension_root')))
  250. {
  251. $this->parent->abort(JText::_('Module').' '.JText::_($this->route).': '.JText::_('FAILED_TO_CREATE_DIRECTORY').': "'.$this->parent->getPath('extension_root').'"');
  252. return false;
  253. }
  254. }
  255. /*
  256. * Since we created the module directory and will want to remove it if
  257. * we have to roll back the installation, lets add it to the
  258. * installation step stack
  259. */
  260. if ($created) {
  261. $this->parent->pushStep(array ('type' => 'folder', 'path' => $this->parent->getPath('extension_root')));
  262. }
  263. // Copy all necessary files
  264. if ($this->parent->parseFiles($this->manifest->files, -1) === false)
  265. {
  266. // Install failed, roll back changes
  267. $this->parent->abort();
  268. return false;
  269. }
  270. // Parse optional tags
  271. $this->parent->parseMedia($this->manifest->media, $clientId);
  272. $this->parent->parseLanguages($this->manifest->languages, $clientId);
  273. // Parse deprecated tags
  274. $this->parent->parseFiles($this->manifest->images, -1);
  275. /**
  276. * ---------------------------------------------------------------------------------------------
  277. * Database Processing Section
  278. * ---------------------------------------------------------------------------------------------
  279. */
  280. // Was there a module already installed with the same name?
  281. if ($id)
  282. {
  283. // load the entry and update the manifest_cache
  284. $row = &JTable::getInstance('extension');
  285. $row->load($id);
  286. $row->name = $this->get('name'); // update name
  287. $row->manifest_cache = $this->parent->generateManifestCache(); // update manifest
  288. if (!$row->store()) {
  289. // Install failed, roll back changes
  290. $this->parent->abort(JText::_('Module').' '.JText::_($this->route).': '.$db->stderr(true));
  291. return false;
  292. }
  293. }
  294. else
  295. {
  296. $row = & JTable::getInstance('extension');
  297. $row->set('name', $this->get('name'));
  298. $row->set('type', 'module');
  299. $row->set('element', $this->get('element'));
  300. $row->set('folder', ''); // There is no folder for modules
  301. $row->set('enabled', 1);
  302. $row->set('protected', 0);
  303. $row->set('access', $clientId == 1 ? 2 : 0);
  304. $row->set('client_id', $clientId);
  305. $row->set('params', $this->parent->getParams());
  306. $row->set('custom_data', ''); // custom data
  307. $row->set('manifest_cache', $this->parent->generateManifestCache());
  308. if (!$row->store())
  309. {
  310. // Install failed, roll back changes
  311. $this->parent->abort(JText::_('Module').' '.JText::_($this->route).': '.$db->stderr(true));
  312. return false;
  313. }
  314. // Since we have created a module item, we add it to the installation step stack
  315. // so that if we have to rollback the changes we can undo it.
  316. $this->parent->pushStep(array ('type' => 'extension', 'extension_id' => $row->extension_id));
  317. }
  318. /*
  319. * Let's run the queries for the module
  320. * If Joomla 1.5 compatible, with discreet sql files - execute appropriate
  321. * file for utf-8 support or non-utf-8 support
  322. */
  323. // try for Joomla 1.5 type queries
  324. // second argument is the utf compatible version attribute
  325. $utfresult = $this->parent->parseSQLFiles($this->manifest->{strtolower($this->route)}->sql);
  326. if ($utfresult === false)
  327. {
  328. // Install failed, rollback changes
  329. $this->parent->abort(JText::_('Module').' '.JText::_($this->route).': '.JText::_('SQLERRORORFILE')." ".$db->stderr(true));
  330. return false;
  331. }
  332. // Start Joomla! 1.6
  333. ob_start();
  334. ob_implicit_flush(false);
  335. if ($this->parent->manifestClass && method_exists($this->parent->manifestClass,$this->route)) $this->parent->manifestClass->{$this->route}($this);
  336. $msg .= ob_get_contents(); // append messages
  337. ob_end_clean();
  338. /**
  339. * ---------------------------------------------------------------------------------------------
  340. * Finalization and Cleanup Section
  341. * ---------------------------------------------------------------------------------------------
  342. */
  343. // Lastly, we will copy the manifest file to its appropriate place.
  344. if (!$this->parent->copyManifest(-1))
  345. {
  346. // Install failed, rollback changes
  347. $this->parent->abort(JText::_('Module').' '.JText::_($this->route).': '.JText::_('COULD_NOT_COPY_SETUP_FILE'));
  348. return false;
  349. }
  350. // And now we run the postflight
  351. ob_start();
  352. ob_implicit_flush(false);
  353. if ($this->parent->manifestClass && method_exists($this->parent->manifestClass,'postflight')) {
  354. $this->parent->manifestClass->postflight($this->route, $this);
  355. }
  356. $msg .= ob_get_contents(); // append messages
  357. ob_end_clean();
  358. if ($msg != '') {
  359. $this->parent->set('extension_message', $msg);
  360. }
  361. return $row->get('extension_id');
  362. }
  363. /**
  364. * Custom update method
  365. * This is really a shell for the install system
  366. *
  367. * @access public
  368. * @return boolean True on success
  369. * @since 1.6
  370. */
  371. function update()
  372. {
  373. // set the overwrite setting
  374. $this->parent->setOverwrite(true);
  375. $this->parent->setUpgrade(true);
  376. // set the route for the install
  377. $this->route = 'Update';
  378. // go to install which handles updates properly
  379. return $this->install();
  380. }
  381. /**
  382. * Custom discover method
  383. *
  384. * @access public
  385. * @return array(JExtension) list of extensions available
  386. * @since 1.6
  387. */
  388. function discover()
  389. {
  390. $results = Array();
  391. $site_list = JFolder::folders(JPATH_SITE.DS.'modules');
  392. $admin_list = JFolder::folders(JPATH_ADMINISTRATOR.DS.'modules');
  393. $site_info = JApplicationHelper::getClientInfo('site', true);
  394. $admin_info = JApplicationHelper::getClientInfo('administrator', true);
  395. foreach ($site_list as $module)
  396. {
  397. $extension = &JTable::getInstance('extension');
  398. $extension->set('type', 'module');
  399. $extension->set('client_id', $site_info->id);
  400. $extension->set('element', $module);
  401. $extension->set('name', $module);
  402. $extension->set('state', -1);
  403. $results[] = clone $extension;
  404. }
  405. foreach ($admin_list as $module)
  406. {
  407. $extension = &JTable::getInstance('extension');
  408. $extension->set('type', 'module');
  409. $extension->set('client_id', $admin_info->id);
  410. $extension->set('element', $module);
  411. $extension->set('name', $module);
  412. $extension->set('state', -1);
  413. $results[] = clone $extension;
  414. }
  415. return $results;
  416. }
  417. /**
  418. * Custom discover_install method
  419. *
  420. * @access public
  421. * @param int $id The id of the extension to install (from #__discoveredextensions)
  422. * @return void
  423. * @since 1.6
  424. */
  425. function discover_install()
  426. {
  427. // Modules are like templates, and are one of the easiest
  428. // If its not in the extensions table we just add it
  429. $client = JApplicationHelper::getClientInfo($this->parent->extension->client_id);
  430. $manifestPath = $client->path . DS . 'modules'. DS . $this->parent->extension->element . DS . $this->parent->extension->element . '.xml';
  431. $this->parent->manifest = $this->parent->isManifest($manifestPath);
  432. $this->parent->setPath('manifest', $manifestPath);
  433. $manifest_details = JApplicationHelper::parseXMLInstallFile($this->parent->getPath('manifest'));
  434. // TODO: Re-evaluate this; should we run installation triggers? postflight perhaps?
  435. $this->parent->extension->manifest_cache = serialize($manifest_details);
  436. $this->parent->extension->state = 0;
  437. $this->parent->extension->name = $manifest_details['name'];
  438. $this->parent->extension->enabled = 1;
  439. $this->parent->extension->params = $this->parent->getParams();
  440. if ($this->parent->extension->store()) {
  441. return $this->parent->extension->get('extension_id');
  442. }
  443. else
  444. {
  445. JError::raiseWarning(101, JText::_('Module').' '.JText::_('Discover Install').': '.JText::_('Failed to store extension details'));
  446. return false;
  447. }
  448. }
  449. function refreshManifestCache()
  450. {
  451. $client = JApplicationHelper::getClientInfo($this->parent->extension->client_id);
  452. $manifestPath = $client->path . DS . 'modules'. DS . $this->parent->extension->element . DS . $this->parent->extension->element . '.xml';
  453. $this->parent->manifest = $this->parent->isManifest($manifestPath);
  454. $this->parent->setPath('manifest', $manifestPath);
  455. $manifest_details = JApplicationHelper::parseXMLInstallFile($this->parent->getPath('manifest'));
  456. $this->parent->extension->manifest_cache = serialize($manifest_details);
  457. $this->parent->extension->name = $manifest_details['name'];
  458. if ($this->parent->extension->store()) {
  459. return true;
  460. }
  461. else
  462. {
  463. JError::raiseWarning(101, JText::_('Module').' '.JText::_('Refresh Manifest Cache').': '.JText::_('Failed to store extension details'));
  464. return false;
  465. }
  466. }
  467. /**
  468. * Custom uninstall method
  469. *
  470. * @access public
  471. * @param int $id The id of the module to uninstall
  472. * @return boolean True on success
  473. * @since 1.5
  474. */
  475. public function uninstall($id)
  476. {
  477. // Initialise variables.
  478. $row = null;
  479. $retval = true;
  480. $db = &$this->parent->getDbo();
  481. // First order of business will be to load the module object table from the database.
  482. // This should give us the necessary information to proceed.
  483. $row = & JTable::getInstance('extension');
  484. if (!$row->load((int) $id) || !strlen($row->element))
  485. {
  486. JError::raiseWarning(100, JText::_('ERRORUNKOWNEXTENSION'));
  487. return false;
  488. }
  489. // Is the module we are trying to uninstall a core one?
  490. // Because that is not a good idea...
  491. if ($row->protected)
  492. {
  493. JError::raiseWarning(100, JText::_('Module').' '.JText::_('Uninstall').': '.JText::sprintf('WARNCOREMODULE', $row->name)."<br />".JText::_('WARNCOREMODULE2'));
  494. return false;
  495. }
  496. // Get the extension root path
  497. jimport('joomla.application.helper');
  498. $element = $row->element;
  499. $client = &JApplicationHelper::getClientInfo($row->client_id);
  500. if ($client === false)
  501. {
  502. $this->parent->abort(JText::_('Module').' '.JText::_('Uninstall').': '.JText::_('Unknown client type').' ['.$row->client_id.']');
  503. return false;
  504. }
  505. $this->parent->setPath('extension_root', $client->path.DS.'modules'.DS.$element);
  506. $this->parent->setPath('source', $this->parent->getPath('extension_root'));
  507. // Get the package manifest objecct
  508. $this->manifest = $this->parent->getManifest();
  509. // If there is an manifest class file, lets load it
  510. $this->scriptElement = $this->manifest->scriptfile;
  511. $manifestScript = (string)$this->manifest->scriptfile;
  512. if ($manifestScript)
  513. {
  514. $manifestScriptFile = $this->parent->getPath('extension_root').DS.$manifestScript;
  515. if (is_file($manifestScriptFile))
  516. {
  517. // load the file
  518. include_once $manifestScriptFile;
  519. }
  520. // Set the class name
  521. $classname = $element.'InstallerScript';
  522. if (class_exists($classname))
  523. {
  524. // create a new instance
  525. $this->parent->manifestClass = new $classname($this);
  526. // and set this so we can copy it later
  527. $this->set('manifest_script', $manifestScript);
  528. // Note: if we don't find the class, don't bother to copy the file
  529. }
  530. }
  531. ob_start();
  532. ob_implicit_flush(false);
  533. // run uninstall if possible
  534. if ($this->parent->manifestClass && method_exists($this->parent->manifestClass,'uninstall')) {
  535. $this->parent->manifestClass->uninstall($this);
  536. }
  537. $msg = ob_get_contents();
  538. ob_end_clean();
  539. if (!$this->manifest INSTANCEOF JXMLElement)
  540. {
  541. // Make sure we delete the folders
  542. JFolder::delete($this->parent->getPath('extension_root'));
  543. JError::raiseWarning(100, 'Module Uninstall: Package manifest file invalid or not found');
  544. return false;
  545. }
  546. /*
  547. * Let's run the uninstall queries for the component
  548. * If Joomla 1.5 compatible, with discreet sql files - execute appropriate
  549. * file for utf-8 support or non-utf support
  550. */
  551. // try for Joomla 1.5 type queries
  552. // second argument is the utf compatible version attribute
  553. $utfresult = $this->parent->parseSQLFiles($this->manifest->uninstall->sql);
  554. if ($utfresult === false)
  555. {
  556. // Install failed, rollback changes
  557. JError::raiseWarning(100, JText::_('Module').' '.JText::_('Uninstall').': '.JText::_('SQLERRORORFILE')." ".$db->stderr(true));
  558. $retval = false;
  559. }
  560. // Remove other files
  561. $this->parent->removeFiles($this->manifest->media);
  562. $this->parent->removeFiles($this->manifest->languages, $row->client_id);
  563. // Lets delete all the module copies for the type we are uninstalling
  564. $query = 'SELECT `id`' .
  565. ' FROM `#__modules`' .
  566. ' WHERE module = '.$db->Quote($row->element) .
  567. ' AND client_id = '.(int)$row->client_id;
  568. $db->setQuery($query);
  569. try {
  570. $modules = $db->loadResultArray();
  571. }
  572. catch(JException $e) {
  573. $modules = array();
  574. }
  575. // Do we have any module copies?
  576. if (count($modules))
  577. {
  578. // Ensure the list is sane
  579. JArrayHelper::toInteger($modules);
  580. $modID = implode(',', $modules);
  581. // Wipe out any items assigned to menus
  582. $query = 'DELETE' .
  583. ' FROM #__modules_menu' .
  584. ' WHERE moduleid IN ('.$modID.')';
  585. $db->setQuery($query);
  586. try {
  587. $db->query();
  588. }
  589. catch(JException $e)
  590. {
  591. JError::raiseWarning(100, JText::_('Module').' '.JText::_('Uninstall').': '.$db->stderr(true));
  592. $retval = false;
  593. }
  594. // Wipe out any instances in the modules table
  595. $query = 'DELETE' .
  596. ' FROM #__modules' .
  597. ' WHERE id IN ('.$modID.')';
  598. $db->setQuery($query);
  599. try {
  600. $db->query();
  601. }
  602. catch (JException $e)
  603. {
  604. JError::raiseWarning(100, JText::_('Module').' '.JText::_('Uninstall').': '.$db->stderr(true));
  605. $retval = false;
  606. }
  607. }
  608. // Now we will no longer need the module object, so lets delete it and free up memory
  609. $row->delete($row->extension_id);
  610. $query = 'DELETE FROM `#__modules` WHERE module = '.$db->Quote($row->element) . ' AND client_id = ' . $row->client_id;
  611. $db->setQuery($query);
  612. try {
  613. $db->Query(); // clean up any other ones that might exist as well
  614. }
  615. catch(JException $e) {
  616. //Ignore the error...
  617. }
  618. unset ($row);
  619. // Remove the installation folder
  620. if (!JFolder::delete($this->parent->getPath('extension_root')))
  621. {
  622. // JFolder should raise an error
  623. $retval = false;
  624. }
  625. return $retval;
  626. }
  627. /**
  628. * Custom rollback method
  629. * - Roll back the menu item
  630. *
  631. * @access public
  632. * @param array $arg Installation step to rollback
  633. * @return boolean True on success
  634. * @since 1.5
  635. */
  636. protected function _rollback_menu($arg)
  637. {
  638. // Get database connector object
  639. $db = &$this->parent->getDbo();
  640. // Remove the entry from the #__modules_menu table
  641. $query = 'DELETE' .
  642. ' FROM `#__modules_menu`' .
  643. ' WHERE moduleid='.(int)$arg['id'];
  644. $db->setQuery($query);
  645. try {
  646. return $db->query();
  647. }
  648. catch(JException $e) {
  649. return false;
  650. }
  651. }
  652. /**
  653. * Custom rollback method
  654. * - Roll back the module item
  655. *
  656. * @access public
  657. * @param array $arg Installation step to rollback
  658. * @return boolean True on success
  659. * @since 1.5
  660. */
  661. protected function _rollback_module($arg)
  662. {
  663. // Get database connector object
  664. $db = &$this->parent->getDbo();
  665. // Remove the entry from the #__modules table
  666. $query = 'DELETE' .
  667. ' FROM `#__modules`' .
  668. ' WHERE id='.(int)$arg['id'];
  669. $db->setQuery($query);
  670. try {
  671. return $db->query();
  672. }
  673. catch(JException $e) {
  674. return false;
  675. }
  676. }
  677. }