| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Joomla.Platform 4 * @subpackage Installer 5 * 6 * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. 7 * @license GNU General Public License version 2 or later; see LICENSE 8 */ 9 10 defined('JPATH_PLATFORM') or die; 11 12 jimport('joomla.base.adapterinstance'); 13 14 /** 15 * Module installer 16 * 17 * @package Joomla.Platform 18 * @subpackage Installer 19 * @since 11.1 20 */ 21 class JInstallerModule extends JAdapterInstance 22 { 23 /** 24 * Install function routing 25 * 26 * @var string 27 * @since 11.1 28 */ 29 protected $route = 'Install'; 30 31 /** 32 * @var 33 * @since 11.1 34 */ 35 protected $manifest = null; 36 37 /** 38 * @var 39 * @since 11.1 40 */ 41 protected $manifest_script = null; 42 43 /** 44 * Extension name 45 * 46 * @var 47 * @since 11.1 48 */ 49 protected $name = null; 50 51 /** 52 * @var 53 * @since 11.1 54 */ 55 protected $element = null; 56 57 /** 58 * @var string 59 * @since 11.1 60 */ 61 protected $scriptElement = null; 62 63 /** 64 * Custom loadLanguage method 65 * 66 * @param string $path The path where we find language files 67 * 68 * @return void 69 * 70 * @since 11.1 71 */ 72 public function loadLanguage($path = null) 73 { 74 $source = $this->parent->getPath('source'); 75 76 if (!$source) 77 { 78 $this->parent 79 ->setPath( 80 'source', 81 ($this->parent->extension->client_id ? JPATH_ADMINISTRATOR : JPATH_SITE) . '/modules/' . $this->parent->extension->element 82 ); 83 } 84 85 $this->manifest = $this->parent->getManifest(); 86 87 if ($this->manifest->files) 88 { 89 $element = $this->manifest->files; 90 $extension = ''; 91 92 if (count($element->children())) 93 { 94 foreach ($element->children() as $file) 95 { 96 if ((string) $file->attributes()->module) 97 { 98 $extension = strtolower((string) $file->attributes()->module); 99 break; 100 } 101 } 102 } 103 104 if ($extension) 105 { 106 $lang = JFactory::getLanguage(); 107 $source = $path ? $path : ($this->parent->extension->client_id ? JPATH_ADMINISTRATOR : JPATH_SITE) . '/modules/' . $extension; 108 $folder = (string) $element->attributes()->folder; 109 110 if ($folder && file_exists("$path/$folder")) 111 { 112 $source = "$path/$folder"; 113 } 114 115 $client = (string) $this->manifest->attributes()->client; 116 $lang->load($extension . '.sys', $source, null, false, false) 117 || $lang->load($extension . '.sys', constant('JPATH_' . strtoupper($client)), null, false, false) 118 || $lang->load($extension . '.sys', $source, $lang->getDefault(), false, false) 119 || $lang->load($extension . '.sys', constant('JPATH_' . strtoupper($client)), $lang->getDefault(), false, false); 120 } 121 } 122 } 123 124 /** 125 * Custom install method 126 * 127 * @return boolean True on success 128 * 129 * @since 11.1 130 */ 131 public function install() 132 { 133 // Get a database connector object 134 $db = $this->parent->getDbo(); 135 136 // Get the extension manifest object 137 $this->manifest = $this->parent->getManifest(); 138 139 // Manifest Document Setup Section 140 141 // Set the extensions name 142 $name = (string) $this->manifest->name; 143 $name = JFilterInput::getInstance()->clean($name, 'string'); 144 $this->set('name', $name); 145 146 // Get the component description 147 $description = (string) $this->manifest->description; 148 if ($description) 149 { 150 $this->parent->set('message', JText::_($description)); 151 } 152 else 153 { 154 $this->parent->set('message', ''); 155 } 156 157 // Target Application Section 158 // Get the target application 159 if ($cname = (string) $this->manifest->attributes()->client) 160 { 161 // Attempt to map the client to a base path 162 $client = JApplicationHelper::getClientInfo($cname, true); 163 164 if ($client === false) 165 { 166 $this->parent 167 ->abort(JText::sprintf('JLIB_INSTALLER_ABORT_MOD_UNKNOWN_CLIENT', JText::_('JLIB_INSTALLER_' . $this->route), $client->name)); 168 return false; 169 } 170 171 $basePath = $client->path; 172 $clientId = $client->id; 173 } 174 else 175 { 176 // No client attribute was found so we assume the site as the client 177 $cname = 'site'; 178 $basePath = JPATH_SITE; 179 $clientId = 0; 180 } 181 182 // Set the installation path 183 $element = ''; 184 if (count($this->manifest->files->children())) 185 { 186 foreach ($this->manifest->files->children() as $file) 187 { 188 if ((string) $file->attributes()->module) 189 { 190 $element = (string) $file->attributes()->module; 191 $this->set('element', $element); 192 193 break; 194 } 195 } 196 } 197 if (!empty($element)) 198 { 199 $this->parent->setPath('extension_root', $basePath . '/modules/' . $element); 200 } 201 else 202 { 203 $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_MOD_INSTALL_NOFILE', JText::_('JLIB_INSTALLER_' . $this->route))); 204 205 return false; 206 } 207 208 // Check to see if a module by the same name is already installed 209 // If it is, then update the table because if the files aren't there 210 // we can assume that it was (badly) uninstalled 211 // If it isn't, add an entry to extensions 212 $query = $db->getQuery(true); 213 $query->select($query->qn('extension_id'))->from($query->qn('#__extensions')); 214 $query->where($query->qn('element') . ' = ' . $query->q($element))->where($query->qn('client_id') . ' = ' . (int) $clientId); 215 $db->setQuery($query); 216 217 try 218 { 219 $db->Query(); 220 } 221 catch (JException $e) 222 { 223 // Install failed, roll back changes 224 $this->parent 225 ->abort(JText::sprintf('JLIB_INSTALLER_ABORT_MOD_ROLLBACK', JText::_('JLIB_INSTALLER_' . $this->route), $db->stderr(true))); 226 227 return false; 228 } 229 230 $id = $db->loadResult(); 231 232 // If the module directory already exists, then we will assume that the 233 // module is already installed or another module is using that 234 // directory. 235 // Check that this is either an issue where its not overwriting or it is 236 // set to upgrade anyway 237 238 if (file_exists($this->parent->getPath('extension_root')) && (!$this->parent->getOverwrite() || $this->parent->getUpgrade())) 239 { 240 // Look for an update function or update tag 241 $updateElement = $this->manifest->update; 242 // Upgrade manually set or 243 // Update function available or 244 // Update tag detected 245 if ($this->parent->getUpgrade() || ($this->parent->manifestClass && method_exists($this->parent->manifestClass, 'update')) 246 || $updateElement) 247 { 248 // Force this one 249 $this->parent->setOverwrite(true); 250 $this->parent->setUpgrade(true); 251 252 if ($id) 253 { 254 // If there is a matching extension mark this as an update; semantics really 255 $this->route = 'Update'; 256 } 257 } 258 elseif (!$this->parent->getOverwrite()) 259 { 260 // Overwrite is set 261 // We didn't have overwrite set, find an update function or find an update tag so lets call it safe 262 $this->parent 263 ->abort( 264 JText::sprintf( 265 'JLIB_INSTALLER_ABORT_MOD_INSTALL_DIRECTORY', JText::_('JLIB_INSTALLER_' . $this->route), 266 $this->parent->getPath('extension_root') 267 ) 268 ); 269 270 return false; 271 } 272 } 273 274 // Installer Trigger Loading 275 276 // If there is an manifest class file, let's load it; we'll copy it later (don't have destination yet) 277 $this->scriptElement = $this->manifest->scriptfile; 278 $manifestScript = (string) $this->manifest->scriptfile; 279 280 if ($manifestScript) 281 { 282 $manifestScriptFile = $this->parent->getPath('source') . '/' . $manifestScript; 283 284 if (is_file($manifestScriptFile)) 285 { 286 // Load the file 287 include_once $manifestScriptFile; 288 } 289 290 // Set the class name 291 $classname = $element . 'InstallerScript'; 292 293 if (class_exists($classname)) 294 { 295 // Create a new instance. 296 $this->parent->manifestClass = new $classname($this); 297 // And set this so we can copy it later. 298 $this->set('manifest_script', $manifestScript); 299 300 // Note: if we don't find the class, don't bother to copy the file. 301 } 302 } 303 304 // Run preflight if possible (since we know we're not an update) 305 ob_start(); 306 ob_implicit_flush(false); 307 308 if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, 'preflight')) 309 { 310 if ($this->parent->manifestClass->preflight($this->route, $this) === false) 311 { 312 // Install failed, rollback changes 313 $this->parent->abort(JText::_('JLIB_INSTALLER_ABORT_MOD_INSTALL_CUSTOM_INSTALL_FAILURE')); 314 315 return false; 316 } 317 } 318 319 // Create msg object; first use here 320 $msg = ob_get_contents(); 321 ob_end_clean(); 322 323 // Filesystem Processing Section 324 325 // If the module directory does not exist, lets create it 326 $created = false; 327 328 if (!file_exists($this->parent->getPath('extension_root'))) 329 { 330 if (!$created = JFolder::create($this->parent->getPath('extension_root'))) 331 { 332 $this->parent 333 ->abort( 334 JText::sprintf( 335 'JLIB_INSTALLER_ABORT_MOD_INSTALL_CREATE_DIRECTORY', JText::_('JLIB_INSTALLER_' . $this->route), 336 $this->parent->getPath('extension_root') 337 ) 338 ); 339 340 return false; 341 } 342 } 343 344 // Since we created the module directory and will want to remove it if 345 // we have to roll back the installation, let's add it to the 346 // installation step stack 347 348 if ($created) 349 { 350 $this->parent->pushStep(array('type' => 'folder', 'path' => $this->parent->getPath('extension_root'))); 351 } 352 353 // Copy all necessary files 354 if ($this->parent->parseFiles($this->manifest->files, -1) === false) 355 { 356 // Install failed, roll back changes 357 $this->parent->abort(); 358 359 return false; 360 } 361 362 // If there is a manifest script, let's copy it. 363 if ($this->get('manifest_script')) 364 { 365 $path['src'] = $this->parent->getPath('source') . '/' . $this->get('manifest_script'); 366 $path['dest'] = $this->parent->getPath('extension_root') . '/' . $this->get('manifest_script'); 367 368 if (!file_exists($path['dest']) || $this->parent->getOverwrite()) 369 { 370 if (!$this->parent->copyFiles(array($path))) 371 { 372 // Install failed, rollback changes 373 $this->parent->abort(JText::_('JLIB_INSTALLER_ABORT_MOD_INSTALL_MANIFEST')); 374 375 return false; 376 } 377 } 378 } 379 380 // Parse optional tags 381 $this->parent->parseMedia($this->manifest->media, $clientId); 382 $this->parent->parseLanguages($this->manifest->languages, $clientId); 383 384 // Parse deprecated tags 385 $this->parent->parseFiles($this->manifest->images, -1); 386 387 // Database Processing Section 388 389 $row = JTable::getInstance('extension'); 390 391 // Was there a module already installed with the same name? 392 if ($id) 393 { 394 // Load the entry and update the manifest_cache 395 $row->load($id); 396 $row->name = $this->get('name'); // update name 397 $row->manifest_cache = $this->parent->generateManifestCache(); // update manifest 398 399 if (!$row->store()) 400 { 401 // Install failed, roll back changes 402 $this->parent 403 ->abort(JText::sprintf('JLIB_INSTALLER_ABORT_MOD_ROLLBACK', JText::_('JLIB_INSTALLER_' . $this->route), $db->stderr(true))); 404 405 return false; 406 } 407 } 408 else 409 { 410 $row->set('name', $this->get('name')); 411 $row->set('type', 'module'); 412 $row->set('element', $this->get('element')); 413 $row->set('folder', ''); // There is no folder for modules 414 $row->set('enabled', 1); 415 $row->set('protected', 0); 416 $row->set('access', $clientId == 1 ? 2 : 0); 417 $row->set('client_id', $clientId); 418 $row->set('params', $this->parent->getParams()); 419 $row->set('custom_data', ''); // custom data 420 $row->set('manifest_cache', $this->parent->generateManifestCache()); 421 422 if (!$row->store()) 423 { 424 // Install failed, roll back changes 425 $this->parent 426 ->abort(JText::sprintf('JLIB_INSTALLER_ABORT_MOD_ROLLBACK', JText::_('JLIB_INSTALLER_' . $this->route), $db->stderr(true))); 427 return false; 428 } 429 430 // Set the insert id 431 $row->extension_id = $db->insertid(); 432 433 // Since we have created a module item, we add it to the installation step stack 434 // so that if we have to rollback the changes we can undo it. 435 $this->parent->pushStep(array('type' => 'extension', 'extension_id' => $row->extension_id)); 436 437 // Create unpublished module in jos_modules 438 $name = preg_replace('#[\*?]#', '', JText::_($this->get('name'))); 439 $module = JTable::getInstance('module'); 440 $module->set('title', $name); 441 $module->set('module', $this->get('element')); 442 $module->set('access', '1'); 443 $module->set('showtitle', '1'); 444 $module->set('client_id', $clientId); 445 $module->set('language', '*'); 446 447 $module->store(); 448 } 449 450 // Let's run the queries for the module 451 // If Joomla 1.5 compatible, with discrete sql files, execute appropriate 452 // file for utf-8 support or non-utf-8 support 453 454 // Try for Joomla 1.5 type queries 455 // Second argument is the utf compatible version attribute 456 if (strtolower($this->route) == 'install') 457 { 458 $utfresult = $this->parent->parseSQLFiles($this->manifest->install->sql); 459 460 if ($utfresult === false) 461 { 462 // Install failed, rollback changes 463 $this->parent 464 ->abort( 465 JText::sprintf('JLIB_INSTALLER_ABORT_MOD_INSTALL_SQL_ERROR', JText::_('JLIB_INSTALLER_' . $this->route), $db->stderr(true)) 466 ); 467 468 return false; 469 } 470 471 // Set the schema version to be the latest update version 472 if ($this->manifest->update) 473 { 474 $this->parent->setSchemaVersion($this->manifest->update->schemas, $row->extension_id); 475 } 476 } 477 elseif (strtolower($this->route) == 'update') 478 { 479 if ($this->manifest->update) 480 { 481 $result = $this->parent->parseSchemaUpdates($this->manifest->update->schemas, $row->extension_id); 482 if ($result === false) 483 { 484 // Install failed, rollback changes 485 $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_MOD_UPDATE_SQL_ERROR', $db->stderr(true))); 486 return false; 487 } 488 } 489 } 490 491 // Start Joomla! 1.6 492 ob_start(); 493 ob_implicit_flush(false); 494 495 if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, $this->route)) 496 { 497 if ($this->parent->manifestClass->{$this->route}($this) === false) 498 { 499 // Install failed, rollback changes 500 $this->parent->abort(JText::_('JLIB_INSTALLER_ABORT_MOD_INSTALL_CUSTOM_INSTALL_FAILURE')); 501 502 return false; 503 } 504 } 505 506 // Append messages 507 $msg .= ob_get_contents(); 508 ob_end_clean(); 509 510 // Finalization and Cleanup Section 511 512 // Lastly, we will copy the manifest file to its appropriate place. 513 if (!$this->parent->copyManifest(-1)) 514 { 515 // Install failed, rollback changes 516 $this->parent->abort(JText::_('JLIB_INSTALLER_ABORT_MOD_INSTALL_COPY_SETUP')); 517 518 return false; 519 } 520 521 // And now we run the postflight 522 ob_start(); 523 ob_implicit_flush(false); 524 525 if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, 'postflight')) 526 { 527 $this->parent->manifestClass->postflight($this->route, $this); 528 } 529 530 // Append messages 531 $msg .= ob_get_contents(); 532 ob_end_clean(); 533 534 if ($msg != '') 535 { 536 $this->parent->set('extension_message', $msg); 537 } 538 539 return $row->get('extension_id'); 540 } 541 542 /** 543 * Custom update method 544 * 545 * This is really a shell for the install system 546 * 547 * @return boolean True on success. 548 * 549 * @since 11.1 550 */ 551 public function update() 552 { 553 // Set the overwrite setting 554 $this->parent->setOverwrite(true); 555 $this->parent->setUpgrade(true); 556 // Set the route for the install 557 $this->route = 'Update'; 558 559 // Go to install which handles updates properly 560 return $this->install(); 561 } 562 563 /** 564 * Custom discover method 565 * 566 * @return array JExtension list of extensions available 567 * 568 * @since 11.1 569 */ 570 public function discover() 571 { 572 $results = array(); 573 $site_list = JFolder::folders(JPATH_SITE . '/modules'); 574 $admin_list = JFolder::folders(JPATH_ADMINISTRATOR . '/modules'); 575 $site_info = JApplicationHelper::getClientInfo('site', true); 576 $admin_info = JApplicationHelper::getClientInfo('administrator', true); 577 578 foreach ($site_list as $module) 579 { 580 $manifest_details = JApplicationHelper::parseXMLInstallFile(JPATH_SITE . "/modules/$module/$module.xml"); 581 $extension = JTable::getInstance('extension'); 582 $extension->set('type', 'module'); 583 $extension->set('client_id', $site_info->id); 584 $extension->set('element', $module); 585 $extension->set('name', $module); 586 $extension->set('state', -1); 587 $extension->set('manifest_cache', json_encode($manifest_details)); 588 $results[] = clone $extension; 589 } 590 591 foreach ($admin_list as $module) 592 { 593 $manifest_details = JApplicationHelper::parseXMLInstallFile(JPATH_ADMINISTRATOR . "/modules/$module/$module.xml"); 594 $extension = JTable::getInstance('extension'); 595 $extension->set('type', 'module'); 596 $extension->set('client_id', $admin_info->id); 597 $extension->set('element', $module); 598 $extension->set('name', $module); 599 $extension->set('state', -1); 600 $extension->set('manifest_cache', json_encode($manifest_details)); 601 $results[] = clone $extension; 602 } 603 604 return $results; 605 } 606 607 /** 608 * Custom discover_install method 609 * 610 * @return mixed Extension ID on success, boolean false on failure 611 * 612 * @since 11.1 613 */ 614 public function discover_install() 615 { 616 // Modules are like templates, and are one of the easiest 617 // If its not in the extensions table we just add it 618 $client = JApplicationHelper::getClientInfo($this->parent->extension->client_id); 619 $manifestPath = $client->path . '/modules/' . $this->parent->extension->element . '/' . $this->parent->extension->element . '.xml'; 620 $this->parent->manifest = $this->parent->isManifest($manifestPath); 621 $description = (string) $this->parent->manifest->description; 622 623 if ($description) 624 { 625 $this->parent->set('message', JText::_($description)); 626 } 627 else 628 { 629 $this->parent->set('message', ''); 630 } 631 632 $this->parent->setPath('manifest', $manifestPath); 633 $manifest_details = JApplicationHelper::parseXMLInstallFile($this->parent->getPath('manifest')); 634 // TODO: Re-evaluate this; should we run installation triggers? postflight perhaps? 635 $this->parent->extension->manifest_cache = json_encode($manifest_details); 636 $this->parent->extension->state = 0; 637 $this->parent->extension->name = $manifest_details['name']; 638 $this->parent->extension->enabled = 1; 639 $this->parent->extension->params = $this->parent->getParams(); 640 if ($this->parent->extension->store()) 641 { 642 return $this->parent->extension->get('extension_id'); 643 } 644 else 645 { 646 JError::raiseWarning(101, JText::_('JLIB_INSTALLER_ERROR_MOD_DISCOVER_STORE_DETAILS')); 647 648 return false; 649 } 650 } 651 652 /** 653 * Refreshes the extension table cache 654 * 655 * @return boolean Result of operation, true if updated, false on failure. 656 * 657 * @since 11.1 658 */ 659 public function refreshManifestCache() 660 { 661 $client = JApplicationHelper::getClientInfo($this->parent->extension->client_id); 662 $manifestPath = $client->path . '/modules/' . $this->parent->extension->element . '/' . $this->parent->extension->element . '.xml'; 663 $this->parent->manifest = $this->parent->isManifest($manifestPath); 664 $this->parent->setPath('manifest', $manifestPath); 665 $manifest_details = JApplicationHelper::parseXMLInstallFile($this->parent->getPath('manifest')); 666 $this->parent->extension->manifest_cache = json_encode($manifest_details); 667 $this->parent->extension->name = $manifest_details['name']; 668 669 if ($this->parent->extension->store()) 670 { 671 return true; 672 } 673 else 674 { 675 JError::raiseWarning(101, JText::_('JLIB_INSTALLER_ERROR_MOD_REFRESH_MANIFEST_CACHE')); 676 677 return false; 678 } 679 } 680 681 /** 682 * Custom uninstall method 683 * 684 * @param integer $id The id of the module to uninstall 685 * 686 * @return boolean True on success 687 * 688 * @since 11.1 689 */ 690 public function uninstall($id) 691 { 692 // Initialise variables. 693 $row = null; 694 $retval = true; 695 $db = $this->parent->getDbo(); 696 697 // First order of business will be to load the module object table from the database. 698 // This should give us the necessary information to proceed. 699 $row = JTable::getInstance('extension'); 700 701 if (!$row->load((int) $id) || !strlen($row->element)) 702 { 703 JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_MOD_UNINSTALL_ERRORUNKOWNEXTENSION')); 704 return false; 705 } 706 707 // Is the module we are trying to uninstall a core one? 708 // Because that is not a good idea... 709 if ($row->protected) 710 { 711 JError::raiseWarning(100, JText::sprintf('JLIB_INSTALLER_ERROR_MOD_UNINSTALL_WARNCOREMODULE', $row->name)); 712 return false; 713 } 714 715 // Get the extension root path 716 $element = $row->element; 717 $client = JApplicationHelper::getClientInfo($row->client_id); 718 719 if ($client === false) 720 { 721 $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ERROR_MOD_UNINSTALL_UNKNOWN_CLIENT', $row->client_id)); 722 return false; 723 } 724 $this->parent->setPath('extension_root', $client->path . '/modules/' . $element); 725 726 $this->parent->setPath('source', $this->parent->getPath('extension_root')); 727 728 // Get the package manifest objecct 729 // We do findManifest to avoid problem when uninstalling a list of extensions: getManifest cache its manifest file. 730 $this->parent->findManifest(); 731 $this->manifest = $this->parent->getManifest(); 732 733 // Attempt to load the language file; might have uninstall strings 734 $this->loadLanguage(($row->client_id ? JPATH_ADMINISTRATOR : JPATH_SITE) . '/modules/' . $element); 735 736 // If there is an manifest class file, let's load it 737 $this->scriptElement = $this->manifest->scriptfile; 738 $manifestScript = (string) $this->manifest->scriptfile; 739 740 if ($manifestScript) 741 { 742 $manifestScriptFile = $this->parent->getPath('extension_root') . '/' . $manifestScript; 743 744 if (is_file($manifestScriptFile)) 745 { 746 // Load the file 747 include_once $manifestScriptFile; 748 } 749 750 // Set the class name 751 $classname = $element . 'InstallerScript'; 752 753 if (class_exists($classname)) 754 { 755 // Create a new instance 756 $this->parent->manifestClass = new $classname($this); 757 // And set this so we can copy it later 758 $this->set('manifest_script', $manifestScript); 759 760 // Note: if we don't find the class, don't bother to copy the file 761 } 762 } 763 764 ob_start(); 765 ob_implicit_flush(false); 766 767 // Run uninstall if possible 768 if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, 'uninstall')) 769 { 770 $this->parent->manifestClass->uninstall($this); 771 } 772 773 $msg = ob_get_contents(); 774 ob_end_clean(); 775 776 if (!($this->manifest instanceof JXMLElement)) 777 { 778 // Make sure we delete the folders 779 JFolder::delete($this->parent->getPath('extension_root')); 780 JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_MOD_UNINSTALL_INVALID_NOTFOUND_MANIFEST')); 781 782 return false; 783 } 784 785 /* 786 * Let's run the uninstall queries for the component 787 * If Joomla 1.5 compatible, with discreet sql files - execute appropriate 788 * file for utf-8 support or non-utf support 789 */ 790 // Try for Joomla 1.5 type queries 791 // Second argument is the utf compatible version attribute 792 $utfresult = $this->parent->parseSQLFiles($this->manifest->uninstall->sql); 793 794 if ($utfresult === false) 795 { 796 // Install failed, rollback changes 797 JError::raiseWarning(100, JText::sprintf('JLIB_INSTALLER_ERROR_MOD_UNINSTALL_SQL_ERROR', $db->stderr(true))); 798 $retval = false; 799 } 800 801 // Remove the schema version 802 $query = $db->getQuery(true); 803 $query->delete()->from('#__schemas')->where('extension_id = ' . $row->extension_id); 804 $db->setQuery($query); 805 $db->Query(); 806 807 // Remove other files 808 $this->parent->removeFiles($this->manifest->media); 809 $this->parent->removeFiles($this->manifest->languages, $row->client_id); 810 811 // Let's delete all the module copies for the type we are uninstalling 812 $query = $db->getQuery(true); 813 $query->select($query->qn('id'))->from($query->qn('#__modules')); 814 $query->where($query->qn('module') . ' = ' . $query->q($row->element)); 815 $query->where($query->qn('client_id') . ' = ' . (int) $row->client_id); 816 $db->setQuery($query); 817 818 try 819 { 820 $modules = $db->loadColumn(); 821 } 822 catch (JException $e) 823 { 824 $modules = array(); 825 } 826 827 // Do we have any module copies? 828 if (count($modules)) 829 { 830 // Ensure the list is sane 831 JArrayHelper::toInteger($modules); 832 $modID = implode(',', $modules); 833 834 // Wipe out any items assigned to menus 835 $query = 'DELETE' . ' FROM #__modules_menu' . ' WHERE moduleid IN (' . $modID . ')'; 836 $db->setQuery($query); 837 try 838 { 839 $db->query(); 840 } 841 catch (JException $e) 842 { 843 JError::raiseWarning(100, JText::sprintf('JLIB_INSTALLER_ERROR_MOD_UNINSTALL_EXCEPTION', $db->stderr(true))); 844 $retval = false; 845 } 846 847 // Wipe out any instances in the modules table 848 $query = 'DELETE' . ' FROM #__modules' . ' WHERE id IN (' . $modID . ')'; 849 $db->setQuery($query); 850 851 try 852 { 853 $db->query(); 854 } 855 catch (JException $e) 856 { 857 JError::raiseWarning(100, JText::sprintf('JLIB_INSTALLER_ERROR_MOD_UNINSTALL_EXCEPTION', $db->stderr(true))); 858 $retval = false; 859 } 860 } 861 862 // Now we will no longer need the module object, so let's delete it and free up memory 863 $row->delete($row->extension_id); 864 $query = 'DELETE FROM #__modules WHERE module = ' . $db->Quote($row->element) . ' AND client_id = ' . $row->client_id; 865 $db->setQuery($query); 866 867 try 868 { 869 // Clean up any other ones that might exist as well 870 $db->Query(); 871 } 872 catch (JException $e) 873 { 874 // Ignore the error... 875 } 876 877 unset($row); 878 879 // Remove the installation folder 880 if (!JFolder::delete($this->parent->getPath('extension_root'))) 881 { 882 // JFolder should raise an error 883 $retval = false; 884 } 885 886 return $retval; 887 } 888 889 /** 890 * Custom rollback method 891 * - Roll back the menu item 892 * 893 * @param array $arg Installation step to rollback 894 * 895 * @return boolean True on success 896 * 897 * @since 11.1 898 */ 899 protected function _rollback_menu($arg) 900 { 901 // Get database connector object 902 $db = $this->parent->getDbo(); 903 904 // Remove the entry from the #__modules_menu table 905 $query = 'DELETE' . ' FROM #__modules_menu' . ' WHERE moduleid=' . (int) $arg['id']; 906 $db->setQuery($query); 907 908 try 909 { 910 return $db->query(); 911 } 912 catch (JException $e) 913 { 914 return false; 915 } 916 } 917 918 /** 919 * Custom rollback method 920 * - Roll back the module item 921 * 922 * @param array $arg Installation step to rollback 923 * 924 * @return boolean True on success 925 * 926 * @since 11.1 927 */ 928 protected function _rollback_module($arg) 929 { 930 // Get database connector object 931 $db = $this->parent->getDbo(); 932 933 // Remove the entry from the #__modules table 934 $query = 'DELETE' . ' FROM #__modules' . ' WHERE id=' . (int) $arg['id']; 935 $db->setQuery($query); 936 try 937 { 938 return $db->query(); 939 } 940 catch (JException $e) 941 { 942 return false; 943 } 944 } 945 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Apr 3 11:40:28 2012 | Cross-referenced by PHPXref 0.7.1 |