MyComponent icon indicating copy to clipboard operation
MyComponent copied to clipboard

Fatal error: Call to a member function checkPolicy() on a non-object

Open mooror opened this issue 9 years ago • 3 comments

Hey there Bob, Glad to be back :D but his time I have a small problem when I'm trying to use the bootstrap utility. Now granted I am using it from my comandline which might be changing things, but I can bootstrap any of the new projects just fine which I find strange. Heres the full error:

Fatal error: Call to a member function checkPolicy() on a non-object in /home/siteleas/public_html/builder/core/model/modx/processors/element/create.class.php on line 44

And here is my siteleasecore.config.php file code:

<?php

$packageNameLower = 'siteleasecore'; /* No spaces, no dashes */

$components = array(
    /* These are used to define the package and set values for placeholders */
    'packageName' => 'siteleasecore',  /* No spaces, no dashes */
    'packageNameLower' => $packageNameLower,
    'packageDescription' => 'The siteleasecore for the pspsundance project',
    'version' => '0.0.1',
    'release' => 'beta1',
    'author' => 'Ben Blake',
    'email' => '<http://bobsguides.com>',
    'authorUrl' => 'http://www.sitelease.ca',
    'authorSiteName' => "Sitelease.ca",
    'packageDocumentationUrl' => 'http://bobsguides.com/siteleasecore-tutorial.html',
    'copyright' => '2016',

    /* no need to edit this except to change format */
    'createdon' => strftime('%m-%d-%Y'),

    'gitHubUsername' => 'Mooror',
    'gitHubRepository' => 'siteleasecore',

    /* two-letter code of your primary language */
    'primaryLanguage' => 'en',

    /* Set directory and file permissions for project directories */
    'dirPermission' => 0755,  /* No quotes!! */
    'filePermission' => 0644, /* No quotes!! */

    /* Define source and target directories */

    /* path to MyComponent source files */
    'mycomponentRoot' => $this->modx->getOption('mc.root', null,
        MODX_CORE_PATH . 'components/mycomponent/'),

    /* path to new project root */
    'targetRoot' => MODX_ASSETS_PATH . 'mycomponents/' . $packageNameLower . '/',


    /* *********************** NEW SYSTEM SETTINGS ************************ */

    /* If your extra needs new System Settings, set their field values here.
     * You can also create or edit them in the Manager (System -> System Settings),
     * and export them with exportObjects. If you do that, be sure to set
     * their namespace to the lowercase package name of your extra */

    'newSystemSettings' => array(),

    /* ************************ NEW SYSTEM EVENTS ************************* */

    /* Array of your new System Events (not default
     * MODX System Events). Listed here so they can be created during
     * install and removed during uninstall.
     *
     * Warning: Do *not* list regular MODX System Events here !!! */

    'newSystemEvents' => array(),

    /* ************************ NAMESPACE(S) ************************* */
    /* (optional) Typically, there's only one namespace which is set
     * to the $packageNameLower value. Paths should end in a slash
    */

    'namespaces' => array(
        'siteleasecore' => array(
            'name' => 'siteleasecore',
            'path' => '{core_path}components/siteleasecore/',
            'assets_path' => '{assets_path}components/siteleasecore/',
        ),

    ),

    /* ************************ CONTEXT(S) ************************* */
    /* (optional) List any contexts other than the 'web' context here
    */

    'contexts' => array(),

    /* *********************** CONTEXT SETTINGS ************************ */

    /* If your extra needs Context Settings, set their field values here.
     * You can also create or edit them in the Manager (Edit Context -> Context Settings),
     * and export them with exportObjects. If you do that, be sure to set
     * their namespace to the lowercase package name of your extra.
     * The context_key should be the name of an actual context.
     * */

    'contextSettings' => array(),

    /* ************************* CATEGORIES *************************** */
    /* (optional) List of categories. This is only necessary if you
     * need to categories other than the one named for packageName
     * or want to nest categories.
    */

    'categories' => array(
        'siteleasecore' => array(
            'category' => 'siteleasecore',
            'parent' => '',  /* top level category */
        ),
        'components' => array(
            'category' => 'Components',
            'parent' => 'siteleasecore', /* nested under siteleasecore */
        ),
        'stripes' => array(
            'category' => 'Stripes',
            'parent' => 'components', /* nested under components */
        ),
        'modules' => array(
            'category' => 'Modules',
            'parent' => 'components', /* nested under components */
        ),
        'stripesets' => array(
            'category' => 'Stripe Sets',
            'parent' => 'components', /* nested under components */
        )
    ),

    /* *************************** MENUS ****************************** */

    /* If your extra needs Menus, you can create them here
     * or create them in the Manager, and export them with exportObjects.
     * Be sure to set their namespace to the lowercase package name
     * of your extra.
     *
     * Every menu should have exactly one action */

    'menus' => array(),


    /* ************************* ELEMENTS **************************** */

    /* Array containing elements for your extra. 'category' is required
       for each element, all other fields are optional.
       Property Sets (if any) must come first!

       The standard file names are in this form:
           SnippetName.snippet.php
           PluginName.plugin.php
           ChunkName.chunk.html
           TemplateName.template.html

       If your file names are not standard, add this field:
          'filename' => 'actualFileName',
    */


    'elements' => array(
        'propertySets' => array( /* all three fields are required */),
        'snippets' => array(),
        'plugins' => array(),
        'chunks' => array(
            'header-set' => array(
                'description' => 'Shared header section of each page',
                'category' => 'stripesets',
                'static' => false,
            ),
            'footer-set' => array(
                'description' => 'Shared footer section of each page',
                'category' => 'stripesets',
                'static' => false,                
            ),
            'scripts-set' => array(
                'description' => 'Shared scripts section of each page',
                'category' => 'stripesets',
                'static' => false,                
            ),
            'head-styles-set' => array(
                'description' => 'Shared styles section of each page',
                'category' => 'stripesets',
                'static' => false,                
            ),
        ),
        'templates' => array(
            'entranceTemplate' => array(
                'category' => 'siteleasecore',
                'description' => 'The main entrance template',
                'static' => false,                
            ),
            'formTemplate' => array(
                'category' => 'siteleasecore',
                'description' => 'The main form template',
                'static' => false,                
            ),
            'galleryTemplate' => array(
                'category' => 'siteleasecore',
                'description' => 'The main gallery template',
                'static' => false,                
            ),
            'infoTemplate' => array(
                'category' => 'siteleasecore',
                'description' => 'The main info template',
                'static' => false,                
            ),
        ),
        'templateVars' => array(),
    ),
    /* (optional) will make all element objects static - 'static' field above will be ignored */
    'allStatic' => false,


    /* ************************* RESOURCES ****************************
     Important: This list only affects Bootstrap. There is another
     list of resources below that controls ExportObjects.
     * ************************************************************** */
    /* Array of Resource pagetitles for your Extra; All other fields optional.
       You can set any resource field here */
    'resources' => array(        
        'mainMenu' => array( /* siteleasecore with other fields */
            'pagetitle' => 'Main Menu',
            'alias' => 'mainMenu',
            'context_key' => 'siteleasecore',                       
            'richtext' => false,
            'published' => true,            
        ),
        'entrance' => array( /* siteleasecore with other fields */
            'pagetitle' => 'Entrance',
            'alias' => 'entrance',
            'context_key' => 'siteleasecore',
            'parent' => 'MainMenu',
            'template' => 'entranceTemplate',
            'richtext' => true,
            'published' => true,            
        ),
        'photoGallery' => array( /* siteleasecore with other fields */
            'pagetitle' => 'Photo Gallery',
            'alias' => 'photoGallery',
            'context_key' => 'siteleasecore',
            'parent' => 'MainMenu',
            'template' => 'galleryTemplates',
            'richtext' => true,
            'published' => true,            
        ),
        'order' => array( /* siteleasecore with other fields */
            'pagetitle' => 'Order',
            'alias' => 'order',
            'context_key' => 'siteleasecore',
            'parent' => 'MainMenu',
            'template' => 'formTemplates',
            'richtext' => true,
            'published' => true,            
        ),
        'aboutUs' => array( /* siteleasecore with other fields */
            'pagetitle' => 'About Us',
            'alias' => 'aboutUs',
            'context_key' => 'siteleasecore',
            'parent' => 'MainMenu',
            'template' => 'infoTemplates',
            'richtext' => true,
            'published' => true,            
        ),
        'pricing' => array( /* siteleasecore with other fields */
            'pagetitle' => 'Pricing',
            'alias' => 'pricing',
            'context_key' => 'siteleasecore',
            'parent' => 'MainMenu',
            'template' => 'infoTemplates',
            'richtext' => true,
            'published' => true,            
        ),
        'reorder' => array( /* siteleasecore with other fields */
            'pagetitle' => 'Reorder',
            'alias' => 'reorder',
            'context_key' => 'siteleasecore',
            'parent' => 'MainMenu',
            'template' => 'formTemplates',
            'richtext' => true,
            'published' => true,            
        ),        
        'qAndA' => array( /* siteleasecore with other fields */
            'pagetitle' => 'Q And A',
            'alias' => 'qAndA',
            'context_key' => 'siteleasecore',
            'parent' => 'MainMenu',
            'template' => 'infoTemplates',
            'richtext' => true,
            'published' => true,            
        ),        
    ),


    /* Array of languages for which you will have language files,
     *  and comma-separated list of topics
     *  ('.inc.php' will be added as a suffix). */
    'languages' => array(
        'en' => array(
            'default',
            'properties',
            'forms',
        ),
    ),
    /* ********************************************* */
    /* Define optional directories to create under assets.
     * Add your own as needed.
     * Set to true to create directory.
     * Set to hasAssets = false to skip.
     * Empty js and/or css files will be created.
     */
    'hasAssets' => true,

    'assetsDirs' => array(
        /* If true, a default (empty) CSS file will be created */
        'css' => true,

        /* If true, a default (empty) JS file will be created */
        'js' => true,

        'images' => true,
        'audio' => true,
        'video' => true,
        'themes' => true,
    ),
    /* minify any JS files */
    'minifyJS' => true,
    /* Create a single JS file from all JS files */
    'createJSMinAll' => true,
    /* if this is false, regular jsmin will be used.
       JSMinPlus is slower but more reliable */
    'useJSMinPlus' => true,

    /* These will automatically go under assets/components/yourcomponent/js/
       Format: directory:filename
       (no trailing slash on directory)
       if 'createCmpFiles is true, these will be ignored.
    */
    'jsFiles' => array(
        'siteleasecore.js',
    ),

    /* Desired CSS files */
    'cssFiles' => array(
        'siteleasecore.css',
    ),

    /* ********************************************* */
    /* Define basic directories and files to be created in project*/

    'docs' => array(
        'readme.txt',
        'license.txt',
        'changelog.txt',
        'tutorial.html'
    ),

    /* (optional) Description file for GitHub project home page */
    'readme.md' => true,
    /* assume every package has a core directory */
    'hasCore' => true,

    /* ********************************************* */
    /* (optional) Array of extra script resolver(s) to be run
     * during install. Note that resolvers to connect plugins to events,
     * property sets to elements, resources to templates, and TVs to
     * templates will be created automatically -- *don't* list those here!
     *
     * 'default' creates a default resolver named after the package.
     * (other resolvers may be created above for TVs and plugins).
     * Suffix 'resolver.php' will be added automatically */
    'resolvers' => array(
        'default',
        'addUsers'
    ),

    /* (optional) Validators can abort the install after checking
     * conditions. Array of validator names (no
     * prefix of suffix) or '' 'default' creates a default resolver
     *  named after the package suffix 'validator.php' will be added */

    'validators' => array(
        'default',
        'hasGdLib'
    ),

    /* (optional) install.options is needed if you will interact
     * with user during the install.
     * See the user.input.php file for more information.
     * Set this to 'install.options' or ''
     * The file will be created as _build/install.options/user.input.php
     * Don't change the filename or directory name. */
    'install.options' => 'install.options',


    /* Suffixes to use for resource and element code files (not implemented)  */
    'suffixes' => array(
        'modPlugin' => '.php',
        'modSnippet' => '.php',
        'modChunk' => '.html',
        'modTemplate' => '.html',
        'modResource' => '.html',
    ),


    /* ********************************************* */
    /* (optional) Only necessary if you will have class files.
     *
     * Array of class files to be created.
     *
     * Format is:
     *
     * 'ClassName' => 'directory:filename',
     *
     * or
     *
     *  'ClassName' => 'filename',
     *
     * ('.class.php' will be appended automatically)
     *
     *  Class file will be created as:
     * yourcomponent/core/components/yourcomponent/model/[directory/]{filename}.class.php
     * Note: If a CMP is being created, classes containing the
     * project name will be ignored here.
     *
     * Set to array() if there are no classes. */
    'classes' => array(),

    /* ************************************
     *  These values are for CMPs.
     *  Set any of these to an empty array if you don't need them.
     *  **********************************/

    /* If this is false, the rest of this section will be ignored */

    'createCmpFiles' => false,

    /* IMPORTANT: The array values in the rest of
       this section should be all lowercase */

    /* This is the main action file for your component.
       It will automatically go in core/component/yourcomponent/
    */

    'actionFile' => 'index.class.php',

    /* CSS file for CMP */

    'cssFile' => 'mgr.css',

    /* These will automatically go to core/components/yourcomponent/processors/
       format directory:filename
       '.class.php' will be appended to the filename

       Built-in processor classes include getlist, create, update, duplicate,
       import, and export. */

    'processors' => array(
        'mgr/snippet:getlist',
        'mgr/snippet:changecategory',
        'mgr/snippet:remove',

        'mgr/chunk:getlist',
        'mgr/chunk:changecategory',
        'mgr/chunk:remove',
    ),

    /* These will automatically go to core/components/yourcomponent/controllers[/directory]/filename
       Format: directory:filename */

    'controllers' => array(
        ':home.class.php',
    ),

    /* These will automatically go in assets/components/yourcomponent/ */

    'connectors' => array(
        'connector.php'

    ),
    /* These will automatically go to assets/components/yourcomponent/js[/directory]/filename
       Format: directory:filename */

    'cmpJsFiles' => array(
        ':siteleasecore.class.js',
        'sections:home.js',
        'widgets:home.panel.js',
        'widgets:snippet.grid.js',
        'widgets:chunk.grid.js',
    ),

    /* These go to core/components/componentName/templates/
     * The format is:
     *    filename:content
     * content is optional
     */

    'cmpTemplates' => array (
         'mgr:<div id="siteleasecore-panel-home-div"></div>',
    ),


    /* *******************************************
     * These settings control exportObjects.php  *
     ******************************************* */
    /* ExportObjects will update existing files. If you set dryRun
       to '1', ExportObjects will report what it would have done
       without changing anything. Note: On some platforms,
       dryRun is *very* slow  */

    'dryRun' => '0',

    /* Array of elements to export. All elements set below will be handled.
     *
     * To export resources, be sure to list pagetitles and/or IDs of parents
     * of desired resources
    */
    'process' => array(
        'contexts',
        'snippets',
        'plugins',
        'templateVars',
        'templates',
        'chunks',
        'resources',
        'propertySets',
        'systemSettings',
        'contextSettings',
        'systemEvents',
        'menus'
    ),
    /*  Array  of resources to process. You can specify specific resources
        or parent (container) resources, or both.

        They can be specified by pagetitle or ID, but you must use the same method
        for all settings and specify it here. Important: use IDs if you have
        duplicate pagetitles */
    'getResourcesById' => false,

    'exportResources' => array(
        'Resource1',
        'Resource2',
    ),
    /* Array of resource parent IDs to get children of. */
    'parents' => array(),
    /* Also export the listed parent resources
      (set to false to include just the children) */
    'includeParents' => false,


    /* ******************** LEXICON HELPER SETTINGS ***************** */
    /* These settings are used by LexiconHelper */
    'rewriteCodeFiles' => false,  /* remove ~~descriptions */
    'rewriteLexiconFiles' => true, /* automatically add missing strings to lexicon files */
    /* ******************************************* */

    /* Array of aliases used in code for the properties array.
     * Used by the checkproperties utility to check properties in code against
     * the properties in your properties transport files.
     * if you use something else, add it here (OK to remove ones you never use.
     * Search also checks with '$this->' prefix -- no need to add it here. */
    'scriptPropertiesAliases' => array(
        'props',
        'sp',
        'config',
        'scriptProperties'
    ),
);

return $components;

Thanks in advance Bob, Mooror P.s. I am pretty certain the error is to do with this file as I can bootstrap other project.config.php files fine but not this one.

mooror avatar Dec 28 '15 06:12 mooror

The file has some PHP syntax errors. Do yourself a big favor and get a good code editor like PhpStorm that will show you the PHP syntax errors. It will save you countless hours.

I'm not sure if this is your problem, but this code is missing its concatenation operators:

    /* path to MyComponent source files */  
        'mycomponentRoot' => $this->modx->getOption('mcroot', null,  
            MODX_CORE_PATH  'components/mycomponent/'),  

    /* path to new project root */  
        'targetRoot' => MODX_ASSETS_PATH  'mycomponents/'  $packageNameLower  '/',  

It should be:

    /* path to MyComponent source files */  
        'mycomponentRoot' => $this->modx->getOption('mcroot', null,  
            MODX_CORE_PATH . 'components/mycomponent/'),  

    /* path to new project root */  
        'targetRoot' => MODX_ASSETS_PATH . 'mycomponents/' . $packageNameLower  '/',  

The error message is reporting that MODX is trying to do a permission check for a category that doesn't exist.

BobRay avatar Dec 28 '15 19:12 BobRay

Hey there Bob, Thank you for the swift reply. I checked my code and the dots are there so I guess it must be githubs interpretation of the dot (for some reason it removes it I guess). Any way I was able to get the project bootstrapped just fine once I changed all of the category names to exactly what they were in the object. So instead of this:

'stripesets' => array(
            'category' => 'Stripe Sets',
            'parent' => 'components', /* nested under components */
        )

I had to do this:

'stripesets' => array(
            'category' => 'stripesets',
            'parent' => 'components', /* nested under components */
        )

But now I am running into problems with the bootstrap creating the rescource objects. Heres the error:

Processing Resources
ERROR -- [Object Adapter] Failed to create object
    class: modResource
    nameKey: pagetitle
    name: Main Menu
    Creating E:\Ampps\www\mother-workspace\websites\pspsundance\modx/assets/mycomponents/siteleasecore/_build/data/resources/main_menu.content.html
ERROR -- [ResourceAdapter] Could not find parent for resource: Entrance
ERROR -- [Object Adapter] Failed to create object
    class: modResource
    nameKey: pagetitle
    name: Entrance
    Creating E:\Ampps\www\mother-workspace\websites\pspsundance\modx/assets/mycomponents/siteleasecore/_build/data/resources/entrance.content.html
ERROR -- [ResourceAdapter] Could not find parent for resource: Photo Gallery
ERROR -- [Object Adapter] Failed to create object
    class: modResource
    nameKey: pagetitle
    name: Photo Gallery
    Creating E:\Ampps\www\mother-workspace\websites\pspsundance\modx/assets/mycomponents/siteleasecore/_build/data/resources/photo_gallery.content.html
ERROR -- [ResourceAdapter] Could not find parent for resource: Order
ERROR -- [Object Adapter] Failed to create object
    class: modResource
    nameKey: pagetitle
    name: Order
    Creating E:\Ampps\www\mother-workspace\websites\pspsundance\modx/assets/mycomponents/siteleasecore/_build/data/resources/order.content.html
ERROR -- [ResourceAdapter] Could not find parent for resource: About Us
ERROR -- [Object Adapter] Failed to create object
    class: modResource
    nameKey: pagetitle
    name: About Us
    Creating E:\Ampps\www\mother-workspace\websites\pspsundance\modx/assets/mycomponents/siteleasecore/_build/data/resources/about_us.content.html
ERROR -- [ResourceAdapter] Could not find parent for resource: Pricing
ERROR -- [Object Adapter] Failed to create object
    class: modResource
    nameKey: pagetitle
    name: Pricing
    Creating E:\Ampps\www\mother-workspace\websites\pspsundance\modx/assets/mycomponents/siteleasecore/_build/data/resources/pricing.content.html
ERROR -- [ResourceAdapter] Could not find parent for resource: Reorder
ERROR -- [Object Adapter] Failed to create object
    class: modResource
    nameKey: pagetitle
    name: Reorder
    Creating E:\Ampps\www\mother-workspace\websites\pspsundance\modx/assets/mycomponents/siteleasecore/_build/data/resources/reorder.content.html
ERROR -- [ResourceAdapter] Could not find parent for resource: Q And A
ERROR -- [Object Adapter] Failed to create object
    class: modResource
    nameKey: pagetitle
    name: Q And A
    Creating E:\Ampps\www\mother-workspace\websites\pspsundance\modx/assets/mycomponents/siteleasecore/_build/data/resources/q_and_a.content.html

The files are being created fine for each of the resources but the objects in modx are not working. I tried building the project to see if somehow that would do anything to fix this (worth a try I though :D ) but upon installing the transport package the resources didn't show up. All the chunks and resources showed up great, in fact I'm really impressed with the category handling as I had them nested a bit deep. Anyway thank you so much for your help and please let me know if you need more information (and what specific information you need).

Sorry for all the problems, Mooror P.S. as a small side question how might I add spaces to category names?

mooror avatar Dec 29 '15 03:12 mooror

The resource parent field must contain the actual pagetitle of the parent (that's how they're found). Yours don't match the 'pagetitle' field specified in the earlier resources.

It's a good practice to have the array key and the pagetitle match exactly to avoid this problem:

    'Main Menu' => array( /* siteleasecore with other fields */
            'pagetitle' => 'Main Menu',
            'alias' => 'mainMenu',
            'context_key' => 'siteleasecore',                       
            'richtext' => false,
            'published' => true,            
    ),

I suspect the problem with categories has the same cause. If you do the same thing there, you should be able to use spaces in the names (though I've never tried it).

BobRay avatar Dec 29 '15 06:12 BobRay