This is the documentation for concrete5 version 5.6 and earlier. View Current Documentation

Where a package requires certain prerequisites to be met before it can be installed, you can use tests in the package controller install() method to check those prerequisites and prevent installation unless conditions are met.

This is easily shown with an example. In my Magic Data Commerce addon, the package requires that both Magic Data and eCommerce are already installed. Furthermore, it needs at least a minimum version of those addons to be installed.

The install method in the package controller consequently tests for those addon packages and versions, throwing exceptions if the prerequisites are not met. The concrete5 package installer then translates those exceptions into an installation error banner and the package would not be installed.

protected $mdVersionRequired = '2.5.1';
protected $ccVersionRequired = '2.8.8';
public function install() {

  $md_pkg  = Package::getByHandle('jl_magic_data');
  if (  !is_object($md_pkg) || 
        version_compare($md_pkg->getPackageVersion(), $this->mdVersionRequired, 'lt')
    throw new Exception(t('Installation requires as a prerequisite that Magic Data v%s+ is already installed.', $this->mdVersionRequired));

  $cc_pkg  = Package::getByHandle('core_commerce');
  if (  !is_object($cc_pkg) || 
        version_compare($cc_pkg->getPackageVersion(), $this->ccVersionRequired, 'lt')
    throw new Exception(t('Installation requires as a prerequisite that eCommerce v%s+ is already installed.', $this->ccVersionRequired));

  $pkg = parent::install();

  Rest of installation code

The important point is that parent::install(); is not called until after the prerequisite tests have been completed.

Read more How-Tos by JohntheFish.

Loading Conversation