Adding an Additional Block to a Marketplace Package

Permalink
Does any one know how or if there is there a way to add and additional block to a Marketplace Package that will install with out having to uninstall and then reinstall? Thanks for the help.

I found this, but it's not the solution I am looking for.
http://www.concrete5.org/community/forums/customizing_c5/extending-...

dwayneparton
View Replies:
12345j replied on at Permalink Reply
12345j
without using the same handle no, the install scrpt would have to be run again, and can only do that on install.
jordanlev replied on at Permalink Reply
jordanlev
Yes, but it might cause trouble if the marketplace addon is itself updated...

If you add an "upgrade" function to the package controller, put the block installation code in there, then increment the package version number -- now you can go to the dashboard and "upgrade" the package. This is what the code looks like:
public function upgrade() {
  parent::upgrade();
  BlockType::installBlockTypeFromPackage('your_block_handle', $this);
}

(note that I'm not sure about passing "$this" to the installBlockTypeFromPackage function -- seems like it should work but maybe not, in which case you'd have to do "$pkg = Package::getByHandle('the_package_handle')")

BUT if the package is upgraded via the marketplace, you'll get all out of whack because you changed the version number, etc.
dwayneparton replied on at Permalink Reply
dwayneparton
Thanks for the responses. I was hoping maybe I had overlooked something. It seems that the conclusion is that on your on installation it is possible but trying to implement something like this in the marketplace would be a recipe for problems. Thanks again.
TimDix replied on at Permalink Reply
TimDix
This can be done, you just need to be careful.

For all of my packages, I do the following:
public function install() {
    $pkg = parent::install();
    //Both install and Upgrade pass off to this
    $this->installComponents($pkg);
}


public function upgrade() {
    parent::upgrade();
    //Both install and Upgrade pass off to this
    $pkg = Package::getByHandle($this->$pkgHandle);
    $this->installComponents($pkg);
}


//This actually lists all components, which are responsible for ensuring they're installed.
public function installComponents($pkg) {
    /* From here, you check to see if each component has 
       been added, and if not, install. For example, I have 
       a custom attribute type called range. */
    $rt = AttributeType::getByHandle('range');
    if(!$rt->atID)
    {
        //Add the new Type
        $rt = AttributeType::add('range', t('Range'), $pkg);
        //Associate our type with collections
        $cakc = AttributeKeyCategory::getByHandle('collection');
        $cakc->associateAttributeKeyType($rt);
    }   
}
andrew replied on at Permalink Reply
andrew
I agree with Jordan: just increment the version number, create an upgrade function and install the block there.

One note, though: upgrade() gets run any time your version number in the package is greater than the one that you had installed. So you want to build the upgrade() function in such a way that it checks to see whether your components already exist, before trying to install them.
dwayneparton replied on at Permalink Reply
dwayneparton
Thanks alot! I haven't had time to work through this but I really appreciate the help.