Installation & Uninstallation Code 
If the product you are developing requires additional code, such as database queries, to be run during installation or uninstallation, this section will cover how to accomplish this.

Once you have created a product, you will be taken back to the main product manager page. From this page, select Edit from the dropdown for your product. Here, you can edit the existing product properties (see this page for more information) or add/edit install and uninstall codes. We will concentrate on the install codes section:

Version
(mandatory)
The version of your product that this specific install/uninstall code pair corresponds to. This is used to control when the code is executed (see below).
Install Code
(optional)
This PHP code will be run only during installation of or while upgrading your product, starting with code attached to the oldest version. If the user is upgrading, only codes attached to newer versions will be run. Here is an example:

You make several releases of your product, DemoProduct, versions 1.0, 1.1, 2.0, and 2.0.1. A user currently has version 2.0 installed. When he or she upgrades to 2.0.1, the only install code that will be run is code attached to the 2.0.1 release. However, when someone installs your product for the first time, code will be run from all versions in the order of 1.0, 1.1, 2.0, and finally 2.0.1.

This system allows you to provide increment upgrades and first time installs in the same system.
Uninstall Code
(optional)
This PHP code is run only when your product is fully uninstalled. This should be used to clean up any tables or extra data that your product has created. Note that control panel options, phrases, templates, and plugins will automatically be cleaned up for you.

Multiple pieces of uninstall code are executed from the newest to oldest version. Using the example above, the uninstall codes will be run in this order: 2.0.1, 2.0, 1.1, 1.0. This allows you to couple install codes and uninstall codes together into a specific version, preventing some uninstallation errors from occuring.

Warning:
You must handle errors that may occur in the install/uninstall code as there is no built in error checking beyond what PHP natively provides.
User Contributed Notes: Installation & Uninstallation Code Add a Comment