0

I'm trying to debug my install script with no effort. When I try to get any output inside my foreach loop there is no result in my Mage::Log() file.

<?php
$installer = $this;
$installer->startSetup();
$attrCodes = ['attr1', 'attr2', 'attr3'];
$objCatalogEavSetup = Mage::getResourceModel('catalog/eav_mysql4_setup', 'core_setup');

Mage::log('hello before foreach');
// get all attributes
foreach ($attrCodes as $attrCode) {
  Mage::log('Attribute code: ' . $attrCode);
}

Mage::log('hello after foreach');
$installer->endSetup();

I can see the log info before the foreach loop. But I got no info inside or after that loop.

Isn't it possible to debug an install script? I usually work with PHPStorm and use the internal debugger. But it seems that I'm unable to debug an install script with PHPStorm or with Mage::Log().

EDIT:
I'm totally sorry for this mess.
I didn't give credits to the comment line above the loop so I decided to shorten my code here.
But the truth is I can't call my upgrade script with a line comment.
That is the reason for my problem. I have to change a line comment to a block comment /**/ and now it works.

Never run into this problem with magento before.

Timo.Klement
  • 655
  • 1
  • 11
  • 31
  • 1
    You said you can see the log before the foreach but more importantly, do you see the info **after** the foreach ? If not then, it means you have to error **in** the foreach. – β.εηοιτ.βε Feb 02 '15 at 10:35

2 Answers2

0

Agree, with "Tipo", the problem is in the foreach loop. You should try this edit, when you create the array:

$attrCodes = array('attr1', 'attr2', 'attr3');
imso077
  • 311
  • 3
  • 4
  • I don't think so. If the new array `[]` notation was not recognised by his server, the OP would have an error **before** the first `Mage::log` – β.εηοιτ.βε Feb 02 '15 at 11:57
  • 1
    If not recognized, then he will get just a warning or notice, not an error, but if he pass a variable to foreach what is not an array, he get an error... – imso077 Feb 02 '15 at 12:07
  • Mhm, just tested and you are totally right. I excepted something like `unexpected [` from the parser. – β.εηοιτ.βε Feb 02 '15 at 12:28
0

Try This Code and check :

$attrCodes = array('attr1', 'attr2', 'attr3');
Mage::log('hello before foreach');
foreach ($attrCodes as $attrCode) {
    Mage::log('Attribute code: ' . $attrCode);
}
Mage::log('hello after foreach');
Suresh Chikani
  • 948
  • 2
  • 9
  • 23