/** * Save uploaded file before saving config value * * @return Mage_Backend_Model_Config_Backend_File */ protected function _beforeSave() { $value = $this->getValue(); $tmpName = $this->_requestData->getTmpName($this->getPath()); if ($tmpName) { $uploadDir = $this->_getUploadDir(); try { $file = array(); $file['tmp_name'] = $tmpName; $file['name'] = $this->_requestData->getName($this->getPath()); $uploader = new Mage_Core_Model_File_Uploader($file); $uploader->setAllowedExtensions($this->_getAllowedExtensions()); $uploader->setAllowRenameFiles(true); $uploader->addValidateCallback('size', $this, 'validateMaxSize'); $result = $uploader->save($uploadDir); } catch (Exception $e) { Mage::throwException($e->getMessage()); return $this; } $filename = $result['file']; if ($filename) { if ($this->_addWhetherScopeInfo()) { $filename = $this->_prependScopeInfo($filename); } $this->setValue($filename); } } else { if (is_array($value) && !empty($value['delete'])) { $this->setValue(''); } else { $this->unsValue(); } } return $this; }
public function testGetNameReturnsNullIfInvalidPathIsProvided() { $this->assertNull($this->_model->getName('section_1/group_2/field_1')); $this->assertNull($this->_model->getName('section_1/group_3/field_1')); $this->assertNull($this->_model->getName('section_1/group_1/field_2')); $this->assertNull($this->_model->getName('section_1/group_1')); }