Skip to content

Check if users before attempting to access #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2015

Conversation

ckrazoyo
Copy link

Updated previously existing Magento Zendesk extension to this version, afterwords Magento admin panel threw following error. Resolved by wrapping statement in if(users) to ensure there are users before attempting to continue.

Client on EE Magento ver. 1.13.1.0

Warning: array_filter() expects parameter 1 to be array, null given in /home/client/pinupgirl/env/stage/www/mage/app/code/community/Zendesk/Zendesk/Block/Adminhtml/Dashboard/Tab/Tickets/Grid/Renderer/Email.php on line 27

#0 [internal function]: mageCoreErrorHandler(2, 'array_filter() ...', '/home/client/pi...', 27, Array) 
#1 /home/client/pinupgirl/env/stage/www/mage/app/code/community/Zendesk/Zendesk/Block/Adminhtml/Dashboard/Tab/Tickets/Grid/Renderer/Email.php(27): array_filter(NULL, Object(Closure)) 
#2 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column.php(128): Zendesk_Zendesk_Block_Adminhtml_Dashboard_Tab_Tickets_Grid_Renderer_Email->render(Object(Varien_Object)) 
#3 /home/client/pinupgirl/env/stage/www/mage/app/design/adminhtml/default/default/template/zendesk/widget/grid.phtml(162): Mage_Adminhtml_Block_Widget_Grid_Column->getRowField(Object(Varien_Object)) 
#4 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Core/Block/Template.php(241): include('/home/client/pi...') 
#5 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Core/Block/Template.php(272): Mage_Core_Block_Template->fetchView('adminhtml/defau...') 
#6 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Core/Block/Template.php(286): Mage_Core_Block_Template->renderView() 
#7 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Adminhtml/Block/Template.php(81): Mage_Core_Block_Template->_toHtml() 
#8 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Core/Block/Abstract.php(919): Mage_Adminhtml_Block_Template->_toHtml() 
#9 /home/client/pinupgirl/env/stage/www/mage/app/code/community/Zendesk/Zendesk/Block/Adminhtml/Dashboard/Grids.php(50): Mage_Core_Block_Abstract->toHtml()
#10 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Core/Block/Abstract.php(293): Zendesk_Zendesk_Block_Adminhtml_Dashboard_Grids->_prepareLayout() 
#11 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Core/Model/Layout.php(456): Mage_Core_Block_Abstract->setLayout(Object(Mage_Core_Model_Layout)) 
#12 /home/client/pinupgirl/env/stage/www/mage/app/code/community/Zendesk/Zendesk/Model/Observer.php(44): Mage_Core_Model_Layout->createBlock('zendesk/adminht...') 
#13 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Core/Model/App.php(1338): Zendesk_Zendesk_Model_Observer->insertBlock(Object(Varien_Event_Observer)) 
#14 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Core/Model/App.php(1317): Mage_Core_Model_App->_callObserverMethod(Object(Zendesk_Zendesk_Model_Observer), 'insertBlock', Object(Varien_Event_Observer)) 
#15 /home/client/pinupgirl/env/stage/www/mage/app/Mage.php(448): Mage_Core_Model_App->dispatchEvent('core_block_abst...', Array) 
#16 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Core/Block/Abstract.php(943): Mage::dispatchEvent('core_block_abst...', Array) 
#17 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Core/Block/Abstract.php(637): Mage_Core_Block_Abstract->toHtml() 
#18 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Core/Block/Abstract.php(581): Mage_Core_Block_Abstract->_getChildHtml('totals', true) 
#19 /home/client/pinupgirl/env/stage/www/mage/app/design/adminhtml/default/default/template/dashboard/index.phtml(123): Mage_Core_Block_Abstract->getChildHtml('totals') 
#20 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Core/Block/Template.php(241): include('/home/client/pi...') 
#21 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Core/Block/Template.php(272): Mage_Core_Block_Template->fetchView('adminhtml/defau...') 
#22 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Core/Block/Template.php(286): Mage_Core_Block_Template->renderView() 
#23 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Adminhtml/Block/Template.php(81): Mage_Core_Block_Template->_toHtml() 
#24 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Core/Block/Abstract.php(919): Mage_Adminhtml_Block_Template->_toHtml() 
#25 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Core/Block/Text/List.php(43): Mage_Core_Block_Abstract->toHtml() 
#26 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Core/Block/Abstract.php(919): Mage_Core_Block_Text_List->_toHtml() 
#27 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Core/Block/Abstract.php(637): Mage_Core_Block_Abstract->toHtml() 
#28 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Core/Block/Abstract.php(581): Mage_Core_Block_Abstract->_getChildHtml('content', true) 
#29 /home/client/pinupgirl/env/stage/www/mage/app/design/adminhtml/default/default/template/page.phtml(74): Mage_Core_Block_Abstract->getChildHtml('content') 
#30 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Core/Block/Template.php(241): include('/home/client/pi...') 
#31 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Core/Block/Template.php(272): Mage_Core_Block_Template->fetchView('adminhtml/defau...') 
#32 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Core/Block/Template.php(286): Mage_Core_Block_Template->renderView() 
#33 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Adminhtml/Block/Template.php(81): Mage_Core_Block_Template->_toHtml() 
#34 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Core/Block/Abstract.php(919): Mage_Adminhtml_Block_Template->_toHtml() 
#35 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Core/Model/Layout.php(555): Mage_Core_Block_Abstract->toHtml() 
#36 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Core/Controller/Varien/Action.php(390): Mage_Core_Model_Layout->getOutput() 
#37 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Adminhtml/controllers/DashboardController.php(43): Mage_Core_Controller_Varien_Action->renderLayout() 
#38 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Mage_Adminhtml_DashboardController->indexAction() 
#39 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('index') 
#40 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http)) 
#41 /home/client/pinupgirl/env/stage/www/mage/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch() 
#42 /home/client/pinupgirl/env/stage/www/mage/app/Mage.php(684): Mage_Core_Model_App->run(Array) 
#43 /home/client/pinupgirl/env/stage/www/mage/index.php(104): Mage::run('default', 'store') 
#44 {main}

@jwswj
Copy link
Contributor

jwswj commented May 19, 2015

@ckrazoyo what version are you running now? master from Github or a specific version from Magento connect?

@ckrazoyo
Copy link
Author

Hello,
Currently the client is running master from Github. He already had a
Zendesk extension installed, but it was several months old at least and it
is unknown who installed or how it was installed. He was informed that he
should install the latest version from github due to a different issue and
his communication with Zendesk support.

Thanks,
Chris

On Tue, May 19, 2015 at 11:38 AM, Jason Smale notifications@github.com
wrote:

@ckrazoyo https://github.com/ckrazoyo what version are you running now?
master from Github or a specific version from Magento connect?


Reply to this email directly or view it on GitHub
#66 (comment)
.

@ckrazoyo
Copy link
Author

Hi,
So there is some fix for that? My code was really just to get it up and
running rather then bringing the entire admin panel to a halt. I
anticipated the client continuing his support discussion with Zendesk, but
instead he was instructed to put this in as a pull request.

Thanks,
Chris

On Wed, May 20, 2015 at 4:20 PM, Chris Kendall ckendall@razoyo.com wrote:

Hello,
Currently the client is running master from Github. He already had a
Zendesk extension installed, but it was several months old at least and it
is unknown who installed or how it was installed. He was informed that he
should install the latest version from github due to a different issue and
his communication with Zendesk support.

Thanks,
Chris

On Tue, May 19, 2015 at 11:38 AM, Jason Smale notifications@github.com
wrote:

@ckrazoyo https://github.com/ckrazoyo what version are you running
now? master from Github or a specific version from Magento connect?


Reply to this email directly or view it on GitHub
#66 (comment)
.

@jwswj
Copy link
Contributor

jwswj commented May 24, 2015

Thanks for providing the PR. We'll be reviewing it this week.

@joseconsador
Copy link
Contributor

👍 we can bundle this with the next release. I see nothing wrong with the code, quite similar to our previous fixes. Just want to note that the extension has only been tested up to Enterprise Edition 1.12 .
/cc @miogalang @mmolina


if( count($found) ) {

if ($users) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we Just enclose the whole thing in the if block to save on checks?

  if ($users) {
    $found = array_filter($users, function($user) use($value) {
      return (int) $user['id'] === $value;
    });

    if( count($found) ) {
      $user = array_shift($found);
      return $user['email'];
    }
  }
return '';
}

Also can we remove the whitespaces at the end of lines 37, 39, 40

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As closure functions are supported from PHP >= 5.3.0, I would discourage to use them within Magento code as they are not used anywhere else. It does make use of create_function() or you could just simply iterate over the array with foreach and return $user['email'] when the right user ID was found.

jwswj pushed a commit that referenced this pull request Aug 7, 2015
Check if users before attempting to access
@jwswj jwswj merged commit 7c916e4 into agnostack:master Aug 7, 2015
@jwswj
Copy link
Contributor

jwswj commented Aug 7, 2015

Thanks @ckrazoyo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants