
在实际中,扩展经常需要发布新的版本,那么如何进行管理真的是一个问题。不单单是组件,其他的扩展同样存在这样的一些问题。在这一章节中,我们将探讨如何进行扩展的更新管理。
joomla扩展更新检查
在joomla中有一个功能,就是系统可以自动检查扩展的更新状态。直接登录joomla后台,你会看到如下图:
点击之后出现下面的界面:
那么这些扩展是怎么做到的呢?
由于以前也有关注过类似的技术,大概知道应该在安装包中会有一个地方指定到什么地方去更新。因此就去了jQuery Easy这个扩展的安装目录。在他的XML文件中我发现了我需要的内容:
</config> <updateservers> <server type="extension" priority="1" name="jQuery Easy auto updater">http://www.barejoomlatemplates.com/autoupdates/jqueryeasy/jqueryeasy-update.xml</server> </updateservers> </extension>
这里有一个updateservers的字段,顾名思义就是更新服务器的地址。
这 个字段有一个子字段<server >.在server中指定type="extension" ,这个可以理解,用来指定当前更新的是扩展更新还是语言文件更新。 priority="1" 优先级这个字段,具体什么意思也不清楚。name="jQuery Easy auto updateer"这个估计可以随便写。最重要的就是URL地址了。是一个xml文件。
很清楚,为了让我们的扩展也具有自动检查更新的功能,我们需要做两件事。第一件事就是在xml文件中增加updateserves这个字段,另一件事就是在服务端包含一个xml文件。
第一件事我们已经大致了解了。下面就来看看第二件事,分析一下jqueryeasy-update.xml这个文件。直接在浏览器中访问这个URL地址,就可以看到这个文件的详细信息了。
<?xml version="1.0" encoding="utf-8"?> <updates> <update> <name>System - jQuery Easy</name> <description>jQuery Easy Plugin - Check the release history before updating to get the latest recommendations</description> <element>jqueryeasy</element> <type>plugin</type> <folder>system</folder> <client>0</client> <client_id>0</client_id> <version>1.5.5</version> <infourl title="jQueryEasy URL">http://www.simplifyyourweb.com/index.php/downloads/category/8-loading-jquery</infourl> <downloads> <downloadurl type="full" format="zip">http://www.barejoomlatemplates.com/autoupdates/jqueryeasy/v155/plg_system_jqueryeasy.zip</downloadurl> </downloads> <tags> <tag>stable</tag> </tags> <maintainer>Simplify Your Web</maintainer> <maintainerurl>http://www.simplifyyourweb.com</maintainerurl> <targetplatform name="joomla" version="1.6" /> </update> ..............................................此处有删减............................................................................. <update> <name>System - jQuery Easy</name> <description>jQuery Easy Plugin - Check the release history before updating to get the latest recommendations</description> <element>jqueryeasy</element> <type>plugin</type> <folder>system</folder> <client>0</client> <client_id>0</client_id> <version>1.5.5</version> <infourl title="jQueryEasy URL">http://www.simplifyyourweb.com/index.php/downloads/category/8-loading-jquery</infourl> <downloads> <downloadurl type="full" format="zip">http://www.barejoomlatemplates.com/autoupdates/jqueryeasy/v155/joomla3/plg_system_jqueryeasy.zip</downloadurl> </downloads> <tags> <tag>stable</tag> </tags> <maintainer>Simplify Your Web</maintainer> <maintainerurl>http://www.simplifyyourweb.com</maintainerurl> <targetplatform name="joomla" version="3.1" /> </update> <update> <name>System - jQuery Easy</name> <description>jQuery Easy Plugin - Check the release history before updating to get the latest recommendations</description> <element>jqueryeasy</element> <type>plugin</type> <folder>system</folder> <client>0</client> <client_id>0</client_id> <version>1.5.5</version> <infourl title="jQueryEasy URL">http://www.simplifyyourweb.com/index.php/downloads/category/8-loading-jquery</infourl> <downloads> <downloadurl type="full" format="zip">http://www.barejoomlatemplates.com/autoupdates/jqueryeasy/v155/joomla3/plg_system_jqueryeasy.zip</downloadurl> </downloads> <tags> <tag>stable</tag> </tags> <maintainer>Simplify Your Web</maintainer> <maintainerurl>http://www.simplifyyourweb.com</maintainerurl> <targetplatform name="joomla" version="3.2" /> </update> </updates>
代码太长了,不过大体结构还是很清楚的。
主要的几个字段还是很好理解的。重点关 注<version><downloadurl>这个两个字段,<version>指定了即将下载的版 本,<downloadurl>这里就指定了新版本的下载地址。另外一个重点就是<targetplatform>字段,这个字 段指定目标平台是什么。
最开始我还很疑惑,为什么XML文件中的内容要重复那么多次呢,仔细看看,原来他们的<targetplatform>这个字段不同。用意是指定不同的joomla版本来下载不同的文件。
总结
joomla 自动检查更新的流程大致如下:扩展在安装的时候会添加一个updateservers这个字段,这里指定了更新文件的地址。joomla会每隔一段时间去 数据库中读取所有扩种的updateservers字段,然后访问里面的更新地址。通过分析该地址的XML文件,来决定是否需要更新。
有了上面的理解,基本上现在我们能够在自己的扩展上实现自动检查更新这个功能了。下一节将实际测试一下。敬请期待
于2014-09-05日修改:在实际中,如果在#__extensions表中是并没有发现updateservers这个值。这个令我很意外。同时,在实际的使用中。必须在安装的时候在xml文件中就指定updateserver这个字段,否则系统不会自动检测。这个需要注意。
本人在一个扩展安装后,然后去修改xml文件,增加了updateservers这个字段,发现是没有作用的。
于2014-10-09日修改:joomla有一个专门的更新组件来管理更新,所以在#__extension表中是找不到updateservers的值得。但是我们可以在#__update_sites表中找到。这就是为什么在安装的时候才会有效。
评论 (0)