跳至主要内容
版本:5.1

程序包

程序包是一种特殊的 Joomla 扩展类型,用于一次安装多个扩展。 例如,如果您有一个组件和一个模块依赖于彼此,则可以使用程序包。 将它们组合成一个程序包将允许用户在一个操作中安装和卸载这两个扩展。

创建程序包

程序包扩展是通过将所有单个扩展的 .zip 文件与程序包 xml 清单文件一起压缩来创建的。 例如,如果您有一个由以下组成部分组成的程序包

  • 组件 helloworld
  • 模块 helloworld
  • 库 helloworld
  • 系统插件 helloworld
  • 模板 helloworld

那么程序包应在 pkg_helloworld 文件夹中具有以下树结构

pkg_helloworld
├─── pkg_helloworld.xml
├─── constituents
│ ├─── com_helloworld.zip
│ ├─── mod_helloworld.zip
│ ├─── lib_helloworld.zip
│ ├─── plg_sys_helloworld.zip
│ └─── tpl_helloworld.zip
└─── pkg_script.xml

pkg_helloworld.xml 清单文件可能具有以下内容

pkg_helloworld.xml
<?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>today</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>
<blockChildUninstall>true</blockChildUninstall>
<files folder="constituents">
<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>

然后,将 pkg_helloworld 文件夹压缩并以正常方式安装程序包扩展。 当您转到管理扩展时,您将看到

  • helloworld 程序包的整体条目,以及
  • 程序包中每个组成扩展的条目。

这些与 Joomla #__extensions 表中的关联行匹配。

下面列出了您必须确保正确执行的几个项目,以便程序包安装/卸载过程按预期工作。

文件命名

程序包的清单文件必须命名为 pkg_<packagename>.xml,其中 <packagename> 是您 XML 中的元素

<packagename>helloworld</packagename>

因此,在这种情况下,清单文件必须命名为 pkg_helloworld.xml

当您卸载程序包时,Joomla 会查找名为 pkg_<packagename>.xml 的清单文件,如果您没有正确命名它,那么卸载将失败,Joomla 会报告它找不到清单文件。

id 属性

在每个组成扩展的 <file> 元素中,id 属性必须与该扩展在 #__extensions 表中的记录的 element 列匹配。

(有关此 element 字段如何设置的说明,请参阅 元数据前端文件 部分)。

当您卸载程序包时,Joomla 使用清单文件中的此信息在 #__extensions 表中执行数据库查找以查找每个组成扩展。 如果您没有正确设置它,那么 Joomla 将不会卸载该组成扩展。

插件 group 属性

group 属性是程序包安装程序定位插件以进行卸载所必需的。

组指的是在插件清单文件的 <extension> 元素中指定的 group 属性,并与 Joomla /plugins 目录下的子文件夹名称匹配。

blockChildUninstall 标签

使用此标签可以阻止管理员单独卸载程序包的组成扩展。

如果您省略了此标签或有

<blockChildUninstall>false</blockChildUninstall>

那么管理员将能够卸载程序包的组成扩展,而不会影响其他扩展。

其他标签

程序包 XML 清单文件的其他标签的工作方式与其他扩展的标签类似,如 清单文件安装过程和脚本文件 中所述。