API16

Difference between revisions of "JInstallerLibrary/uninstall"

From Joomla! Documentation

< API16:JInstallerLibrary
(New page: ===Description=== Custom uninstall method <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowiki>]</now...)
 
m (preparing for archive only)
 
(2 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
Custom uninstall method
 
Custom uninstall method
  
<span class="editsection" style="font-size:76%;">
 
<nowiki>[</nowiki>[[Description:JInstallerLibrary/uninstall|Edit Descripton]]<nowiki>]</nowiki>
 
</span>
 
  
{{Description:JInstallerLibrary/uninstall}}
+
 
 +
<! removed transcluded page call, red link never existed >
  
 
===Syntax===
 
===Syntax===
Line 118: Line 116:
 
</source>
 
</source>
  
<span class="editsection" style="font-size:76%;">
+
 
<nowiki>[</nowiki>[[SeeAlso:JInstallerLibrary/uninstall|Edit See Also]]<nowiki>]</nowiki>
+
<! removed transcluded page call, red link never existed >
</span>
 
{{SeeAlso:JInstallerLibrary/uninstall}}
 
  
 
===Examples===
 
===Examples===
<CodeExamplesForm />
+
=== Code Examples ===
 
<dpl>
 
<dpl>
 
  noresultsheader=\n
 
  noresultsheader=\n
 
  category=uninstall
 
  category=uninstall
 
  category=JInstallerLibrary
 
  category=JInstallerLibrary
  category=CodeExample
+
  namespace=CodeExample
 
  category=MethodExample
 
  category=MethodExample
 
  include=*
 
  include=*
 
  format= ,,,
 
  format= ,,,
 
</dpl>
 
</dpl>
 +
[[Category:Archived pages API16]]

Latest revision as of 20:50, 24 March 2017

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Custom uninstall method


<! removed transcluded page call, red link never existed >

Syntax[edit]

uninstall($id)
Parameter Name Default Value Description
$id $id The id of the library to uninstall

Returns[edit]

boolean True on success

Defined in[edit]

libraries/joomla/installer/adapters/library.php

Importing[edit]

jimport( 'joomla.installer.adapters.library' );

Source Body[edit]

function uninstall($id)
{
        // Initialise variables.
        $retval = true;

        // First order of business will be to load the module object table from the database.
        // This should give us the necessary information to proceed.
        $row = & JTable::getInstance('extension');
        if (!$row->load((int) $id) || !strlen($row->element))
        {
                JError::raiseWarning(100, JText::_('ERRORUNKOWNEXTENSION'));
                return false;
        }

        // Is the library we are trying to uninstall a core one?
        // Because that is not a good idea...
        if ($row->protected)
        {
                JError::raiseWarning(100, JText::_('Library').' '.JText::_('Uninstall').': '.JText::sprintf('WARNCOREMODULE', $row->name)."<br />".JText::_('WARNCOREMODULE2'));
                return false;
        }

        $manifestFile = JPATH_MANIFESTS.DS.'libraries' . DS . $row->element .'.xml';

        // Because libraries may not have their own folders we cannot use the standard method of finding an installation manifest
        if (file_exists($manifestFile))
        {
                $manifest = new JLibraryManifest($manifestFile);
                // Set the plugin root path
                $this->parent->setPath('extension_root', JPATH_ROOT.DS.'libraries'.DS.$manifest->libraryname);

                $xml = JFactory::getXML($manifestFile);

                // If we cannot load the xml file return null
                if ( ! $xml)
                {
                        JError::raiseWarning(100, JText::_('Library').' '.JText::_('Uninstall').': '.JText::_('Could not load manifest file'));
                        return false;
                }

                /*
                 * Check for a valid XML root tag.
                 * @todo: Remove backwards compatability in a future version
                 * Should be 'extension', but for backward compatability we will accept 'install'.
                 */
                if ($xml->getName() != 'install' && $xml->getName() != 'extension')
                {
                        JError::raiseWarning(100, JText::_('Library').' '.JText::_('Uninstall').': '.JText::_('Invalid manifest file'));
                        return false;
                }

                $this->parent->removeFiles($xml->files, -1);
                JFile::delete($manifestFile);

        }
        else
        {
                // remove this row entry since its invalid
                $row->delete($row->extension_id);
                unset($row);
                JError::raiseWarning(100, 'Library Uninstall: Manifest File invalid or not found');
                return false;
        }

        // TODO: Change this so it walked up the path backwards so we clobber multiple empties
        // If the folder is empty, let's delete it
        if (JFolder::exists($this->parent->getPath('extension_root')))
        {
                if (is_dir($this->parent->getPath('extension_root')))
                {
                        $files = JFolder::files($this->parent->getPath('extension_root'));
                        if (!count($files)) {
                                JFolder::delete($this->parent->getPath('extension_root'));
                        }
                }
        }

        $this->parent->removeFiles($xml->languages);

        $row->delete($row->extension_id);
        unset($row);

        return $retval;
}


<! removed transcluded page call, red link never existed >

Examples[edit]

Code Examples[edit]