public function testConnection() { $exportDirectory = $this->_fixBasePath($this->getDestination()->getPath()); $testResult = new Varien_Object(); // Check for forbidden folders $forbiddenFolders = array(Mage::getBaseDir('base'), Mage::getBaseDir('base') . DS . 'downloader'); foreach ($forbiddenFolders as $forbiddenFolder) { if (@realpath($exportDirectory) == $forbiddenFolder) { return $testResult->setSuccess(false)->setMessage(Mage::helper('xtento_orderexport')->__('It is not allowed to save export files in the directory you have specified. Please change the local export directory to be located in the ./var/ folder for example. Do not use the Magento root directory for example.')); } } if (!is_dir($exportDirectory) && !preg_match('/%exportid%/', $exportDirectory)) { // Try to create the directory. if (!@mkdir($exportDirectory)) { return $testResult->setSuccess(false)->setMessage(Mage::helper('xtento_orderexport')->__('The specified local directory does not exist. We could not create it either. Please make sure the parent directory is writable or create the directory manually: %s', $exportDirectory)); } else { $testResult->setDirectoryCreated(true); } } $this->_connection = @opendir($exportDirectory); if (!$this->_connection || @(!is_writable($exportDirectory))) { return $testResult->setSuccess(false)->setMessage(Mage::helper('xtento_orderexport')->__('Could not open local export directory for writing. Please make sure that we have rights to read and write in the directory: %s', $exportDirectory)); } if ($testResult->getDirectoryCreated()) { $testResult->setSuccess(true)->setMessage(Mage::helper('xtento_orderexport')->__('Local directory didn\'t exist and was created successfully. Connection tested successfully.')); if (!$this->getDestination()->getBackupDestination()) { $this->getDestination()->setLastResult($testResult->getSuccess())->setLastResultMessage($testResult->getMessage())->save(); } return $testResult; } else { $testResult->setSuccess(true)->setMessage(Mage::helper('xtento_orderexport')->__('Local directory exists and is writable. Connection tested successfully.')); if (!$this->getDestination()->getBackupDestination()) { $this->getDestination()->setLastResult($testResult->getSuccess())->setLastResultMessage($testResult->getMessage())->save(); } return $testResult; } }
/** * Saving tag and relation between tag, customer, product and store */ public function saveAction() { $customerSession = Mage::getSingleton('customer/session'); if (!$customerSession->authenticate($this)) { return; } $tagName = (string) $this->getRequest()->getQuery('productTagName'); $productId = (int) $this->getRequest()->getParam('product'); if (strlen($tagName) && $productId) { $session = Mage::getSingleton('catalog/session'); $product = Mage::getModel('catalog/product')->load($productId); if (!$product->getId()) { $session->addError($this->__('Unable to save tag(s).')); } else { try { $customerId = $customerSession->getCustomerId(); $storeId = Mage::app()->getStore()->getId(); $tagNamesArr = $this->_cleanTags($this->_extractTags($tagName)); $counter = new Varien_Object(array("new" => 0, "exist" => array(), "success" => array(), "recurrence" => array())); $tagModel = Mage::getModel('tag/tag'); $tagRelationModel = Mage::getModel('tag/tag_relation'); foreach ($tagNamesArr as $tagName) { $tagModel->unsetData()->loadByName($tagName)->setStoreId($storeId)->setName($tagName); $tagRelationModel->unsetData()->setStoreId($storeId)->setProductId($productId)->setCustomerId($customerId)->setActive(1)->setCreatedAt($tagRelationModel->getResource()->formatDate(time())); if (!$tagModel->getId()) { $tagModel->setFirstCustomerId($customerId)->setFirstStoreId($storeId)->setStatus($tagModel->getPendingStatus())->save(); $tagRelationModel->setTagId($tagModel->getId())->save(); $counter->setNew($counter->getNew() + 1); } else { $tagStatus = $tagModel->getStatus(); $tagRelationModel->setTagId($tagModel->getId()); switch ($tagStatus) { case $tagModel->getApprovedStatus(): if ($this->_checkLinkBetweenTagProduct($tagRelationModel)) { if (!$this->_checkLinkBetweenTagCustomerProduct($tagRelationModel, $tagModel)) { $tagRelationModel->save(); } $counter->setExist(array_merge($counter->getExist(), array($tagName))); } else { $tagRelationModel->save(); $counter->setSuccess(array_merge($counter->getSuccess(), array($tagName))); } break; case $tagModel->getPendingStatus(): if (!$this->_checkLinkBetweenTagCustomerProduct($tagRelationModel, $tagModel)) { $tagRelationModel->save(); } $counter->setNew($counter->getNew() + 1); break; case $tagModel->getDisabledStatus(): if ($this->_checkLinkBetweenTagCustomerProduct($tagRelationModel, $tagModel)) { $counter->setRecurrence(array_merge($counter->getRecurrence(), array($tagName))); } else { $tagModel->setStatus($tagModel->getPendingStatus())->save(); $tagRelationModel->save(); $counter->setNew($counter->getNew() + 1); } break; } } } $this->_fillMessageBox($counter); } catch (Exception $e) { Mage::logException($e); $session->addError($this->__('Unable to save tag(s).')); } } } $this->_redirectReferer(); }