本文整理汇总了PHP中Varien_Io_File::isWriteable方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Io_File::isWriteable方法的具体用法?PHP Varien_Io_File::isWriteable怎么用?PHP Varien_Io_File::isWriteable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_Io_File
的用法示例。
在下文中一共展示了Varien_Io_File::isWriteable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createModule
public function createModule($data)
{
$namespace = $this->_cleanString($data['namespace']);
$module = $this->_cleanString($data['module']);
$pool = $data['pool'];
$version = $this->_cleanString($data['version']);
$dependencies = array();
if (isset($data['depends'])) {
foreach ($data['depends'] as $dependency) {
$dependencies[] = sprintf('%s<%s />', str_repeat(' ', 4 * 4), $dependency);
}
}
$replacements = array('{{Namespace}}' => $namespace, '{{namespace}}' => strtolower($namespace), '{{Module}}' => $module, '{{module}}' => strtolower($module), '{{pool}}' => $pool, '{{version}}' => $version, '{{depends}}' => implode(PHP_EOL, $dependencies));
$io = new Varien_Io_File();
$tplDir = $this->getTemplateDir();
$tmpDir = $this->getTmpModuleDir($namespace . '_' . $module);
$io->checkAndCreateFolder($tmpDir);
if (!$io->isWriteable($tmpDir)) {
Mage::throwException('Module temp dir is not writeable');
}
@shell_exec("cp -r {$tplDir} {$tmpDir}");
$files = $this->_getTemplateFiles($tmpDir);
if (empty($files)) {
Mage::throwException('Could not copy templates files to module temp dir');
}
$this->_replaceVars($tmpDir, $replacements);
$dest = Mage::getBaseDir();
if (!$io->isWriteable($dest)) {
Mage::throwException(sprintf('Could not move module files to Magento tree. However, module structure is available in %s', $tmpDir));
}
@shell_exec("cp -r {$tmpDir} {$dest}");
return true;
}
示例2: checkFolderPermissionsErrors
/**
* Check is folders exist and have writable permissions
*
* @return string Error message if exist
*/
public function checkFolderPermissionsErrors()
{
$arrFolders = array('image_dir' => Mage::getConfig()->getOptions()->getMediaDir() . DS . Mage::helper('nwdrevslider/images')->getImageDir(), 'thumb_dir' => Mage::getConfig()->getOptions()->getMediaDir() . DS . Mage::helper('nwdrevslider/images')->getImageThumbDir(), 'admin_css_dir' => Mage::getBaseDir() . Mage::helper('nwdrevslider/css')->getAdminCssDir(), 'front_css_dir' => Mage::getBaseDir() . Mage::helper('nwdrevslider/css')->getFrontCssDir());
$ioFile = new Varien_Io_File();
$arrErrors = array();
foreach ($arrFolders as $_folder) {
try {
if (!($ioFile->checkandcreatefolder($_folder) && $ioFile->isWriteable($_folder))) {
$arrErrors[] = $_folder;
}
} catch (Exception $e) {
$arrErrors[] = $_folder;
Mage::logException($e);
}
}
if (!(in_array($arrFolders['admin_css_dir'], $arrErrors) || in_array($arrFolders['front_css_dir'], $arrErrors))) {
if (!file_exists($arrFolders['admin_css_dir'] . 'statics.css')) {
Mage::helper('nwdrevslider/css')->putStaticCss();
}
if (!file_exists($arrFolders['admin_css_dir'] . 'dynamic.css')) {
Mage::helper('nwdrevslider/css')->putDynamicCss();
}
}
$strError = $arrErrors ? Mage::helper('nwdrevslider')->__('Following directories not found or not writable, please change permissions to: ') . implode(' , ', $arrErrors) : '';
return $strError;
}
示例3: createIndexSitemapFile
/**
* Create additional xml index file with links to other xml files (if number of them more than 1)
*/
public function createIndexSitemapFile()
{
if (sizeof($this->filenamesForIndexSitemap) > 1) {
$io = new Varien_Io_File();
$io->setAllowCreateFolders(true);
$io->open(array('path' => $this->getPath()));
$fileToCreate = Mage::helper('ascurl')->insertStringToFilename($this->getSitemapFilename(), '_index');
if ($io->fileExists($fileToCreate) && !$io->isWriteable($fileToCreate)) {
Mage::throwException(Mage::helper('sitemap')->__('File "%s" cannot be saved. Please, make sure the directory "%s" is writeable by web server.', $fileToCreate, $this->getPath()));
}
$io->streamOpen($fileToCreate);
$io->streamWrite('<?xml version="1.0" encoding="UTF-8"?>' . "\n");
$io->streamWrite('<sitemapindex ' . self::URLSET . '>');
$storeId = $this->getStoreId();
$baseUrl = Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
$date = Mage::getSingleton('core/date')->gmtDate('Y-m-d');
$path = $this->getSitemapPath();
$fullPath = preg_replace('/(?<=[^:])\\/{2,}/', '/', $baseUrl . $path);
foreach ($this->filenamesForIndexSitemap as $item) {
$xml = sprintf('<sitemap><loc>%s</loc><lastmod>%s</lastmod></sitemap>', htmlspecialchars($fullPath . $item), $date);
$io->streamWrite($xml);
}
$io->streamWrite('</sitemapindex>');
$io->streamClose();
}
}
示例4: generateXml
public function generateXml()
{
$io = new Varien_Io_File();
$io->setAllowCreateFolders(true);
$io->open(array('path' => $this->getPath()));
if ($io->fileExists($this->getSitemapFilename()) && !$io->isWriteable($this->getSitemapFilename())) {
Mage::throwException(Mage::helper('sitemap')->__('File "%s" cannot be saved. Please, make sure the directory "%s" is writeable by web server.', $this->getSitemapFilename(), $this->getPath()));
}
$io->streamOpen($this->getSitemapFilename());
$io->streamWrite('<?xml version="1.0" encoding="UTF-8"?>' . "\n");
$io->streamWrite('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
$storeId = $this->getStoreId();
$date = Mage::getSingleton('core/date')->gmtDate('Y-m-d');
$baseUrl = Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
// Generate filterurl sitemap
$changefreq = (string) Mage::getStoreConfig('sitemap/category/changefreq', $storeId);
$priority = (string) Mage::getStoreConfig('sitemap/category/priority', $storeId);
/* @var $collection Flagbit_FilterUrls_Model_Resource_Mysql4_Url_Collection */
$collection = Mage::getModel('filterurls/url')->getCollection();
$collection->addFieldToFilter('store_id', $storeId);
foreach ($collection as $item) {
$xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>', htmlspecialchars($baseUrl . $item->getRequestPath()), $date, $changefreq, $priority);
$io->streamWrite($xml . PHP_EOL);
}
$io->streamWrite('</urlset>');
$io->streamClose();
$this->setSitemapTime(Mage::getSingleton('core/date')->gmtDate('Y-m-d H:i:s'));
$this->save();
return $this;
}
示例5: _beforeSave
protected function _beforeSave()
{
$io = new Varien_Io_File();
$realPath = $io->getCleanPath($this->getPath());
/**
* Check path is allow
*/
if (!$io->allowedPath($realPath, Mage::getBaseDir())) {
Mage::throwException(Mage::helper('sitemap')->__('Please define correct path'));
}
/**
* Check exists and writeable path
*/
if (!$io->fileExists($realPath, false)) {
Mage::throwException(Mage::helper('sitemap')->__('Please create the specified folder "%s" before saving the sitemap.', Mage::helper('core')->htmlEscape($this->getPreparedFilename())));
}
if (!$io->isWriteable($realPath)) {
Mage::throwException(Mage::helper('sitemap')->__('Please make sure that "%s" is writable by web-server.', $this->getPreparedFilename()));
}
/**
* Check allow filename
*/
if (!preg_match('#\\.xml$#', $this->getSitemapFilename())) {
$this->setSitemapFilename($this->getSitemapFilename() . '.xml');
}
$this->setSitemapPath(rtrim(str_replace(str_replace('\\', '/', Mage::getBaseDir()), '', $realPath), '/') . '/');
return parent::_beforeSave();
}
示例6: generateXml
/**
* Generate XML file
*
* @return Mage_Sitemap_Model_Sitemap
*/
public function generateXml()
{
$io = new Varien_Io_File();
$io->setAllowCreateFolders(true);
$io->open(array('path' => $this->getPath()));
if ($io->fileExists($this->getSitemapFilename()) && !$io->isWriteable($this->getSitemapFilename())) {
Mage::throwException(Mage::helper('sitemap')->__('File "%s" cannot be saved. Please, make sure the directory "%s" is writeable by web server.', $this->getSitemapFilename(), $this->getPath()));
}
$io->streamOpen($this->getSitemapFilename());
$io->streamWrite('<?xml version="1.0" encoding="UTF-8"?>' . "\n");
$io->streamWrite('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:content="http://www.google.com/schemas/sitemap-content/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">' . "\n");
$storeId = $this->getStoreId();
$date = Mage::getSingleton('core/date')->gmtDate('Y-m-d');
$baseUrl = Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
// Hans2103 change -> set mediaUrl
$mediaUrl = Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
$mediaUrl = preg_replace('/^https/', 'http', $mediaUrl);
/**
* Generate categories sitemap
*/
$changefreq = (string) Mage::getStoreConfig('sitemap/category/changefreq', $storeId);
$priority = (string) Mage::getStoreConfig('sitemap/category/priority', $storeId);
$collection = Mage::getResourceModel('sitemap/catalog_category')->getCollection($storeId);
foreach ($collection as $item) {
$xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>' . "\n", htmlspecialchars($baseUrl . $item->getUrl()), $date, $changefreq, $priority);
$io->streamWrite($xml);
$this->check_counter($io);
}
unset($collection);
/**
* Generate products sitemap
*/
/**
* override to include images in sitemap
*/
$changefreq = (string) Mage::getStoreConfig('sitemap/product/changefreq', $storeId);
$priority = (string) Mage::getStoreConfig('sitemap/product/priority', $storeId);
$collection = Mage::getResourceModel('sitemap/catalog_product')->getCollection($storeId);
foreach ($collection as $item) {
$xml = sprintf('<url><loc>%s</loc><image:image><image:loc>%s</image:loc><image:title>%s</image:title></image:image><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority><PageMap xmlns="http://www.google.com/schemas/sitemap-pagemap/1.0"><DataObject type="thumbnail"><Attribute name="name" value="%s"/><Attribute name="src" value="%s"/></DataObject></PageMap></url>' . "\n", htmlspecialchars($baseUrl . $item->getUrl()), htmlspecialchars($mediaUrl . 'catalog/product' . $item->getMedia()), htmlspecialchars($item->getName()), $date, $changefreq, $priority, htmlspecialchars($item->getName()), htmlspecialchars($mediaUrl . 'catalog/product' . $item->getMedia()));
$io->streamWrite($xml);
}
unset($collection);
/**
* Generate cms pages sitemap
*/
$changefreq = (string) Mage::getStoreConfig('sitemap/page/changefreq', $storeId);
$priority = (string) Mage::getStoreConfig('sitemap/page/priority', $storeId);
$collection = Mage::getResourceModel('sitemap/cms_page')->getCollection($storeId);
foreach ($collection as $item) {
$xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>' . "\n", htmlspecialchars($baseUrl . $item->getUrl()), $date, $changefreq, $priority);
$io->streamWrite($xml);
}
unset($collection);
$io->streamWrite('</urlset>');
$io->streamClose();
$this->setSitemapTime(Mage::getSingleton('core/date')->gmtDate('Y-m-d H:i:s'));
$this->save();
return $this;
}
示例7: generateXml
/**
* Generate sitemap XML file - override to dispatch more events
*
* @return $this|Mage_Sitemap_Model_Sitemap
*/
public function generateXml()
{
$io = new Varien_Io_File();
$io->setAllowCreateFolders(true);
$io->open(array('path' => $this->getPath()));
if ($io->fileExists($this->getSitemapFilename()) && !$io->isWriteable($this->getSitemapFilename())) {
Mage::throwException(Mage::helper('sitemap')->__('File "%s" cannot be saved. Please, make sure the directory "%s" is writeable by web server.', $this->getSitemapFilename(), $this->getPath()));
}
$io->streamOpen($this->getSitemapFilename());
$io->streamWrite('<?xml version="1.0" encoding="UTF-8"?>' . "\n");
$io->streamWrite('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
$storeId = $this->getStoreId();
$date = Mage::getSingleton('core/date')->gmtDate('Y-m-d');
$baseUrl = Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
/**
* Generate categories sitemap
*/
$changefreq = (string) Mage::getStoreConfig('sitemap/category/changefreq', $storeId);
$priority = (string) Mage::getStoreConfig('sitemap/category/priority', $storeId);
$collection = Mage::getResourceModel('sitemap/catalog_category')->getCollection($storeId);
$categories = new Varien_Object();
$categories->setItems($collection);
Mage::dispatchEvent('sitemap_categories_generating_before', array('collection' => $categories));
foreach ($categories->getItems() as $item) {
$xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>', htmlspecialchars($baseUrl . $item->getUrl()), $date, $changefreq, $priority);
$io->streamWrite($xml);
}
unset($collection);
/**
* Generate products sitemap
*/
$changefreq = (string) Mage::getStoreConfig('sitemap/product/changefreq', $storeId);
$priority = (string) Mage::getStoreConfig('sitemap/product/priority', $storeId);
$collection = Mage::getResourceModel('sitemap/catalog_product')->getCollection($storeId);
$products = new Varien_Object();
$products->setItems($collection);
Mage::dispatchEvent('sitemap_products_generating_before', array('collection' => $products));
foreach ($products->getItems() as $item) {
$xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>', htmlspecialchars($baseUrl . $item->getUrl()), $date, $changefreq, $priority);
$io->streamWrite($xml);
}
unset($collection);
/**
* Generate cms pages sitemap
*/
$changefreq = (string) Mage::getStoreConfig('sitemap/page/changefreq', $storeId);
$priority = (string) Mage::getStoreConfig('sitemap/page/priority', $storeId);
$collection = Mage::getResourceModel('sitemap/cms_page')->getCollection($storeId);
foreach ($collection as $item) {
$xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>', htmlspecialchars($baseUrl . $item->getUrl()), $date, $changefreq, $priority);
$io->streamWrite($xml);
}
unset($collection);
$io->streamWrite('</urlset>');
$io->streamClose();
$this->setSitemapTime(Mage::getSingleton('core/date')->gmtDate('Y-m-d H:i:s'));
$this->save();
return $this;
}
示例8: checkFilePermissions
public function checkFilePermissions()
{
$io = new Varien_Io_File();
$io->checkAndCreateFolder($this->local_dir);
if (!$io->isWriteable($this->local_dir)) {
return 'folder is not writable';
}
return '';
}
示例9: isDirectoryWriteable
public function isDirectoryWriteable()
{
$base_dir = Mage::getBaseDir() . DS;
$file = new Varien_Io_File();
if ($file->isWriteable($base_dir)) {
return true;
} else {
return false;
}
}
示例10: _validateUploadedFile
/**
* Validate uploaded file
*
* @throws Mage_Core_Exception
* @return Mage_Catalog_Model_Product_Option_Type_File
*/
protected function _validateUploadedFile()
{
$option = $this->getOption();
if (Mage::helper('aitcg/options')->checkAitOption($option)) {
$values = Mage::app()->getRequest()->getParam('options');
$optionValue = $values[$option->getId()];
$runValidation = ($option->getIsRequire() || $this->_validateValue($option)) && !is_null($optionValue);
if (!$runValidation) {
$this->setUserValue(null);
return $this;
}
$optionValue = Mage::helper('core')->jsonDecode($optionValue);
$this->_initFilesystem();
$model = Mage::getModel('aitcg/image');
$src = Mage::getBaseDir('media') . DS . $model->getFullTempPath() . DS . $optionValue['config']['rand'] . '.' . Aitoc_Aitcg_Model_Image::FORMAT_PNG;
$fileName = Mage_Core_Model_File_Uploader::getCorrectFileName(pathinfo(strtolower($src), PATHINFO_FILENAME));
$dispersion = Mage_Core_Model_File_Uploader::getDispretionPath($fileName);
$filePath = $dispersion;
$fileHash = md5(file_get_contents($src));
$filePath .= DS . $fileHash . '.' . Aitoc_Aitcg_Model_Image::FORMAT_PNG;
$fileFullPath = $this->getQuoteTargetDir() . $filePath;
$_width = 0;
$_height = 0;
$_fileSize = 0;
if (is_readable($src)) {
$_imageSize = getimagesize($src);
if ($_imageSize) {
$_width = $_imageSize[0];
$_height = $_imageSize[1];
}
$_fileSize = filesize($src);
}
$manager = Mage::getModel('aitcg/image_manager');
$template_id = $manager->addImage($values[$option->getId()], Mage::app()->getRequest()->getParam('product'), $option->getId(), $option);
$this->setUserValue(array('type' => 'image/png', 'title' => 'custom_product_preview.png', 'quote_path' => $this->getQuoteTargetDir(true) . $filePath, 'order_path' => $this->getOrderTargetDir(true) . $filePath, 'fullpath' => $fileFullPath, 'size' => $_fileSize, 'width' => $_width, 'height' => $_height, 'secret_key' => substr($fileHash, 0, 20), Aitoc_Aitcg_Helper_Options::OPTION_DATA_KEY => array('template_id' => $template_id, Aitoc_Aitcg_Model_Sales_Order_Item_Converter::CUSTOMER_IMAGE_META_VERSION_KEY => Aitoc_Aitcg_Model_Sales_Order_Item_Converter::CUSTOMER_IMAGE_META_VERSION)));
$path = dirname($fileFullPath);
$io = new Varien_Io_File();
if (!$io->isWriteable($path) && !$io->mkdir($path, 0777, true)) {
Mage::throwException(Mage::helper('catalog')->__("Cannot create writeable directory '%s'.", $path));
}
@copy($src, $fileFullPath);
return $this;
} else {
return parent::_validateUploadedFile();
}
}
示例11: _createSitemap
/**
* Create new sitemap file
*
* @param string $fileName
* @param string $type
* @return void
*/
protected function _createSitemap($fileName = null, $type = self::TYPE_URL)
{
if (!$fileName) {
$this->_sitemapIncrement++;
$fileName = $this->_getCurrentSitemapFilename($this->_sitemapIncrement);
}
$this->_fileHandler = $this->_getFileObject();
$this->_fileHandler->setAllowCreateFolders(true);
$path = $this->_fileHandler->getCleanPath($this->_getBaseDir() . $this->getSitemapPath());
$this->_fileHandler->open(array('path' => $path));
if ($this->_fileHandler->fileExists($fileName) && !$this->_fileHandler->isWriteable($fileName)) {
Mage::throwException(Mage::helper('Mage_Sitemap_Helper_Data')->__('File "%s" cannot be saved. Please, make sure the directory "%s" is writable by web server.', $fileName, $path));
}
$fileHeader = sprintf($this->_tags[$type][self::OPEN_TAG_KEY], $type);
$this->_fileHandler->streamOpen($fileName);
$this->_fileHandler->streamWrite($fileHeader);
$this->_fileSize = strlen($fileHeader . sprintf($this->_tags[$type][self::CLOSE_TAG_KEY], $type));
}
示例12: _deactivateModule
protected function _deactivateModule()
{
$file = Mage::getBaseDir('etc') . DS . 'modules' . DS . 'Netzarbeiter_GroupsCatalog.xml';
$io = new Varien_Io_File();
if (!$io->fileExists($file)) {
$message = Mage::helper('netzarbeiter_groupscatalog2')->__("The file app/etc/modules/Netzarbeiter_GroupsCatalog.xml doesn't exist.");
Mage::throwException($message);
}
$xml = simplexml_load_file($file);
if (in_array((string) $xml->modules->Netzarbeiter_GroupsCatalog->active, array('true', '1'), true)) {
if (!$io->isWriteable($file)) {
$message = Mage::helper('netzarbeiter_groupscatalog2')->__('The file app/etc/modules/Netzarbeiter_GroupsCatalog.xml is not writable.<br/>' . 'Please fix it and flush the configuration cache, or deactivate the module manually in that file.');
Mage::throwException($message);
}
$xml->modules->Netzarbeiter_GroupsCatalog->active = 'false';
$xml->asXML($file);
Mage::app()->cleanCache(Mage_Core_Model_Config::CACHE_TAG);
}
}
示例13: _beforeSave
protected function _beforeSave()
{
$io = new Varien_Io_File();
$realPath = $io->getCleanPath(Mage::getBaseDir() . '/' . $this->getSitemapPath());
if (!$io->allowedPath($realPath, Mage::getBaseDir())) {
Mage::throwException(Mage::helper('xsitemap')->__('Please define correct path'));
}
if (!$io->fileExists($realPath, false)) {
Mage::throwException(Mage::helper('xsitemap')->__('Please create the specified folder "%s" before saving the sitemap.', $this->getSitemapPath()));
}
if (!$io->isWriteable($realPath)) {
Mage::throwException(Mage::helper('xsitemap')->__('Please make sure that "%s" is writable by web-server.', $this->getSitemapPath()));
}
if (!preg_match('#^[a-zA-Z0-9_\\.]+$#', $this->getSitemapFilename())) {
Mage::throwException(Mage::helper('xsitemap')->__('Please use only letters (a-z or A-Z), numbers (0-9) or underscore (_) in the filename. No spaces or other characters are allowed.'));
}
if (!preg_match('#\\.xml$#', $this->getSitemapFilename())) {
$this->setSitemapFilename($this->getSitemapFilename() . '.xml');
}
$this->setSitemapPath(rtrim(str_replace(str_replace('\\', '/', Mage::getBaseDir()), '', $realPath), '/') . '/');
return parent::_beforeSave();
}
示例14: processFileQueue
/**
* Process File Queue
* @return Mage_Catalog_Model_Product_Type_Abstract
*/
public function processFileQueue()
{
if (empty($this->_fileQueue)) {
return $this;
}
foreach ($this->_fileQueue as &$queueOptions) {
if (isset($queueOptions['operation']) && ($operation = $queueOptions['operation'])) {
switch ($operation) {
case 'receive_uploaded_file':
$src = isset($queueOptions['src_name']) ? $queueOptions['src_name'] : '';
$dst = isset($queueOptions['dst_name']) ? $queueOptions['dst_name'] : '';
/** @var $uploader Zend_File_Transfer_Adapter_Http */
$uploader = isset($queueOptions['uploader']) ? $queueOptions['uploader'] : null;
$path = dirname($dst);
$io = new Varien_Io_File();
if (!$io->isWriteable($path) && !$io->mkdir($path, 0777, true)) {
Mage::throwException(Mage::helper('catalog')->__("Cannot create writeable directory '%s'.", $path));
}
$uploader->setDestination($path);
if (empty($src) || empty($dst) || !$uploader->receive($src)) {
/**
* @todo: show invalid option
*/
if (isset($queueOptions['option'])) {
$queueOptions['option']->setIsValid(false);
}
Mage::throwException(Mage::helper('catalog')->__("File upload failed"));
}
Mage::helper('core/file_storage_database')->saveFile($dst);
break;
case 'move_uploaded_file':
$src = $queueOptions['src_name'];
$dst = $queueOptions['dst_name'];
move_uploaded_file($src, $dst);
Mage::helper('core/file_storage_database')->saveFile($dst);
break;
default:
break;
}
}
$queueOptions = null;
}
return $this;
}
示例15: generateXml
/**
* Generate XML file
*
* @return ET_FeedSalidzini_Model_Feedsalidzini
*/
public function generateXml()
{
$io = new Varien_Io_File();
$io->setAllowCreateFolders(true);
$io->open(array('path' => $this->getPath()));
if ($io->fileExists($this->getXmlfileFilename()) && !$io->isWriteable($this->getXmlfileFilename())) {
Mage::throwException(Mage::helper('feedsalidzini')->__('File "%s" cannot be saved. Please, make sure the directory "%s" is writeable by web server.', $this->getXmlfileFilename(), $this->getPath()));
}
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><root></root>');
$storeId = $this->getStoreId();
$appEmulation = Mage::getSingleton('core/app_emulation');
$initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
/* @var $collection Mage_Catalog_Model_Resource_Product_Collection
* @var $product Mage_Catalog_Model_Product
* @var $categories Mage_Catalog_Model_Resource_Category_Collection
* @var $category Mage_Catalog_Model_Category
* @var $stockCollection Mage_CatalogInventory_Model_Resource_Stock_Item_Collection
* @var $stockItem Mage_CatalogInventory_Model_Stock_Item
*/
/* Collecting categories info */
$categories = Mage::getModel('catalog/category')->getCollection();
$categories->addIsActiveFilter();
$categories->addNameToResult();
$categories->addUrlRewriteToResult();
foreach ($categories as $category) {
$this->_tmpCategories[$category->getId()] = array('id' => $category->getId(), 'level' => $category->getLevel(), 'name' => $category->getName(), 'path' => $category->getPathIds(), 'url' => $_SERVER["SCRIPT_FILENAME"] ? str_replace($_SERVER["SCRIPT_FILENAME"] . "/", "", $category->getUrl()) : $category->getUrl(), 'parent' => $category->getParentCategory()->getId());
}
/* Collecting product stock info */
$stockCollection = Mage::getModel('cataloginventory/stock_item')->getCollection();
foreach ($stockCollection as $stockItem) {
$this->_stock[$stockItem->getProductId()] = $stockItem->getQty();
}
unset($stockCollection);
/* Subproduct collection */
if ($this->_includeStock && $this->_emulateStock == 2) {
/* @var $db Varien_Db_Adapter_Interface */
$db = Mage::getSingleton('core/resource')->getConnection('core_write');
$model = Mage::getResourceModel('catalog/product');
$superTable = $model->getTable("catalog_product_super_link");
$query = $db->query("SELECT * FROM " . $superTable);
while ($row = $query->fetch()) {
if (!isset($this->_superProducts[$row["parent_id"]])) {
$this->_superProducts[$row["parent_id"]] = array();
}
$this->_superProducts[$row["parent_id"]][] = $row["product_id"];
}
}
/* Attribute collection */
/* @var $attributes Mage_Eav_Model_Resource_Entity_Attribute_Collection
* @var $attribute Mage_Eav_Model_Entity_Attribute
*/
$attributes = Mage::getSingleton('eav/config')->getEntityType(Mage_Catalog_Model_Product::ENTITY)->getAttributeCollection()->addFieldToFilter('attribute_code', array('in', $this->_nameAttributes));
foreach ($attributes as $attribute) {
if (!in_array($attribute->getFrontendInput(), array('select', 'multiselect'))) {
continue;
}
$options = $attribute->getSource()->getAllOptions();
$this->_attributeOptions[$attribute->getAttributeCode()] = array();
foreach ($options as $option) {
$this->_attributeOptions[$attribute->getAttributeCode()][$option['value']] = $option['label'];
}
}
/* Collecting product info */
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addFieldToFilter("type_id", array("in" => $this->_filterProductTypes));
$collection->addAttributeToFilter("visibility", array("in" => $this->_filterProductVisibility));
$collection->addStoreFilter($storeId);
$collection->addAttributeToSelect("name");
foreach ($this->_nameAttributes as $attr) {
$collection->addAttributeToSelect($attr);
}
if (!in_array("manufacturer", $this->_nameAttributes)) {
$collection->addAttributeToSelect("manufacturer");
}
$collection->addAttributeToSelect("model");
$collection->addAttributeToSelect("price");
$collection->addAttributeToSelect("status");
$collection->addCategoryIds();
$collection->addUrlRewrite();
$collection->addFinalPrice();
//echo $collection->getSelect();
foreach ($collection as $product) {
if (!$this->_shouldExport($product)) {
continue;
}
$maxLevel = -1;
if ($this->_hideDuplicates) {
$selectedCategory = false;
foreach ($product->getCategoryIds() as $categoryId) {
if (isset($this->_tmpCategories[$categoryId])) {
$categoryInfo = $this->_tmpCategories[$categoryId];
if ($categoryInfo['level'] > $maxLevel) {
$maxLevel = $categoryInfo['level'];
$selectedCategory = $categoryInfo;
}
//.........这里部分代码省略.........