-
Notifications
You must be signed in to change notification settings - Fork 0
The Update package
Joomla! comes with an extensions updater feature. That said, its API is hard to use and leads to a lot of code repetition. Even worse, trying to use the support for commercial extensions is a pain. This is why FOF comes with the FOF30\Update\Update model class.
This class is not designed to be used on its own. You will need to create a Model in your extension extending from this class. For example:
class MyUpdates extends FOF30\Update\Update {}
As is it won't help you much. At the very least you have to tell it which component this model refers to. You can do so in your constructor. For example:
class MyUpdates extends FOF30\Update\Update
{
public function __construct($config = array())
{
$config['update_component'] = 'com_foobar';
parent::__construct($config);
}
}You can now get the updates to your component by doing
$updateInfo = $container->model('MyUpdates')->getUpdates();This will return an array with the following keys:
- hasUpdate. Boolean. True if there is an updated version available.
- version. String. The version number of the updated version available.
- infoURL. String. The optional information URL as found in the extension's update XML stream.
If you want to find out the current version of your extension you can do:
$currentVersion = $container->model('MyUpdates')->getVersion();And now you have all the update information you might need.
In order to modify the update site and/or use the Joomla! 3.2 or later support for paid extensions you need to first define a few things in your constructor:
class MyUpdates extends FOF30\Update\Update
{
public function __construct($config = array())
{
$config['update_component'] = 'com_foobar';
$config['update_sitename'] = 'Foobar updates';
$config['update_site'] = 'http://www.example.com/updates/com_foobar.xml';
$config['update_extraquery'] = 'authorisation=mySuperSecretCode';
parent::__construct($config);
}
}The parameters you are setting are:
- update_sitename. The name of the update site, as stored in Joomla!'s #__update_sites table and used... nowhere at all (typical Joomla)!
- update_site. The URL to the update XML file for this extension
- update_extraquery. Something to be appended to the download URL. The idea is that you'll be using this to authenticate your clients to your site and allow them to download your commercial extension. It's a good idea to never hardcode this parameter but read it from your component's configuration.
Then, somewhere in your component, you need to run:
$currentVersion = $container->model('MyUpdates')->refreshUpdateSite();It's a good idea to put that in your component's control panel Controller, in the onBeforeBrowse() method.
FOF (Framework on Framework) and its documentation are Copyright © 2010-2020 Nicholas K. Dionysopoulos / Akeeba Ltd.
FOF is Open Source Software, distributed under the GNU General Public License, version 2 of the license, or (at your option) any later version.
The FOF Wiki content is provided under the GNU Free Documentation License, version 1.3 of the license, or (at your option) any later version.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license can be found on the GNU site.