J3.x

Difference between revisions of "Developing an MVC Component/Adding an update server"

From Joomla! Documentation

< J3.x:Developing an MVC Component
m
(Several markup changes.)
 
Line 3: Line 3:
 
<!--T:9-->
 
<!--T:9-->
 
en</translate>}}
 
en</translate>}}
 
 
<translate>
 
<translate>
 
<!--T:10-->
 
<!--T:10-->
Line 10: Line 9:
 
<translate>
 
<translate>
 
<!--T:11-->
 
<!--T:11-->
In this part, we will cover the various aspects of setting up an update server for our helloworld component.</translate>
+
In this part, we will cover the various aspects of setting up an update server for our ''helloworld'' component.</translate>
  
 
<translate>
 
<translate>
Line 21: Line 20:
 
<!--T:14-->
 
<!--T:14-->
 
Updating Joomla extensions via an update server is a two step process:
 
Updating Joomla extensions via an update server is a two step process:
# finding the updates available for the installed extensions
+
# Finding the updates available for the installed extensions.
# selecting an update and installing it.
+
# Selecting an update and installing it.
Typically this is done by the administrator via the Extensions / Manage / Update page.  
+
Typically this is done by the administrator via the {{rarr|Extensions,Manage,Update}} page.
# You click on Find Updates to find the updates available
+
# You click on Find Updates to find the updates available.
 
# You mark the checkbox of each update you want to install and click on Update.
 
# You mark the checkbox of each update you want to install and click on Update.
In this step we enable our Helloworld component to be updated in this way.</translate>
+
In this step we enable our ''helloworld'' component to be updated in this way.</translate>
  
 
<translate>
 
<translate>
Line 32: Line 31:
 
<translate>
 
<translate>
 
<!--T:16-->
 
<!--T:16-->
Each Joomla extension which is updated via an update server has a URL associated with it which points to an XML file containing details of the updates available. This file could be hosted on the extension developer's own website, for example. If you go to Extensions / Manage / Update Sites you will see this URL in the Update Site column, and you can click on those URLs to see the format of the XML files. (Some of these XML files may be of type "collection" where the first XML element is <tt><extensionset></tt>, and these are described towards the end of this tutorial, but for now we're concentrating on the type "extension" where the first XML element is <tt><updates></tt>).</translate>
+
Each Joomla extension that is updated via an update server has a URL associated with it that points to an XML file containing details of the updates available. This file could be hosted on the extension developer's own website, for example. If you go to {{rarr|Extensions,Manage,Update Sites}} you will see this URL in the Update Site column, and you can click on those URLs to see the format of the XML files. (Some of these XML files may be of type ''collection'' where the first XML element is ''<extensionset>'', and these are described towards the end of this tutorial, but for now we're concentrating on the type "extension" where the first XML element is ''<updates>'').</translate>
  
 
<translate>
 
<translate>
 
<!--T:17-->
 
<!--T:17-->
The XML file (described more fully below) contains details of what updates are available for that extension, including any restrictions (eg you have to be running a certain Joomla version to be able to use it), and the URL of the zip file containing the new version of the extension.  
+
The XML file (described more fully below) contains details of what updates are available for that extension, including any restrictions (eg you have to be running a certain Joomla version to be able to use it), and the URL of the zip file containing the new version of the extension.
You tell Joomla the URL of the XML file for your extension within the manifest file (helloworld.xml), eg</translate>
+
You tell Joomla the URL of the XML file for your extension within the manifest file (''helloworld.xml''), e.g.</translate>
  
<source lang="xml">
+
<syntaxhighlight lang="xml">
 
<updateservers>
 
<updateservers>
 
<server type="extension" name="Helloworld Updates">http://myDeveloperSite/helloworld-updates/updates.xml</server>
 
<server type="extension" name="Helloworld Updates">http://myDeveloperSite/helloworld-updates/updates.xml</server>
 
</updateservers>
 
</updateservers>
</source>
+
</syntaxhighlight>
  
 
<translate>
 
<translate>
Line 49: Line 48:
 
Below is a basic update XML file </translate>
 
Below is a basic update XML file </translate>
  
<source lang="xml">
+
<syntaxhighlight lang="xml">
 
<updates>
 
<updates>
 
<update>
 
<update>
Line 65: Line 64:
 
</update>
 
</update>
 
</updates>
 
</updates>
</source>
+
</syntaxhighlight>
  
 
<translate>
 
<translate>
 
<!--T:19-->
 
<!--T:19-->
Note that it has  
+
Note that it has
 
* basic information about the component – eg name, version
 
* basic information about the component – eg name, version
 
* a link to the zip file for that update
 
* a link to the zip file for that update
Line 75: Line 74:
 
<translate>
 
<translate>
 
<!--T:20-->
 
<!--T:20-->
Whenever an administrator clicks on the Find Updates button, Joomla sends HTTP requests to each of the URLs of these update servers to retrieve the XML files. It parses each XML file,  
+
Whenever an administrator clicks on the Find Updates button, Joomla sends HTTP requests to each of the URLs of these update servers to retrieve the XML files. It parses each XML file,
 
# ensures it's properly formed XML
 
# ensures it's properly formed XML
 
# compares the version of the update with the version of the extension currently running
 
# compares the version of the update with the version of the extension currently running
Line 81: Line 80:
 
<translate>
 
<translate>
 
<!--T:21-->
 
<!--T:21-->
If it finds it's a valid update for this website, then it inserts a record into the "updates" table in the database. (You'll find at most 1 update for each extension, because if there are several possible then Joomla will store only the most recent valid version, ie with the highest version number).</translate>
+
If it finds it's a valid update for this website, it inserts a record into the ''updates'' table in the database. (You'll find at most one update for each extension, because if there are several possible then Joomla will store only the most recent valid version, i.e. with the highest version number).</translate>
  
 
<translate>
 
<translate>
Line 87: Line 86:
 
<translate>
 
<translate>
 
<!--T:23-->
 
<!--T:23-->
Once an update has been inserted into the "updates" table it is visible to the administrator in the Extension / Manage / Update page. After checking the checkbox and clicking the Update button Joomla will  
+
Once an update has been inserted into the "updates" table it is visible to the administrator in the Extension / Manage / Update page. After checking the checkbox and clicking the Update button Joomla will
 
* once again send an HTTP request to the URL of the update XML file
 
* once again send an HTTP request to the URL of the update XML file
 
* parse the XML file and ensure that conditions for installing that version are still met
 
* parse the XML file and ensure that conditions for installing that version are still met
Line 97: Line 96:
 
<translate>
 
<translate>
 
<!--T:25-->
 
<!--T:25-->
In this tutorial step we will update our helloworld extension to use an update server.</translate>
+
In this tutorial step we will update our ''helloworld'' extension to use an update server.</translate>
 
<translate>
 
<translate>
 
<!--T:26-->
 
<!--T:26-->
We'll also set up the server files so that you can verify that the update process works ok.</translate>
+
We'll also set up the server files so that you can verify that the update process works okay.</translate>
 
<translate>
 
<translate>
 
<!--T:27-->
 
<!--T:27-->
Line 106: Line 105:
 
<translate>
 
<translate>
 
<!--T:28-->
 
<!--T:28-->
For example, I have a folder <tt>/helloworld</tt> which contains my Joomla instance, so that to access the site I put the URL <tt>http://localhost/helloworld/index.php</tt> into the browser.</translate>
+
For example, I have a folder ''/helloworld'' that contains my Joomla instance, so that to access the site I put the URL ''http://localhost/helloworld/index.php'' into the browser.</translate>
 
<translate>
 
<translate>
 
<!--T:29-->
 
<!--T:29-->
For the update server I created a folder <tt>/helloworld-updates</tt> at the same level as <tt>/helloworld</tt>, and put the <tt>updates.xml</tt> file into that folder. I can then access the XML file by putting the URL <tt>http://localhost/helloworld-updates/updates.xml</tt> into the browser.</translate>
+
For the update server I created a folder ''/helloworld-updates'' at the same level as ''/helloworld'', and put the ''updates.xml'' file into that folder. I can then access the XML file by putting the URL ''http://localhost/helloworld-updates/updates.xml'' into the browser.</translate>
 
<translate>
 
<translate>
 
<!--T:30-->
 
<!--T:30-->
Line 118: Line 117:
 
<translate>
 
<translate>
 
<!--T:32-->
 
<!--T:32-->
The only change we need to make to our helloworld component is to include the update server inside the manifest file. Once updated, zip up the component as usual and install it on your Joomla instance. </translate>
+
The only change we need to make to our ''helloworld'' component is to include the update server inside the manifest file. Once updated, zip up the component as usual and install it on your Joomla instance.</translate>
  
 
<span id="helloworld.xml">
 
<span id="helloworld.xml">
<tt>helloworld.xml</tt>
+
''helloworld.xml''
<source lang="xml" highlight="13,100-103">
+
<syntaxhighlight lang="xml" highlight="13,100-103">
 
<?xml version="1.0" encoding="utf-8"?>
 
<?xml version="1.0" encoding="utf-8"?>
 
<extension type="component" version="3.0" method="upgrade">
 
<extension type="component" version="3.0" method="upgrade">
Line 227: Line 226:
 
</updateservers>
 
</updateservers>
 
</extension>
 
</extension>
</source>
+
</syntaxhighlight>
 
</span>
 
</span>
  
Line 234: Line 233:
 
<translate>
 
<translate>
 
<!--T:34-->
 
<!--T:34-->
We're going to put 3 files into the directory which we're using to act as the update server, ie into the /helloworld-updates folder, or wherever you have decided to use. The 3 files are:
+
We're going to put three files into the directory that we're using to act as the update server, i.e. into the ''/helloworld-updates'' folder, or wherever you have decided to use. The three files are:
# the updates.xml file
+
# the ''updates.xml'' file
# an html file which is an information file for the latest version
+
# an HTML file that is an information file for the latest version
# a zip file for the update.  
+
# a zip file for the update.
For security purposes you should also add the usual blank index.html file as well.</translate>
+
For security purposes you should also add the usual empty ''index.html'' file as well.</translate>
 
<translate>
 
<translate>
 
<!--T:35-->
 
<!--T:35-->
The updates.xml file is below. You should change the infourl and downloadurl to suit your environment, and set values for the targetplatform, php_minimum and supported_databases as you wish.</translate>
+
The ''updates.xml'' file is below. Change the ''infourl'' and ''downloadurl'' to suit your environment, and set values for the ''targetplatform'', ''php_minimum'' and ''supported_databases'' as you wish.</translate>
  
<source lang="xml">
+
<syntaxhighlight lang="xml">
 
<updates>
 
<updates>
 
<update>
 
<update>
Line 264: Line 263:
 
</update>
 
</update>
 
</updates>
 
</updates>
</source>
+
</syntaxhighlight>
 
<translate>
 
<translate>
 
<!--T:36-->
 
<!--T:36-->
You can find definitions of the elements of this XML structure at [[Deploying an Update Server]], but note that the attributes min_dev_level and max_dev_level are marked as deprecated in the current (3.9) Joomla code, to be removed in Joomla 4.</translate>
+
You can find definitions of the elements of this XML structure at [[Deploying an Update Server]], but note that the attributes ''min_dev_level'' and ''max_dev_level'' are marked as deprecated in the current (3.9) Joomla code, to be removed in Joomla 4.</translate>
 
<translate>
 
<translate>
 
<!--T:37-->
 
<!--T:37-->
The information file is just a basic html document, which you can modify as you wish. Its filename must match what is specified in the <tt><infourl></tt> tag above.</translate>
+
The information file is just a basic HTML document that you can modify as you wish. Its filename must match what is specified in the ''<infourl>'' tag above.</translate>
  
<source lang="html">
+
<syntaxhighlight lang="html">
 
<!DOCTYPE html>
 
<!DOCTYPE html>
 
<html>
 
<html>
Line 282: Line 281:
 
</body>
 
</body>
 
</html>
 
</html>
</source>
+
</syntaxhighlight>
  
 
<translate>
 
<translate>
 
<!--T:38-->
 
<!--T:38-->
Finally create a store a zip file for the new version. As a minimum you need to update the version in the manifest file, and you may wish to make another change which is visible when you visit the site.  
+
Finally create a store a zip file for the new version. As a minimum you need to update the version in the manifest file, and you may wish to make another change that is visible when you visit the site.
# Update the manifest file (helloworld.xml) to set the version line to <version>1.0.0</version>  
+
# Update the manifest file (''helloworld.xml'') to set the version line to ''<version>1.0.0</version>''
# Create a zip file of the helloworld component
+
# Create a zip file of the ''helloworld'' component
# Copy the zip file into your update server directory. Its name must match what is specified in the <downloadurl> tag (helloworld-1-0-0.zip above).</translate>
+
# Copy the zip file into your update server directory. Its name must match what is specified in the ''<downloadurl>'' tag (''helloworld-1-0-0.zip'' above).</translate>
  
 
<translate>
 
<translate>
Line 296: Line 295:
 
<!--T:40-->
 
<!--T:40-->
 
To test your update server do the following:
 
To test your update server do the following:
# log in to the backend of your site using an admin account
+
# Log in to the Backend of your site using an admin account.
# go to Extensions / Manage / Update  
+
# Go to {{rarr|Extensions,Manage,Update}}.
# click on Find Updates – your helloworld component should appear as an update. (It may already be shown, because when you display the admin control panel it issues an ajax request which initiates the find updates process).
+
# Click on ''Find Updates''. Your ''helloworld'' component should appear as an update. (It may already be shown, because when you display the administrator control panel it issues an AJAX request that initiates the ''find updates'' process).
# click on the checkbox next to the helloworld component, and click on Update
+
# Click on the checkbox next to the ''helloworld'' component, and click on ''Update''.
# go to Extensions / Manage / Manage and find the helloworld component. Its version should now be 1.0.0 (or whatever version you updated to).</translate>
+
# Go to {{rarr|Extensions,Manage,Manage}} and find the ''helloworld'' component. Its version should now be 1.0.0 (or whatever version you updated to).</translate>
 
<translate>
 
<translate>
 
<!--T:41-->
 
<!--T:41-->
(For info, using phpmyadmin you can change the existing version number of the helloworld component by finding the appropriate record in the extensions table, and updating the version number within the json string in the manifest_cache field.)</translate>
+
(For info, using phpMyAdmin you can change the existing version number of the ''helloworld'' component by finding the appropriate record in the extensions table, and updating the version number within the JSON string in the manifest_cache field.)</translate>
  
 
<translate>
 
<translate>
== Collections type == <!--T:42--></translate>
+
== Collections Type == <!--T:42--></translate>
 
<translate>
 
<translate>
 
<!--T:43-->
 
<!--T:43-->
Up to now we've been considering the server type="extension", but Joomla also has a server type="collection". The purpose of this type is to allow you to have a collection of different update XML files. You would use a "collection" type if, for example,  
+
Up to now we've been considering the ''server type="extension"'', but Joomla also has a ''server type="collection"''. The purpose of this type is to allow you to have a collection of different update XML files. You would use a "collection" type if, for example,
# your extension is a package and you want to allow users to update the package components individually
+
# Your extension is a package and you want to allow users to update the package components individually.
# you want to have different update XML files for different versions of Joomla.</translate>
+
# You want to have different update XML files for different versions of Joomla.</translate>
 
<translate>
 
<translate>
 
<!--T:44-->
 
<!--T:44-->
Joomla languages use a collection type. If you have several languages installed and go to Extensions / Manage / Update Sites then you can see that all the languages have the same update site URL pointing to something like https://update.joomla.org/language/translationlist_3.xml . If you open that XML file then you see all the details URLs which are the update XML files of the individual languages, and which can be installed via the Extensions / Manage / Install Languages page.</translate>
+
Joomla languages use a collection type. If you have several languages installed and go to {{rarr|Extensions,Manage,Update Sites}}, you can see that all the languages have the same update site URL pointing to something like ''https://update.joomla.org/language/translationlist_3.xml''. If you open that XML file you'll see all the details URLs that are the update XML files of the individual languages, and that can be installed via the {{rarr|Extensions,Manage,Install Languages}} page.</translate>
  
 
<translate>
 
<translate>
 
<!--T:45-->
 
<!--T:45-->
Joomla core also uses a collection type. If you go to Update Sites and click on the XML file for Joomla! Core then you will see different update XML files depending upon whether the installed version of Joomla is 2.x or 3.x.</translate>
+
Joomla core also uses a collection type. If you go to ''Update Sites'' and click on the XML file for Joomla! Core, you will see different update XML files depending upon whether the installed version of Joomla is 2.x or 3.x.</translate>
 
<translate>
 
<translate>
 
<!--T:46-->
 
<!--T:46-->
If you wish to try using a collection type, then this is still possible with a single update XML file, by following the steps below.</translate>
+
If you wish to try using a collection type, this is still possible with a single update XML file, by following the steps below.</translate>
 
<translate>
 
<translate>
 
<!--T:47-->
 
<!--T:47-->
Firstly delete manually (using phpmyadmin) the records in the database tables update_sites and update_sites_extensions which relate to the helloworld component. Then go into Extensions / Manage / Update and click on Clear Cache. This should have removed all trace of the type="extension" update mechanism.</translate>
+
First manually delete (using phpMyAdmin) the records in the database tables ''update_sites'' and ''update_sites_extensions'' that relate to the ''helloworld'' component. Then go into {{rarr|Extensions,Manage,Update}} and click on ''Clear Cache''. This should remove all traces of the ''type="extension"'' update mechanism.</translate>
 
<translate>
 
<translate>
 
<!--T:48-->
 
<!--T:48-->
Secondly replace the updateservers section of the manifest file with the following (changing the URL appropriately)</translate>
+
Second replace the ''updateservers'' section of the manifest file with the following (changing the URL appropriately)</translate>
<source lang="xml">
+
<syntaxhighlight lang="xml">
 
<updateservers>
 
<updateservers>
 
<server type="collection" name="Helloworld Updates">http://localhost/helloworld-updates/list.xml</server>
 
<server type="collection" name="Helloworld Updates">http://localhost/helloworld-updates/list.xml</server>
 
</updateservers>
 
</updateservers>
</source>
+
</syntaxhighlight>
 
<translate>
 
<translate>
 
<!--T:49-->
 
<!--T:49-->
Zip up the component and install it in the usual way. (Remember, when you install it in this way the version number in the new install file doesn't need to be greater than the version of the one currently installed).</translate>
+
Zip up the component and install it in the usual way. (Remember when you install it in this way the version number in the new install file doesn't need to be greater than the version of the one currently installed).</translate>
 
<translate>
 
<translate>
 
<!--T:50-->
 
<!--T:50-->
Thirdly create a list.xml file which points to the update XML file, and store this in your update server folder. Once again, change the URL and version to match your own situation, making sure that the version quoted in the file is greater than the one currently installed.</translate>
+
Third, create a ''list.xml'' file that points to the update XML file, and store this in your update server folder. Once again, change the URL and version to match your own situation, making sure that the version quoted in the file is greater than the one currently installed.</translate>
<source lang="xml">
+
<syntaxhighlight lang="xml">
 
<extensionset name="Helloworld Update Collection" description="Helloworld Update as Collection">
 
<extensionset name="Helloworld Update Collection" description="Helloworld Update as Collection">
 
<extension name="Helloworld Component" element="com_helloworld" type="component" client="administrator" version="1.0.0" targetplatformversion="3.[23456789]" detailsurl="http://localhost/helloworld-updates/updates.xml"/>
 
<extension name="Helloworld Component" element="com_helloworld" type="component" client="administrator" version="1.0.0" targetplatformversion="3.[23456789]" detailsurl="http://localhost/helloworld-updates/updates.xml"/>
 
</extensionset>
 
</extensionset>
</source>
+
</syntaxhighlight>
 
<translate>
 
<translate>
 
<!--T:51-->
 
<!--T:51-->
If you test the update process as above you should find it works just the same. However, note that in this case the updates.xml file is not processed during the Find Updates process, so if you have an incompatible minimum value of PHP say, then it won't report it at that stage.</translate>
+
If you test the update process as above you should find it works just the same. However, note that in this case the ''updates.xml'' file is not processed during the ''Find Updates'' process. If you have an incompatible minimum value of PHP say, it won't report it at that stage.</translate>
  
 
<translate>
 
<translate>
Line 352: Line 351:
 
*[[User:Robbiej|Robbie Jackson]]
 
*[[User:Robbiej|Robbie Jackson]]
  
<div class="row">  
+
<div class="row">
 
<div class="large-6 columns">{{Basic button|S:MyLanguage/J3.x:Developing_an_MVC_Component/Adding a Feed|<translate><!--T:54--> Prev: Adding a Feed</translate>|class=expand success}}</div>
 
<div class="large-6 columns">{{Basic button|S:MyLanguage/J3.x:Developing_an_MVC_Component/Adding a Feed|<translate><!--T:54--> Prev: Adding a Feed</translate>|class=expand success}}</div>
 
<div class="large-6 columns">{{Basic button|
 
<div class="large-6 columns">{{Basic button|

Latest revision as of 16:55, 31 October 2022

Other languages:
Deutsch • ‎English • ‎Nederlands • ‎español • ‎français • ‎العربية • ‎فارسی • ‎中文(台灣)‎
Joomla! 
3.x
Tutorial
Developing an MVC Component



This is a multiple-article series of tutorials on how to develop a Model-View-Controller Component for Joomla! VersionJoomla 3.x.

Begin with the Introduction, and navigate the articles in this series by using the navigation button at the bottom or the box to the right (the Articles in this series).



This tutorial is part of the Developing an MVC Component for Joomla! 3.2 tutorial. You are encouraged to read the previous parts of the tutorial before reading this.

In this part, we will cover the various aspects of setting up an update server for our helloworld component.

A video accompanying this step is available at Adding an Update Server.

Introduction[edit]

Updating Joomla extensions via an update server is a two step process:

  1. Finding the updates available for the installed extensions.
  2. Selecting an update and installing it.

Typically this is done by the administrator via the Extensions  Manage  Update page.

  1. You click on Find Updates to find the updates available.
  2. You mark the checkbox of each update you want to install and click on Update.

In this step we enable our helloworld component to be updated in this way.

Finding Updates[edit]

Each Joomla extension that is updated via an update server has a URL associated with it that points to an XML file containing details of the updates available. This file could be hosted on the extension developer's own website, for example. If you go to Extensions  Manage  Update Sites you will see this URL in the Update Site column, and you can click on those URLs to see the format of the XML files. (Some of these XML files may be of type collection where the first XML element is <extensionset>, and these are described towards the end of this tutorial, but for now we're concentrating on the type "extension" where the first XML element is <updates>).

The XML file (described more fully below) contains details of what updates are available for that extension, including any restrictions (eg you have to be running a certain Joomla version to be able to use it), and the URL of the zip file containing the new version of the extension. You tell Joomla the URL of the XML file for your extension within the manifest file (helloworld.xml), e.g.

<updateservers>
	<server type="extension" name="Helloworld Updates">http://myDeveloperSite/helloworld-updates/updates.xml</server>
</updateservers>

Below is a basic update XML file

<updates>
	<update>
		<name>Helloworld component</name>
		<description>Helloworld component for Joomla MVC tutorial</description>
		<element>com_helloworld</element>
		<type>component</type>
		<version>1.0.0</version>
		<client>administrator</client>
		<downloads>
			<downloadurl type="full" format="zip">http://myDeveloperSite/helloworld-updates/helloworld-1-0-0.zip</downloadurl>
		</downloads>
		<targetplatform name="joomla" version="3.[23456789]" />
		<php_minimum>7.1</php_minimum>
	</update>
</updates>

Note that it has

  • basic information about the component – eg name, version
  • a link to the zip file for that update
  • restrictions – for Joomla versions 3.2 to 3.9 only, and at least PHP version 7.1

Whenever an administrator clicks on the Find Updates button, Joomla sends HTTP requests to each of the URLs of these update servers to retrieve the XML files. It parses each XML file,

  1. ensures it's properly formed XML
  2. compares the version of the update with the version of the extension currently running
  3. checks any restrictions (Joomla versions, PHP versions, database versions) with what is currently running.

If it finds it's a valid update for this website, it inserts a record into the updates table in the database. (You'll find at most one update for each extension, because if there are several possible then Joomla will store only the most recent valid version, i.e. with the highest version number).

Installing Updates[edit]

Once an update has been inserted into the "updates" table it is visible to the administrator in the Extension / Manage / Update page. After checking the checkbox and clicking the Update button Joomla will

  • once again send an HTTP request to the URL of the update XML file
  • parse the XML file and ensure that conditions for installing that version are still met
  • send an HTTP request to the URL of the update zip file, storing the file received in the HTTP response in its /tmp directory
  • proceed to install the new version from the downloaded zip file.

Approach[edit]

In this tutorial step we will update our helloworld extension to use an update server. We'll also set up the server files so that you can verify that the update process works okay. To do this you'll need to configure part of your development area to act as the update server. This basically means creating a directory below the root directory serviced by your web server, and including the update XML file etc in it. For example, I have a folder /helloworld that contains my Joomla instance, so that to access the site I put the URL http://localhost/helloworld/index.php into the browser. For the update server I created a folder /helloworld-updates at the same level as /helloworld, and put the updates.xml file into that folder. I can then access the XML file by putting the URL http://localhost/helloworld-updates/updates.xml into the browser. You'll need to do something similar in your own environment, and verify that the URL is correct by accessing the XML file through your browser.

Updated Code[edit]

The only change we need to make to our helloworld component is to include the update server inside the manifest file. Once updated, zip up the component as usual and install it on your Joomla instance.

helloworld.xml

<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="3.0" method="upgrade">

	<name>COM_HELLOWORLD</name>
	<!-- The following elements are optional and free of formatting constraints -->
	<creationDate>January 2018</creationDate>
	<author>John Doe</author>
	<authorEmail>john.doe@example.org</authorEmail>
	<authorUrl>http://www.example.org</authorUrl>
	<copyright>Copyright Info</copyright>
	<license>License Info</license>
	<!--  The version string is recorded in the components table -->
	<version>0.0.33</version>
	<!-- The description is optional and defaults to the name -->
	<description>COM_HELLOWORLD_DESCRIPTION</description>

	<!-- Runs on install/uninstall/update; New in 2.5 -->
	<scriptfile>script.php</scriptfile>

	<install> <!-- Runs on install -->
		<sql>
			<file driver="mysql" charset="utf8">sql/install.mysql.utf8.sql</file>
		</sql>
	</install>
	<uninstall> <!-- Runs on uninstall -->
		<sql>
			<file driver="mysql" charset="utf8">sql/uninstall.mysql.utf8.sql</file>
		</sql>
	</uninstall>
	<update> <!-- Runs on update; New since J2.5 -->
		<schemas>
			<schemapath type="mysql">sql/updates/mysql</schemapath>
		</schemas>
	</update>

	<!-- Site Main File Copy Section -->
	<!-- Note the folder attribute: This attribute describes the folder
		to copy FROM in the package to install therefore files copied
		in this section are copied from /site/ in the package -->
	<files folder="site">
		<filename>index.html</filename>
		<filename>helloworld.php</filename>
		<filename>controller.php</filename>
		<filename>router.php</filename>
		<folder>controllers</folder>
		<folder>views</folder>
		<folder>models</folder>
		<folder>helpers</folder>
	</files>

		<languages folder="site/language">
			<language tag="en-GB">en-GB/en-GB.com_helloworld.ini</language>
			<language tag="fr-FR">fr-FR/fr-FR.com_helloworld.ini</language>
		</languages>

	<media destination="com_helloworld" folder="media">
		<filename>index.html</filename>
		<folder>images</folder>
		<folder>js</folder>
		<folder>css</folder>
	</media>

	<administration>
		<!-- Administration Menu Section -->
		<menu link='index.php?option=com_helloworld' img="../media/com_helloworld/images/tux-16x16.png">COM_HELLOWORLD_MENU</menu>
		<!-- Administration Main File Copy Section -->
		<!-- Note the folder attribute: This attribute describes the folder
			to copy FROM in the package to install therefore files copied
			in this section are copied from /admin/ in the package -->
		<files folder="admin">
			<!-- Admin Main File Copy Section -->
			<filename>index.html</filename>
			<filename>config.xml</filename>
			<filename>helloworld.php</filename>
			<filename>controller.php</filename>
			<filename>access.xml</filename>
			<!-- SQL files section -->
			<folder>sql</folder>
			<!-- tables files section -->
			<folder>tables</folder>
			<!-- models files section -->
			<folder>models</folder>
			<!-- views files section -->
			<folder>views</folder>
			<!-- controllers files section -->
			<folder>controllers</folder>
			<!-- helpers files section -->
			<folder>helpers</folder>
			<!-- layout files section -->
			<folder>layouts</folder>
		</files>
		<languages folder="admin/language">
			<language tag="en-GB">en-GB/en-GB.com_helloworld.ini</language>
			<language tag="en-GB">en-GB/en-GB.com_helloworld.sys.ini</language>
			<language tag="fr-FR">fr-FR/fr-FR.com_helloworld.ini</language>
			<language tag="fr-FR">fr-FR/fr-FR.com_helloworld.sys.ini</language>
		</languages>
	</administration>

	 <updateservers>
		<!-- Change the URL below to match that of your own update XML file -->
		<server type="extension" name="Helloworld Updates">http://localhost/helloworld-updates/updates.xml</server>
	</updateservers>
</extension>

Update Server Files[edit]

We're going to put three files into the directory that we're using to act as the update server, i.e. into the /helloworld-updates folder, or wherever you have decided to use. The three files are:

  1. the updates.xml file
  2. an HTML file that is an information file for the latest version
  3. a zip file for the update.

For security purposes you should also add the usual empty index.html file as well. The updates.xml file is below. Change the infourl and downloadurl to suit your environment, and set values for the targetplatform, php_minimum and supported_databases as you wish.

<updates>
	<update>
		<name>Helloworld component</name>
		<description>Helloworld component for Joomla MVC tutorial</description>
		<element>com_helloworld</element>
		<type>component</type>
		<version>1.0.0</version>
		<client>administrator</client>
		<infourl>http://localhost/helloworld-updates/info-1-0-0.html</infourl>
		<downloads>
			<downloadurl type="full" format="zip">http://localhost/helloworld-updates/helloworld-1-0-0.zip</downloadurl>
		</downloads>
		<tags>
			<tag>stable</tag>
		</tags>
		<targetplatform name="joomla" version="3.[23456789]" />
		<php_minimum>5.3</php_minimum>
		<supported_databases mysql="5.6.19"></supported_databases>
	</update>
</updates>

You can find definitions of the elements of this XML structure at Deploying an Update Server, but note that the attributes min_dev_level and max_dev_level are marked as deprecated in the current (3.9) Joomla code, to be removed in Joomla 4. The information file is just a basic HTML document that you can modify as you wish. Its filename must match what is specified in the <infourl> tag above.

<!DOCTYPE html>
<html>
<head>
	<title>Helloworld update</title>
</head>
<body>
	<h1>Update to version 1.0.0</h1>
</body>
</html>

Finally create a store a zip file for the new version. As a minimum you need to update the version in the manifest file, and you may wish to make another change that is visible when you visit the site.

  1. Update the manifest file (helloworld.xml) to set the version line to <version>1.0.0</version>
  2. Create a zip file of the helloworld component
  3. Copy the zip file into your update server directory. Its name must match what is specified in the <downloadurl> tag (helloworld-1-0-0.zip above).

Testing the Update Server[edit]

To test your update server do the following:

  1. Log in to the Backend of your site using an admin account.
  2. Go to Extensions  Manage  Update.
  3. Click on Find Updates. Your helloworld component should appear as an update. (It may already be shown, because when you display the administrator control panel it issues an AJAX request that initiates the find updates process).
  4. Click on the checkbox next to the helloworld component, and click on Update.
  5. Go to Extensions  Manage  Manage and find the helloworld component. Its version should now be 1.0.0 (or whatever version you updated to).

(For info, using phpMyAdmin you can change the existing version number of the helloworld component by finding the appropriate record in the extensions table, and updating the version number within the JSON string in the manifest_cache field.)

Collections Type[edit]

Up to now we've been considering the server type="extension", but Joomla also has a server type="collection". The purpose of this type is to allow you to have a collection of different update XML files. You would use a "collection" type if, for example,

  1. Your extension is a package and you want to allow users to update the package components individually.
  2. You want to have different update XML files for different versions of Joomla.

Joomla languages use a collection type. If you have several languages installed and go to Extensions  Manage  Update Sites, you can see that all the languages have the same update site URL pointing to something like https://update.joomla.org/language/translationlist_3.xml. If you open that XML file you'll see all the details URLs that are the update XML files of the individual languages, and that can be installed via the Extensions  Manage  Install Languages page.

Joomla core also uses a collection type. If you go to Update Sites and click on the XML file for Joomla! Core, you will see different update XML files depending upon whether the installed version of Joomla is 2.x or 3.x. If you wish to try using a collection type, this is still possible with a single update XML file, by following the steps below. First manually delete (using phpMyAdmin) the records in the database tables update_sites and update_sites_extensions that relate to the helloworld component. Then go into Extensions  Manage  Update and click on Clear Cache. This should remove all traces of the type="extension" update mechanism. Second replace the updateservers section of the manifest file with the following (changing the URL appropriately)

<updateservers>
	<server type="collection" name="Helloworld Updates">http://localhost/helloworld-updates/list.xml</server>
</updateservers>

Zip up the component and install it in the usual way. (Remember when you install it in this way the version number in the new install file doesn't need to be greater than the version of the one currently installed). Third, create a list.xml file that points to the update XML file, and store this in your update server folder. Once again, change the URL and version to match your own situation, making sure that the version quoted in the file is greater than the one currently installed.

<extensionset name="Helloworld Update Collection" description="Helloworld Update as Collection">
	<extension name="Helloworld Component" element="com_helloworld" type="component" client="administrator" version="1.0.0" targetplatformversion="3.[23456789]" detailsurl="http://localhost/helloworld-updates/updates.xml"/>
</extensionset>

If you test the update process as above you should find it works just the same. However, note that in this case the updates.xml file is not processed during the Find Updates process. If you have an incompatible minimum value of PHP say, it won't report it at that stage.

Contributors[edit]