0

During my research on question 2 module setup scripts dependence I tested following: I tried to update already created category in module setup file (mysql4-install-0.1.0.php):

$installer = $this;
$installer->startSetup();
$defaultCategory = Mage::getModel('catalog/category')->load(3);
$defaultCategory->setData(array('cool_new_attribute' => 'cool_value', 'name' => 'test'))->save();
$installer->endSetup();

But this line creates new category instead of updating old category. And in system.log file appended following error trace:

exception 'Exception' with message '$_FILES array is empty' in Z:\home\magento.ce\www\lib\Varien\File\Uploader.php:467
Stack trace:
#0 Z:\home\magento.ce\www\lib\Varien\File\Uploader.php(149): Varien_File_Uploader->_setUploadFileId('thumbnail')
#1 Z:\home\magento.ce\www\app\code\core\Mage\Catalog\Model\Category\Attribute\Backend\Image.php(57): Varien_File_Uploader->__construct('thumbnail')
#2 [internal function]: Mage_Catalog_Model_Category_Attribute_Backend_Image->afterSave(Object(Mage_Catalog_Model_Category))
#3 Z:\home\magento.ce\www\app\code\core\Mage\Eav\Model\Entity\Abstract.php(657): call_user_func_array(Array, Array)
#4 Z:\home\magento.ce\www\app\code\core\Mage\Eav\Model\Entity\Abstract.php(1648): Mage_Eav_Model_Entity_Abstract->walkAttributes('backend/afterSa...', Array)
#5 Z:\home\magento.ce\www\app\code\core\Mage\Catalog\Model\Resource\Category.php(235): Mage_Eav_Model_Entity_Abstract->_afterSave(Object(Mage_Catalog_Model_Category))
#6 Z:\home\magento.ce\www\app\code\core\Mage\Eav\Model\Entity\Abstract.php(1124): Mage_Catalog_Model_Resource_Category->_afterSave(Object(Mage_Catalog_Model_Category))
#7 Z:\home\magento.ce\www\app\code\core\Mage\Core\Model\Abstract.php(318): Mage_Eav_Model_Entity_Abstract->save(Object(Mage_Catalog_Model_Category))
#8 Z:\home\magento.ce\www\app\code\local\Test0\Test0\sql\test0_test0_setup\mysql4-install-0.1.0.php(13): Mage_Core_Model_Abstract->save()
#9 Z:\home\magento.ce\www\app\code\core\Mage\Core\Model\Resource\Setup.php(624): include('Z:\home\magento...')
#10 Z:\home\magento.ce\www\app\code\core\Mage\Core\Model\Resource\Setup.php(421): Mage_Core_Model_Resource_Setup->_modifyResourceDb('install', '', '0.1.0')
#11 Z:\home\magento.ce\www\app\code\core\Mage\Core\Model\Resource\Setup.php(327): Mage_Core_Model_Resource_Setup->_installResourceDb('0.1.0')
#12 Z:\home\magento.ce\www\app\code\core\Mage\Core\Model\Resource\Setup.php(235): Mage_Core_Model_Resource_Setup->applyUpdates()
#13 Z:\home\magento.ce\www\app\code\core\Mage\Core\Model\App.php(417): Mage_Core_Model_Resource_Setup::applyAllUpdates()
#14 Z:\home\magento.ce\www\app\code\core\Mage\Core\Model\App.php(343): Mage_Core_Model_App->_initModules()
#15 Z:\home\magento.ce\www\app\Mage.php(685): Mage_Core_Model_App->run(Array)
#16 Z:\home\magento.ce\www\index.php(93): Mage::run('', 'store')
#17 {main}

How I can update the category during module setup, or I am doing something wrong?

1

You should load your category like this:

$defaultCategory = Mage::getModel('catalog/category')->setStoreId(0)->load(3);

The install scripts always run under the assumption you are on store id 1. This may be causing your problem. Also make sure that the category with id 3 exists (just in case).
And to overcome the errors in the exception.log add this at the top of your code.

$_FILES = array();
$_FILES['image']['tmp_name'] = '';
$_FILES['thumbnail']['tmp_name'] = '';

The error appears because of this code in Varien_File_Uploader::_setUploadFileId.

if (empty($_FILES)) {
   throw new Exception('$_FILES array is empty');
}

That method is called by the backend model of the image and thumbnail attributes from the category entity.
This looks like a feature, but it looks more like a bug to me.
It is assuming that you are always going to save a category via browser.
I think the file upload should be handled in the controller and just add the image name to the category instance.

  • I completely agree to your answer, I also tracked the error same with you mentioned. Thank you. Maybe this bug already handled in CE 1.8, I will test it – mageUz Jan 23 '14 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.