Pacotes

From Joomla! Documentation

Revision as of 11:04, 26 July 2022 by Gkiyoshinishimoto (talk | contribs) (Created page with "O ''pkg_helloworld.xml'' pode ter o seguinte conteúdo:")
Other languages:
Deutsch • ‎English • ‎Nederlands • ‎español • ‎français • ‎italiano • ‎português • ‎português do Brasil

Nota sobre os módulos dependentes de componentes

Às vezes, os módulos (ou plugins e assim por diante) usam os modelos e auxiliares de um componente e tal. Nessas ocasiões, seria bom poder empacotar seu módulo de forma que ele seja desinstalado quando o próprio componente for desinstalado. Isso é chamado de gerenciamento de dependências que foi desejado no Joomla, mas ainda não foi feito. Sugere-se que você siga os padrões e use um pacote conforme descrito abaixo.

O que é um pacote?

Um pacote é uma extensão usada para instalar várias extensões ao mesmo tempo. Use um pacote se você tiver, por exemplo, um componente e um módulo que dependem um do outro. Combiná-los em um pacote permitirá que o usuário instale e desinstale ambas as extensões em uma única operação. Extensões de pacote podem ser usadas com o Joomla Joomla 2.5 e suas versões posteriores.

Como crio um pacote?

Uma extensão de pacote é criada compactando todos os arquivos .zip das extensões junto com um arquivo de manifesto .xml. Por exemplo, se você tiver um pacote composto por:

  • componente helloworld
  • módulo helloworld
  • biblioteca helloworld
  • plugin de sistema helloworld
  • tema helloworld

O pacote deve ter a seguinte árvore em seu arquivo zip:

 -- pkg_helloworld.xml
 -- packages <dir>
     |-- com_helloworld.zip
     |-- mod_helloworld.zip
     |-- lib_helloworld.zip
     |-- plg_sys_helloworld.zip
     |-- tpl_helloworld.zip
 -- pkg_script.php

O pkg_helloworld.xml pode ter o seguinte conteúdo:

 <?xml version="1.0" encoding="UTF-8" ?>
 <extension type="package" version="1.6" method="upgrade">
 <name>Hello World Package</name>
 <author>Hello World Package Team</author>
 <creationDate>May 2012</creationDate>
 <packagename>helloworld</packagename>
 <version>1.0.0</version>
 <url>http://www.yoururl.com/</url>
 <packager>Hello World Package Team</packager>
 <packagerurl>http://www.yoururl.com/</packagerurl>
 <description>Example package to combine multiple extensions</description>
 <update>http://www.updateurl.com/update</update>
 <scriptfile>pkg_script.php</scriptfile>
 <files folder="packages">
   <file type="component" id="com_helloworld" >com_helloworld.zip</file>
   <file type="module" id="helloworld" client="site">mod_helloworld.zip</file>
   <file type="library" id="helloworld">lib_helloworld.zip</file>
   <file type="plugin" id="helloworld" group="system">plg_sys_helloworld.zip</file>
   <file type="template" id="helloworld" client="site">tpl_helloworld.zip</file>
 </files>
 </extension>

When you zip this and install it, you will see that all extensions will be installed. The package will be visible in the extension list so that a user might uninstall all extensions contained in the package.

Remember to use the package uninstaller instead of individual subpackage uninstallers to avoid orphan extension entries in the extension manager.

Id= <file id="not_arbitrary">

The id element in <file ..> tag is not arbitrary! The id= should be set to the value of the element column in the #__extensions table. If they are not set correctly, upon uninstallation of the package, the child file will not be found and uninstalled.

Manifest Filename and Packagename

The naming of the manifest file and the ability to uninstall the package file itself are closely related. The manifest file must have a pkg_ prefix. The remainder of the manifest name (without the .xml extension) is to be used as <packagename>. Or, the other way around, a package you want to identify as blurpblurp_J3 gets that as its <packagename> and should be in a manifest file named pkg_blurpblurp_J3.xml. Failure to do so will make it impossible to uninstall the package itself.

An optional <pkg_script.php> which contains a class pkg_<packagename>InstallerScript with public function postflight can be used. (This works in Joomla! 3.6 and later).

Extension Tag

As of Joomla! 3.4, you should include method="upgrade" in the <extension> tag if you want your package to succeed in updating itself on subsequent installations.

The version attribute of the <extension> tag should be set to the minimum supported version of Joomla for this package. For example, if your package only supports Joomla! 3.2 and above, set this to 3.2.

Note: This version attribute is purely optional. It has no influence on Joomla's installation routine. As of Joomla 4, the version attribute has therefore been removed from all core extensions. See pull request 29960 on github.com

Extension Uninstall Dependency

As of Jooma! 3.7.0, a package extension can declare that its child elements cannot be uninstalled independently with a <blockChildUninstall>true</blockChildUninstall> element in the package manifest. If your package needs all its extensions to operate effectively, set this to true or 1.