ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

PHP Error on Add-ons > Accessories Page

February 11, 2011 7:38pm

Subscribe [4]
  • #1 / Feb 11, 2011 7:38pm

    upshot

    85 posts

    When I visit the Add-Ons > Accessories page I get the PHP error:

    A PHP Error was encountered
    Severity: Notice
    Message: Array to string conversion
    Filename: libraries/Cp.php
    Line Number: 731

    And then in the accessory listings below I see under “Available to Member Groups” I see either “—”, “All” or I get groups listed but I see the number 5 included.  Snapshot: http://img4.imageshack.us/i/butlerupshotstagingnety.jpg/

    I did just delete the Member Group with ID of 5 earlier today.  Does this mean there’s some clean up upon deletion of Member Groups that’s not happening properly?

  • #2 / Feb 12, 2011 11:15am

    Ian from Aus

    94 posts

    Note: I think the member group “5” appearing is separate to this error message.

    I’ve just received this error message after upgrading (from 2.0.3) this afternoon… but on one site, but not another.
    After some research, it looks like this is a bug.

    It presents itself when a custom CP template is selected, but I think it is due to an accessory install issue (still investigating). Edit: It is not related to accessories installed or otherwise. They simply need to be located in the third_party directory and are parsed by the accessories controller causing the error.

    My understanding of this part of the code (function load_package_file, line 729) is that it is meant to load any _extra_ CSS files for installed third-party packages (in this case our accessories).
    However, it appears that sometimes (if there are no additional CSS files specified for that accessory?) it returns the CP theme directory. If you have a custom theme selected then there are 2 theme directories (your custom theme and the default for fall-back). This means you have an array of directories, hence the “Array to string conversion” error.

    It seems to me that this “bug” would also occur for JS files as the function load_package_js (line 712) is handled in the same way.

    What I don’t understand (haven’t looked deep enough yet), is why the base CP template directories are returned when searching for additional CSS (possibly also JS) files for installed accessories.

    Geek mode on:

    Line 731:
    $package = trim(str_replace(array(PATH_THIRD, 'views'), '', $this->EE->load->_ci_view_path), '/');

    If you have a custom CP template selected the variable “$this->EE->load->_ci_view_path” is sometimes an array of the template directories (custom and default), rather than a string. Hence the “Array to String conversion” error when it tries to do the “trim” function on the array returned by “str_replace”.

    I need to look at how Accessories are registered in the database to see if the “bug” is actually caused by some corrupt/old data causing the CP theme directories to be returned (another fall-back?) or even further into the code to see what is going on. 😖

    /edit: Updated to note the “Member group 5” issue as separate

  • #3 / Feb 12, 2011 12:00pm

    Ian from Aus

    94 posts

    Hmmmm… ok, I’m confused, but it’s also 2:45am so I’m not going to go further into the code. Time to stop bug hunting and pass on to someone else.

    It seems this bug isn’t related to any how the accessories are registered. They appear whether they are installed in to EE or not.

    When I ‘grep -rn “load_package_css” *’ in the system/expressionengine dir, I get:

    libraries/Cp.php:729:    function load_package_css($file)
    third_party/cp_analytics/acc.cp_analytics.php:17:        $this->EE->cp->load_package_css('accessory');
    third_party/recent_entries/acc.recent_entries.php:46:                $this->EE->cp->load_package_css('recent_entries_default');
    third_party/recent_entries/acc.recent_entries.php:51:                $this->EE->cp->load_package_css('recent_entries_corporate');
    third_party/recent_entries/acc.recent_entries.php:62:                    $this->EE->cp->load_package_css($theme);
    third_party/recent_entries/acc.recent_entries.php:66:                    $this->EE->cp->load_package_css('recent_entries_default');

    And in the output HTML (with both installed):

    <link type="text/css" rel="stylesheet" href="admin?D=cp&C=css&M=third_party&package=cp_analytics&file=accessory" />
    <link type="text/css" rel="stylesheet" href="admin?D=cp&C=css&M=third_party&package=recent_entries&file=recent_entries_default" />
    <link type="text/css" rel="stylesheet" href="admin?D=cp&C=css&M=third_party&package=Array&file=accessory" />
    <link type="text/css" rel="stylesheet" href="admin?D=cp&C=css&M=third_party&package=Array&file=recent_entries_default" />

    And with them both uninstalled:

    <link type="text/css" rel="stylesheet" href="admin?D=cp&C=css&M=third_party&package=Array&file=accessory" />
    <link type="text/css" rel="stylesheet" href="admin?D=cp&C=css&M=third_party&package=Array&file=recent_entries_default" />

    So it appears the offending accessories are any? calling the load_package_css() function. (The recent_entries accessory only calls it once, the 4 listed are in an if/then block).

    From the first HTML block, it appears that when the accessory is installed, the $package variable is set correctly. What I haven’t figured out is why the accessories are being called a second time, and returning an invalid package (the CP directories as an array).

  • #4 / Feb 13, 2011 4:37am

    Ian from Aus

    94 posts

    Ok… next lot of debugging… unfortunately not much further. 😖

    /aside: I’m having troubles dumping a trace to a file. I’m trying to enable output buffering to capture ‘var_dump(debug_backtrace());’ but it is failing miserably. I can only assume that EE’s OB is interfering, although I thought multiple nested OB’s were ok.

    So… using the Exception method getTraceAsString() I’m getting this (for the 4 loops as above):

    #0 system/expressionengine/third_party/cp_analytics/acc.cp_analytics.php(17): Cp->load_package_css('accessory')
    #1 system/expressionengine/libraries/Accessories.php(111): Cp_analytics_acc->Cp_analytics_acc()
    #2 system/expressionengine/libraries/Cp.php(151): EE_Accessories->generate_accessories()
    #3 system/expressionengine/libraries/Core.php(487): Cp->set_default_view_variables()
    #4 system/expressionengine/libraries/Core.php(360): EE_Core->_initialize_cp()
    #5 system/expressionengine/libraries/Core.php(49): EE_Core->_initialize_core()
    #6 system/codeigniter/system/core/Loader.php(920): EE_Core->__construct()
    #7 system/codeigniter/system/core/Loader.php(820): CI_Loader->_ci_init_class('Core', '', NULL, NULL)
    #8 system/codeigniter/system/core/Loader.php(109): CI_Loader->_ci_load_class('core', NULL, NULL)
    #9 system/codeigniter/system/core/Loader.php(984): CI_Loader->library('core')
    #10 system/codeigniter/system/core/Controller.php(53): CI_Loader->_ci_autoloader()
    #11 system/expressionengine/controllers/cp/addons_accessories.php(38): CI_Controller->__construct()
    #12 system/codeigniter/system/core/CodeIgniter.php(267): Addons_accessories->__construct()
    #13 admin(224): require_once('sysytem/...')
    #14 {main}
    
    
    #0 system/expressionengine/third_party/recent_entries/acc.recent_entries.php(66): Cp->load_package_css('recent_entries_…')
    #1 system/expressionengine/libraries/Accessories.php(111): Recent_entries_acc->Recent_entries_acc()
    #2 system/expressionengine/libraries/Cp.php(151): EE_Accessories->generate_accessories()
    #3 system/expressionengine/libraries/Core.php(487): Cp->set_default_view_variables()
    #4 system/expressionengine/libraries/Core.php(360): EE_Core->_initialize_cp()
    #5 system/expressionengine/libraries/Core.php(49): EE_Core->_initialize_core()
    #6 system/codeigniter/system/core/Loader.php(920): EE_Core->__construct()
    #7 system/codeigniter/system/core/Loader.php(820): CI_Loader->_ci_init_class('Core', '', NULL, NULL)
    #8 system/codeigniter/system/core/Loader.php(109): CI_Loader->_ci_load_class('core', NULL, NULL)
    #9 system/codeigniter/system/core/Loader.php(984): CI_Loader->library('core')
    #10 system/codeigniter/system/core/Controller.php(53): CI_Loader->_ci_autoloader()
    #11 system/expressionengine/controllers/cp/addons_accessories.php(38): CI_Controller->__construct()
    #12 system/codeigniter/system/core/CodeIgniter.php(267): Addons_accessories->__construct()
    #13 admin(224): require_once('sysytem/...')
    #14 {main}
    
    
    
    #0 system/expressionengine/third_party/cp_analytics/acc.cp_analytics.php(17): Cp->load_package_css('accessory')
    #1 system/expressionengine/controllers/cp/addons_accessories.php(96): Cp_analytics_acc->Cp_analytics_acc()
    #2 [internal function]: Addons_accessories->index()
    #3 system/codeigniter/system/core/CodeIgniter.php(297): call_user_func_array(Array, Array)
    #4 admin(224): require_once('sysytem/...')
    #5 {main}
    
    
    #0 system/expressionengine/third_party/recent_entries/acc.recent_entries.php(66): Cp->load_package_css('recent_entries_…')
    #1 system/expressionengine/controllers/cp/addons_accessories.php(96): Recent_entries_acc->Recent_entries_acc()
    #2 [internal function]: Addons_accessories->index()
    #3 system/codeigniter/system/core/CodeIgniter.php(297): call_user_func_array(Array, Array)
    #4 admin(224): require_once('sysytem/...')
    #5 {main}

    The first 2 blocks are the “correct” loading of the enabled accessories. The second 2 are the ones causing the problem (the variable ‘$this->EE->load->_ci_view_path’ containing the array of custom and default CP theme directories).

    Unfortunately, due to not being able to trap the output of debug_backtrace(), and it crashing my browser when printed, I haven’t yet worked out where and why the value for ‘_ci_view_path’ is being set.

    The debugging continues…

  • #5 / Feb 13, 2011 10:01am

    Ian from Aus

    94 posts

    Ok…. so after trawling through the code for a while, I think I know what happens. And more importantly, how to fix it.

    For the first two blocks above, call #4 is to the EE_Core->_initialize_cp() function which contains the block:

    // make sure the theme exists, and shunt to default if it does not
            // always add default as a fallback.
            if ($cp_theme == 'default' OR ! is_dir(PATH_CP_THEME.$cp_theme))
            {
                $this->EE->load->_ci_view_path = PATH_CP_THEME.'default/';
                $cp_theme = 'default';
            }
            else
            {
                $this->EE->load->_ci_view_path = array(
                    PATH_CP_THEME.$cp_theme.'/',
                    PATH_CP_THEME.'default/'
                );
            }

    This is setting our variable to the array of custom and default CP theme paths.

    And then in ‘EE_Accessories->generate_accessories()’ (system/expressionengine/libraries/Accessories.php:50) at line 105 we encounter this:

    // switch the view and package path temporarily to the packages's folder
                                $orig_view_path = $this->EE->load->_ci_view_path;
                                $this->EE->load->_ci_view_path = PATH_THIRD.strtolower($name).'/views/';
                                $this->EE->load->add_package_path(PATH_THIRD.strtolower($name).'/');

    This occurs immediately before our new Accessory is instantiated, hence the correct &package;=%package_name% in the first two lines of the first HTML block above.

    In the problem cases, the function Addons_accessories->index() loads the classes with $ACC = new $accessories[$name][‘class’](); on line 96, which still has the CP value for $this->EE->load->_ci_view_path.

    I believe that the above block of code to (as the comment says) “switch the view and package paths temporarily” is what is missing from this particular loading of the class and notably, this same block is used further down this class in the function process_request() when loading the class.

    In short, I believe this patch closes this bug:

    --- addons_accessories.php.orig    2011-02-13 14:00:45.000000000 +0000
    +++ addons_accessories.php    2011-02-13 13:59:54.000000000 +0000
    @@ -93,7 +93,14 @@
                     include $accessories[$name]['path'].$accessories[$name]['file'];
                 }
     
    +            // add the package and view paths
    +            $this->load->add_package_path(PATH_THIRD.strtolower($accessories[$name]['class']).'/');
    +            $orig_view_path = $this->load->_ci_view_path;
    +            $this->load->_ci_view_path = PATH_THIRD.strtolower($accessories[$name]['class']).'/views/';
                 $ACC = new $accessories[$name]['class']();
    +            // switch the view path back to the original, remove package path
    +            $this->load->_ci_view_path = $orig_view_path;
    +            $this->load->remove_package_path(PATH_THIRD.strtolower($accessories[$name]['class']).'/');
     
                 $accessories[$name]['name'] = $ACC->name;
                 $accessories[$name]['version'] = $ACC->version;

    It’s just a shame it has taken me a full day to track this down for such a simple fix. I guess over time I’ll get to know the EE code better.

    /edit:
    Note: This doesn’t solve the reason for the member group being named “5”, but I believe that to be unrelated to this error message.

  • #6 / Feb 14, 2011 3:11am

    John Henry Donovan

    12339 posts

    Ian from Aus,

    It presents itself when a custom CP template is selected, but I think it is due to an accessory install issue (still investigating).

    Can you confirm please that this issue only presents itself when you are installing a third-party Accessory called cp analytics or another one?

    When you upgraded can you confirm you followed the version update docs as opposed to the build update docs?
    Did you update your theme folder?
    Are you using the Corporate theme? Can you try switching to default and see if issue persists?

  • #7 / Feb 14, 2011 3:46am

    Ian from Aus

    94 posts

    It wasn’t due to any accessory install issue. It is due to how the accessories page controller (addons_accessories.php) loads the classes for each accessory, regardless of it being installed or otherwise.

    It appears to occur for any accessory in the third_party directory (installed or not) that contains a call to load_package_css().

    I am not using the corporate theme, but when I switch to the corporate theme the problem persists. Using the default theme does not cause the problem due to the value of $this->load->_ci_view_path being a string rather than the array of custom theme and fall-back default.

    As for the upgrade, I honestly don’t recall which update docs I followed but I’ll take another look.

  • #8 / Feb 14, 2011 9:29am

    Sue Crocker

    26054 posts

    Hi, Ian.

    None of the accessories that ship with EE 2.1.4 beta have load_package_css in there, do you have an example accessory that does?

  • #9 / Feb 14, 2011 9:37am

    Ian from Aus

    94 posts

    The “recent entries” accessory (http://www.vayadesign.net/code/addon/recent_entries_accessory) is one of the accessories I was using that caused the issue.

    I have filed a bug for this specific issue here: https://support.ellislab.com/bugs/detail/15252/, and the developer of this accessory has filed one (which is marked as ‘fixed in beta’) here: https://support.ellislab.com/bugs/detail/14856/

  • #10 / Feb 14, 2011 10:28am

    Sue Crocker

    26054 posts

    Thanks for the listings for the recent accessory issue - just tested it on 2.1.4 beta - and no issues. So I’m going to close this issue since it’s in the bug tracker and fixed for the next release.

    Don’t hesitate to post again as needed.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases