Installing attributes from package controller upgrade

Permalink 1 user found helpful
I am working on a new theme and would like to include custom attributes thus far I have the following in my controller.

I've modified the package controller by Core77https://github.com/core77/foundation_sites...
Everything works on install but I would like to be able to add attributes and page types within a new version of the package.

Can anyone help point me in the right direction?

Am I using the incorrect function to do this?

public function upgrade() {
        parent::upgrade();
        $pkg = parent::getByHandle('custom_pkg');
....
        $this->installPageAttributes($pkg);
    }
    private function installPageAttributes($pkg) {
        $cakc = Category::getByHandle('collection');
        $cakc->setAllowAttributeSets(Category::ASET_ALLOW_SINGLE);
        $fas = $cakc->addSet(
            'custom_collection',
            t('Page Attributes'),
            $pkg);
        //add boolean attributes
        $bp_boolean = CollectionKey::getByHandle('secondary_navigation');


Thank you for your help

TheRealSean
 
hutman replied on at Permalink Reply
hutman
Can you give a little more explanation of what exactly happens when you run the upgrade? If there are errors please provide those.

If you are not getting any errors but the package upgrade seems to not run you code it's possible that it is erroring trying to add a Page Attribute Set that is already there.
TheRealSean replied on at Permalink Reply
TheRealSean
Thanks for your reply,

In its current state, no errors are displayed and the Page Attribute does not exist.

I can run the update_addon command, once run it does not display a confirmation message but it does refresh the page displaying the following 'No updates for your add-ons are available.' (I'm not sure a confirmation message appears if the upgrade is successful?)

I notice that I can install AttributesSets, they appear in the DB after I run the update but the Attributes don't? if that makes sense.
hutman replied on at Permalink Reply
hutman
Do you have debugging turned on? If you do not you likely wouldn't see any errors.
TheRealSean replied on at Permalink Reply
TheRealSean
Yes both debugging turned on and cache turned off, I have seen errors but manage to resolve those at this point I'm drawing a blank
TheRealSean replied on at Permalink Reply
TheRealSean
As for the updgrade script I am attempting to get the package object, parent::upgrade does not return this

so I'm using the getByHandle to grab the package object, then pass that into the Attribute functions.

The Page attribute gets the attribute category from the AttributeKeyCategories table (collection)

$cakc->setAllowAttributeSets(Category::ASET_ALLOW_SINGLE);
Then prevents the attribute from appearing in multiple sets (I only want this set to appear in the page)

$bp_boolean = CollectionKey::getByHandle('secondary_navigation');
if (!$bp_boolean instanceof CollectionKey) {
$bp_boolean = CollectionKey::add('boolean', array(
'akHandle' => 'secondary_navigation',
'akName' => t('Secondary Navigation'),
'akIsSearchable' => true,
'akIsSearchableIndexed' => true), $pkg)->setAttributeSet($fas);
}
Then it should be checking to see if the page attribute exists and if not create the attribute, also assigning it to the set created above (Page Attributes)

I'm running a couple of other functions within the upgrade to create page types/templates but currently the one I appear to be having issues with is just the attribute creation (when run via upgrade)
TheRealSean replied on at Permalink Reply
TheRealSean
It looks like there is an error that is not being displayed I can print e and see content but the $this->set('error', $e); is not catching the error or the debug is not displaying it?
TheRealSean replied on at Permalink Reply
TheRealSean
It looks like this is related to the addSet function

$fas = $cakc->addSet(
            'custom_collection',
            t('Custom Page Attributes'),
            $pkg);


Does anyone know if its possible to check for an attribute set first before adding it, I could only see a way to grab the attributeKey/Category handles and not the set
TheRealSean replied on at Permalink Reply
TheRealSean
On a side not it looks like there is an issue with the extend/update.php file it does not display debug information if stuff goes wrong I added the config data and voila I now see debug information

<?php
namespace Concrete\Controller\SinglePage\Dashboard\Extend;
use \Concrete\Core\Page\Controller\DashboardPageController;
use TaskPermission;
use Package;
use Marketplace;
use \Concrete\Core\Marketplace\RemoteItem as MarketplaceRemoteItem;
use Localization;
use Loader;
use Config;
use Exception;
class Update extends DashboardPageController {
   public function on_start() {
      $this->error = Loader::helper('validation/error');
   }
hutman replied on at Permalink Best Answer Reply
hutman
I know in 5.6 you could do this, I would think there would be something similar in 5.7, if not the same.

$fas = AttributeSet::getByHandle('ubisense_collection');
TheRealSean replied on at Permalink Reply
TheRealSean
you've got it ;) thanks, I had a few issues initially with that but once loaded in at the top it works

use \Concrete\Core\Attribute\Set as AttributeSet;
//then
$cas = AttributeSet::getByHandle('custom_collection');
        if (!$cas instanceof AttributeSet) {
          ...
        }


Thanks for your help.