Skip to content
This repository was archived by the owner on Aug 31, 2025. It is now read-only.

The Update package

Nicholas K. Dionysopoulos edited this page Mar 25, 2015 · 1 revision

The update model helper

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.

Clone this wiki locally