AppExchange Package Upload to Include Custom Themes

Zach, since updating to this, my pages haven’t been auto-deploying. The theme has, which is great. Not sure if you see anything below, I don’t think I changed anything that would affect pages not unpacking. I can still manually unpack them, so its not a permissions or static resource issue. Thoughts?

public without sharing class InstallScript_CheetahBMS implements InstallHandler {
public static final String NAMESPACE_PREFIX = ‘CheetahBMS’;
public static boolean IsRunning {
public get {
if (IsRunning==null) IsRunning = false;
return IsRunning;
}
public set;
}

public void onInstall(InstallContext ctx) {
    IsRunning=true;
    RefreshPagesInModule(NAMESPACE_PREFIX);
    CreateDefaultThemes();
    IsRunning=false;
}

public static List<skuid__Page__c> RefreshPagesInModule(String module) {
    
    // See if a StaticResource containing new pages for this module yet exists      
    StaticResource sr = [
        select Body
        from StaticResource 
        where Name = :(module + 'Pages')
        and ((NamespacePrefix = NULL) OR (NamespacePrefix = :module))
        limit 1
    ];
    
    // The new Pages for our module that we will be inserting       
    List<skuid__Page__c> newPages
         = (List<skuid__Page__c>) JSON.deserialize(sr.Body.toString(),List<skuid__Page__c>.class);
    List<Schema.SObjectField> layoutFields = new List<Schema.SObjectField>{
        skuid__Page__c.skuid__Layout__c,
        skuid__Page__c.skuid__Layout2__c,
        skuid__Page__c.skuid__Layout3__c,
        skuid__Page__c.skuid__Layout4__c,
        skuid__Page__c.skuid__Layout5__c
    };
    
    for (skuid__Page__c p : newPages) {
        // Get rid of the Ids so that upsert will proceed           
        p.Id = null;
        // Ensure that unused Layout fields are set to null         
        for (Schema.Sobjectfield f : layoutFields) {
        if (p.get(f)==null) p.put(f,null);
        }
    }
    
    // If we have successfully compiled new Pages for this module,        
   // delete the old ones and replace them with the new.        
   if (newPages != null &amp;&amp; !newPages.isEmpty()) {
    Schema.SObjectField f = skuid__Page__c.skuid__UniqueId__c;
    List<Database.UpsertResult> cr = Database.upsert(newPages,f,false);
    }   
    return newPages;
}

    // Returns a Map containing the definitions for expected default themes

public static Map<String,Map<String,String>> GetDefaultThemes() {
return new Map<String,Map<String,String>>{
// Desktop Themes
‘CheetahOrange’ => new Map<String,String>{
‘type’ => ‘Desktop’,
‘resourceName’ => ‘CheetahOrangeTheme_2’
}
};
}

// Create our default, expected Theme custom setting records if they don’t exist
public static void CreateDefaultThemes() {

  Map<String,skuid__Theme__c> existingThemes = skuid__Theme__c.getAll();
  Map<String,Map<String,String>> defaultThemes = GetDefaultThemes();
  Set<String> themeNamesToCreate = new Set<String>();
  for (String themeName : defaultThemes.keyset()) {
     if (!existingThemes.containsKey(themeName)) {
        themeNamesToCreate.add(themeName); 
     }  
  }
  
  // If there are some default themes that do not exist in this org,
  // create them!
  if (!themeNamesToCreate.isEmpty()) {
     List<skuid__Theme__c> themesToCreate = new List<skuid__Theme__c>();
     for (String themeName : themeNamesToCreate) {
        Map<String,String> themeDef = defaultThemes.get(themeName);
        themesToCreate.add(new skuid__Theme__c(
           Name                    = themeName,
           skuid__Resource_Namespace__c  = NAMESPACE_PREFIX,
           skuid__Resource_Name__c       = themeDef.get('resourceName'),
           skuid__Active__c           = true,
           skuid__Type__c                = themeDef.get('type')
        ));
     }
     insert themesToCreate;  
  }

}
}