As a package developer, if you add a block type or single page to a package, you can use upgrade() to install them without any need to uninstall the package first.
Package Version 1.0
First, to set the background, the package controller for version 1.0 of a package, installing a block type and a single page.
protected $pkgVersion = '1.0';
public function install() {
$pkg = parent::install();
// install block
BlockType::installBlockTypeFromPackage('my_block', $pkg);
// install single page
Loader::model('single_page');
SinglePage::add('/path/for/page', $pkg);
}
Package Version 1.0.1
In version 1.0.1, the example package provides another block type and another single page. These are installed normally in the install() method to cater for any new installation of the package.
To cater for updates from a previous version of the package, the upgrade() method also installs the block type and single page that have been added since version 1.0.
protected $pkgVersion = '1.0.1';
// Install everything for a new installation
public function install() {
$pkg = parent::install();
// install block type
BlockType::installBlockTypeFromPackage('my_block', $pkg);
// install single page
Loader::model('single_page');
SinglePage::add('/path/for/page', $pkg);
// install another block type
BlockType::installBlockTypeFromPackage('my_other_block', $pkg);
// install another single page
SinglePage::add('/path/for/another_page', $pkg);
}
// Update any existing installation
public function upgrade() {
parent::upgrade();
// add another block type
$bt = BlockType::getByHandle('my_other_block');
if (!is_object($bt)) {
BlockType::installBlockTypeFromPackage('my_other_block', $this);
}
// add another single page
$p = Page::getByPath('/path/for/another_page');
if ($p->isError() || (!is_object($p))) {
SinglePage::add('/path/for/another_page', $this);
}
}
The tests about the block type and single page in the upgrade() method are only really needed if there are further upgrades - they allow for the consequence of users of the package skipping a version before upgrading and prevent failure through erroneous repetition.
Further info:
/concrete/models/package.php
Source code for eCommerce add-on controller - /packages/core_commerce/controller.php
Documentation - http://www.concrete5.org/documentation/developers/system/packages/
Forum post - http://www.concrete5.org/community/forums/customizing_c5/adding-an-additional-block-to-a-marketplace-package/
Related Tutorials
- 13
- 0
- 20
- 0
- 3
- 0
- 7
- 0
- 6
- 0
- 14
- 0
- 7
- 0
- 4
- 0
- 1
- 0
- 7
- 0
- 6
- 0
- 17
- 0
- 13
- 0
- 11
- 0
- 51
- 0
- 5
- 0
- 32
- 0
- 4
- 0
- 1
- 0
- 7
- 0
- 2
- 0
- 9
- 0
- 4
- 0
- 7
- 0
- 5
- 0
- 10
- 0
- 17
- 0
- 13
- 0
- 4
- 0
- 7
- 0
- 29
- 0
- 5
- 0
- 10
- 0
- 2
- 0
- 4
- 0
- 14
- 0
- 3
- 0
- 24
- 0
- 4
- 0
- 17
- 0
- 10
- 0