public function toOptionArray($exclude = true) { $result = array(); $result['Magento'] = array('label' => 'Magento'); $path = Mage::getModuleDir('', 'Mirasvit_SearchIndex') . DS . 'Model' . DS . 'Index'; $io = new Varien_Io_File(); $io->open(); $io->cd($path); foreach ($io->ls(Varien_Io_File::GREP_DIRS) as $space) { $io->cd($space['id']); foreach ($io->ls(Varien_Io_File::GREP_DIRS) as $module) { $io->cd($module['id']); foreach ($io->ls(Varien_Io_File::GREP_DIRS) as $entity) { if ($io->fileExists($entity['id'] . DS . 'Index.php', true)) { $indexCode = $space['text'] . '_' . $module['text'] . '_' . $entity['text']; $index = Mage::helper('searchindex/index')->getIndexModel($indexCode); if (is_object($index)) { if ($index->canUse()) { if (!isset($result[$index->getBaseGroup()])) { $result[$index->getBaseGroup()] = array('label' => $index->getBaseGroup(), 'value' => array()); } $result[$index->getBaseGroup()]['value'][] = array('value' => $index->getCode(), 'label' => $index->getBaseTitle()); } } else { Mage::throwException('Wrong model for index ' . $indexCode); } } } } } return $result; }
/** * Prepare the feed file and returns its path * * @param array $productsData * @param int $storeId * @return string */ public function prepareFeed(array $productsData, $storeId) { $mId = $this->getVendorConfig('merchant_id', $storeId); if (!$mId) { Mage::throwException(Mage::helper('productfeed')->__('Rakuten Seller ID must be set.')); } $filename = 'rakuten_product_' . Mage::getModel('core/date')->date('Ymd') . '.txt'; $filepath = $this->getFeedStorageDir() . $filename; try { $ioAdapter = new Varien_Io_File(); $ioAdapter->setAllowCreateFolders(true); $ioAdapter->createDestinationDir($this->getFeedStorageDir()); $ioAdapter->cd($this->getFeedStorageDir()); $ioAdapter->streamOpen($filename); $ioAdapter->streamWrite(implode(self::DELIMITER, $this->getHeaders()) . "\n"); foreach ($productsData as $productId => $row) { array_unshift($row, $mId); $this->prepareRow($row, $productId); $ioAdapter->streamWrite(implode(self::DELIMITER, $row) . "\n"); // because a CSV enclosure is not supported } return $filepath; } catch (Exception $e) { Mage::throwException(Mage::helper('productfeed')->__('Could not write feed file to path: %s, %s', $filepath, $e->getMessage())); } }
/** * Prepare the feed file and returns its path * * @param array $productsData * @param int $storeId * @return string */ public function prepareFeed(array $productsData, $storeId) { $mId = $this->getVendorConfig('merchant_id', $storeId); $company = $this->getVendorConfig('company', $storeId); if (!$mId || !$company) { Mage::throwException(Mage::helper('productfeed')->__('LinkShare Merchant ID and Company Name must be set.')); } Varien_Profiler::start('productfeed_' . $this->getVendorCode() . '::' . __FUNCTION__); $content = implode(self::DELIMITER, array('HDR', $mId, $company, Mage::getModel('core/date')->date('Y-m-d/H:i:s'))) . self::EOL; foreach ($productsData as $row) { $content .= $row . self::EOL; } $filename = $mId . '_nmerchandis' . Mage::getModel('core/date')->date('Ymd') . '.txt'; $filepath = $this->getFeedStorageDir() . $filename; try { $ioAdapter = new Varien_Io_File(); $ioAdapter->setAllowCreateFolders(true); $ioAdapter->createDestinationDir($this->getFeedStorageDir()); $ioAdapter->cd($this->getFeedStorageDir()); $ioAdapter->streamOpen($filename); $ioAdapter->streamWrite($content); Varien_Profiler::stop('productfeed_' . $this->getVendorCode() . '::' . __FUNCTION__); return $filepath; } catch (Exception $e) { Varien_Profiler::stop('productfeed_' . $this->getVendorCode() . '::' . __FUNCTION__); Mage::throwException(Mage::helper('productfeed')->__('Could not write feed file to path: %s, %s', $filepath, $e->getMessage())); } }
function writeRewriteFile() { $adapter = Mage::getModel('freelunchlabs_cloudfront/refreshadapters_apache'); $base_dir = Mage::getBaseDir() . DS; $file = new Varien_Io_File(); try { if ($file->cd($base_dir) && $file->checkAndCreateFolder($this->cdn_rewrite_directory, 0755)) { if ($file->cd($base_dir . $this->cdn_rewrite_directory)) { if (!$file->write($adapter->filename, $adapter->buildFileContents(), 0644)) { throw new Exception("Could not write .htaccess to: " . $file->pwd()); } } } } catch (Exception $e) { Mage::getSingleton('core/session')->addWarning('Configuration saved but there was an error creating the .htaccess file: ' . $e->getMessage()); } }
public function toOptionArray() { $io = new Varien_Io_File(); $io->cd(Mage::getBaseDir() . DS . 'js' . DS . 'codemirror' . DS . 'theme'); $files = $io->ls(Varien_Io_File::GREP_FILES); $options = array(array('value' => 'default', 'label' => 'default')); foreach ($files as $file) { $theme = pathinfo($file['text'], PATHINFO_FILENAME); $options[] = array('value' => $theme, 'label' => $theme); } return $options; }
/** * Get all files which are older than X days and containing a pattern. * * @param int $days Days * @param string $dir Directory * @param string $filename Filename * @return array */ public function getFilesOlderThan($days, $dir, $filename) { $date = Mage::getModel('core/date')->gmtTimestamp() - 60 * 60 * 24 * $days; $oldFiles = array(); $scanDir = new Varien_Io_File(); $scanDir->cd($dir); foreach ($scanDir->ls(Varien_Io_File::GREP_FILES) as $oldFile) { if (stripos($oldFile['text'], $filename) != false && strtotime($oldFile['mod_date']) < $date) { $oldFiles[] = $oldFile; } } return $oldFiles; }
protected function _rewriteGrid($blcgClass, $originalClass, $gridType) { $classParts = explode('_', str_replace($this->_getBlcgClassPrefix(), '', $blcgClass)); $fileName = array_pop($classParts) . '.php'; $rewriteDir = dirname(__FILE__) . '/../../../Block/Rewrite/' . implode('/', $classParts); $ioFile = new Varien_Io_File(); $ioFile->setAllowCreateFolders(true); $ioFile->checkAndCreateFolder($rewriteDir); $ioFile->cd($rewriteDir); // Use open() to initialize Varien_Io_File::$_iwd // Prevents a warning when chdir() is used without error control in Varien_Io_File::read() if ($ioFile->fileExists($fileName, true) && $ioFile->open()) { if ($content = $ioFile->read($fileName)) { $lines = preg_split('#\\R#', $content, 3); $isUpToDate = false; if (isset($lines[0]) && isset($lines[1]) && $lines[0] == '<?php' && preg_match('#^// BLCG_REWRITE_CODE_VERSION\\=([0-9]+)$#', $lines[1], $matches)) { if ($matches[1] === strval(self::REWRITE_CODE_VERSION)) { $isUpToDate = true; } } } $ioFile->close(); if ($isUpToDate) { return $this; } } $content = '<?php // BLCG_REWRITE_CODE_VERSION=' . self::REWRITE_CODE_VERSION . ' // This file was generated automatically. Do not alter its content. /** * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php * * @category BL * @package BL_CustomGrid * @copyright Copyright (c) ' . date('Y') . ' Benoît Leulliette <*****@*****.**> * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ '; $content .= $this->_getRewriteCode($blcgClass, $originalClass, $gridType); if (!$ioFile->write($fileName, $content)) { Mage::throwException(); } return $this; }
public function cleanCache(Varien_Event_Observer $observer) { /** @var Mage_Catalog_Model_Product_Media_Config $mediaConfig */ $mediaConfig = Mage::getSingleton('catalog/product_media_config'); $baseCacheDir = realpath($mediaConfig->getMediaPath(Aoe_LazyCatalogImages_Helper_Catalog_Image::TOKEN_PREFIX)); $io = new Varien_Io_File(); $io->cd($baseCacheDir); foreach ($io->ls(Varien_Io_File::GREP_DIRS) as $info) { $dir = $info['id']; if (strpos($dir, $baseCacheDir) === 0) { $io->rmdir($dir, true); } } }
public static function toArray() { $result = array(); $path = Mage::getModuleDir('', 'Mirasvit_Email') . DS . 'Model' . DS . 'Event'; $io = new Varien_Io_File(); $io->open(); $io->cd($path); foreach ($io->ls(Varien_Io_File::GREP_DIRS) as $entity) { $io->cd($entity['id']); foreach ($io->ls(Varien_Io_File::GREP_FILES) as $event) { if ($event['filetype'] != 'php') { continue; } $info = pathinfo($event['text']); $eventCode = strtolower($entity['text'] . '_' . $info['filename']); $event = Mage::helper('email/event')->getEventModel($eventCode); foreach ($event->getEvents() as $code => $name) { $result[$event->getEventsGroup()][$code] = $name; } } } return $result; }
/** * Submit refunds back to LinkShare for reimbursement. * * @param int $storeId * @return Grommet_ProductFeed_Model_Vendor_LinkShare_Refund */ public function processDailyRefunds($storeId) { $rows = array(); $ordersProcessed = array(); // add credit memos to the feed $creditmemos = $this->_getCreditMemos($storeId); if (count($creditmemos)) { foreach ($creditmemos as $creditmemo) { $rows = array_merge($rows, $this->creditmemoToFeed($creditmemo)); $ordersProcessed[] = $creditmemo->getOrderId(); } } // add cancelations to the feed $orders = $this->_getOrders($storeId, $ordersProcessed); if (count($orders)) { foreach ($orders as $order) { $rows = array_merge($rows, $this->orderToFeed($order)); } } if (count($rows)) { $mId = $this->getVendorConfig('merchant_id', $storeId); if (!$mId) { Mage::throwException(Mage::helper('productfeed')->__('LinkShare Merchant ID must be set.')); } $content = ''; foreach ($rows as $row) { $content .= implode(self::DELIMITER, array_values($row)) . self::EOL; } $filename = $mId . '_trans' . Mage::getModel('core/date')->date('Ymd') . '.txt'; $filepath = $this->getFeedStorageDir() . $filename; try { $ioAdapter = new Varien_Io_File(); $ioAdapter->setAllowCreateFolders(true); $ioAdapter->createDestinationDir($this->getFeedStorageDir()); $ioAdapter->cd($this->getFeedStorageDir()); $ioAdapter->streamOpen($filename); $ioAdapter->streamWrite($content); } catch (Exception $e) { Mage::throwException(Mage::helper('productfeed')->__('Could not write refund file to path: %s, %s', $filepath, $e->getMessage())); } $publisher = $this->getPublisher(); $publisher->publish($filepath, $this->getPublishParams($storeId)); } return $this; }
protected function _getRuleClasses() { $classes = array(); $rulesDir = Mage::getModuleDir('', 'Mirasvit_Email') . DS . 'Model' . DS . 'Rule' . DS . 'Condition'; $io = new Varien_Io_File(); $io->open(); $io->cd($rulesDir); foreach ($io->ls(Varien_Io_File::GREP_FILES) as $event) { if ($event['filetype'] != 'php') { continue; } $info = pathinfo($event['text']); $class = strtolower($info['filename']); $classes[$class] = 'email/rule_condition_' . strtolower($class); } $io->close(); return $classes; }
/** * Prepare the feed file and returns its path * * @param array $productsData * @param int $storeId * @return string */ public function prepareFeed(array $productsData, $storeId) { $filename = 'mediaforge_' . Mage::getModel('core/date')->date('Ymd') . '.csv'; $filepath = $this->getFeedStorageDir() . $filename; try { $ioAdapter = new Varien_Io_File(); $ioAdapter->setAllowCreateFolders(true); $ioAdapter->createDestinationDir($this->getFeedStorageDir()); $ioAdapter->cd($this->getFeedStorageDir()); $ioAdapter->streamOpen($filename); $ioAdapter->streamWriteCsv($this->_fields, self::DELIMITER); foreach ($productsData as $row) { $ioAdapter->streamWriteCsv($row, self::DELIMITER); } return $filepath; } catch (Exception $e) { Mage::throwException(Mage::helper('productfeed')->__('Could not write feed file to path: %s, %s', $filepath, $e->getMessage())); } }
public function getVariablesHelpers() { $result = array(); $pathes = array('email' => Mage::getModuleDir('', 'Mirasvit_Email') . DS . 'Helper' . DS . 'Variables', 'emaildesign' => Mage::getModuleDir('', 'Mirasvit_EmailDesign') . DS . 'Helper' . DS . 'Variables'); $io = new Varien_Io_File(); $io->open(); foreach ($pathes as $pathKey => $path) { $io->cd($path); foreach ($io->ls(Varien_Io_File::GREP_FILES) as $event) { if ($event['filetype'] != 'php') { continue; } $info = pathinfo($event['text']); $result[] = $pathKey . '/variables_' . strtolower($info['filename']); } } $io->close(); return $result; }
/** * Prepare the feed file and returns its path * * @param array $productsData * @param int $storeId * @return string */ public function prepareFeed(array $productsData, $storeId) { Varien_Profiler::start('productfeed_' . $this->getVendorCode() . '::' . __FUNCTION__); $filename = $this->getVendorCode() . '_' . Mage::getModel('core/date')->date('Ymd') . '.json'; $filepath = $this->getFeedStorageDir() . $filename; try { $ioAdapter = new Varien_Io_File(); $ioAdapter->setAllowCreateFolders(true); $ioAdapter->createDestinationDir($this->getFeedStorageDir()); $ioAdapter->cd($this->getFeedStorageDir()); $ioAdapter->streamOpen($filename); $ioAdapter->streamWrite(json_encode($productsData)); Varien_Profiler::stop('productfeed_' . $this->getVendorCode() . '::' . __FUNCTION__); return $filepath; } catch (Exception $e) { Varien_Profiler::stop('productfeed_' . $this->getVendorCode() . '::' . __FUNCTION__); Mage::throwException(Mage::helper('productfeed')->__('Could not write feed file to path: %s, %s', $filepath, $e->getMessage())); } }
/** * Check file in database storage if needed and place it on file system * * @param string $filePath * @return bool */ protected function _processDatabaseFile($filePath) { if (!Mage::helper('core/file_storage_database')->checkDbUsage()) { return false; } $relativePath = Mage::helper('core/file_storage_database')->getMediaRelativePath($filePath); $file = Mage::getModel('core/file_storage_database')->loadByFilename($relativePath); if (!$file->getId()) { return false; } $directory = dirname($filePath); @mkdir($directory, 0777, true); $io = new Varien_Io_File(); $io->cd($directory); $io->streamOpen($filePath); $io->streamLock(true); $io->streamWrite($file->getContent()); $io->streamUnlock(); $io->streamClose(); return true; }
/** * Deletes all extension folders and the app/etc/modules config file. */ public function deleteExtensionFolderFiles() { $namespacePath = $this->_getNamespacePath(); $extensionPath = $this->_getExtensionPath(); try { $this->_filesystem->rmdir($extensionPath, true); if (is_dir($namespacePath)) { $this->_filesystem->cd($namespacePath); if (count($this->_filesystem->ls()) == 0) { $this->_filesystem->rmdir($namespacePath, true); } } $modulesConfigFile = $this->_namespace . '_' . $this->_extensionName . '.xml'; $modulesConfigFilePath = $this->_helper->getModulesConfigDir() . DS . $modulesConfigFile; if (file_exists($modulesConfigFilePath)) { $this->_filesystem->rm($modulesConfigFilePath); } } catch (Exception $e) { Mage::log($e->getMessage(), null, $this->_helper->getLogFilename()); Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); } }
/** * @param null $store * @return Varien_Io_File */ protected function _getStoreCacheDir($store = null) { $io = new Varien_Io_File(); $io->open(array('path' => $this->getFpcDir())); $storeDir = $this->getStoreDir($store); if (!$io->fileExists($storeDir, false)) { $io->mkdir($storeDir); } $io->cd($storeDir); return $io; }
* Mirasvit * * This source file is subject to the Mirasvit Software License, which is available at http://mirasvit.com/license/. * Do not edit or add to this file if you wish to upgrade the to newer versions in the future. * If you wish to customize this module for your needs. * Please refer to http://www.magentocommerce.com for more information. * * @category Mirasvit * @package Advanced Product Feeds * @version 1.1.2 * @build 619 * @copyright Copyright (C) 2015 Mirasvit (http://mirasvit.com/) */ $templatePath = Mage::getSingleton('feedexport/config')->getTemplatePath(); $rulePath = Mage::getSingleton('feedexport/config')->getRulePath(); $ioFile = new Varien_Io_File(); $ioFile->open(); $ioFile->cd($templatePath); foreach ($ioFile->ls(Varien_Io_File::GREP_FILES) as $fl) { if ($fl['filetype'] == 'xml') { $template = Mage::getModel('feedexport/template'); $template->import($templatePath . DS . $fl['text']); } } $ioFile->cd($rulePath); foreach ($ioFile->ls(Varien_Io_File::GREP_FILES) as $fl) { if ($fl['filetype'] == 'xml') { $rule = Mage::getModel('feedexport/rule'); $rule->import($rulePath . DS . $fl['text']); } }
/** * @param $fileName * @return bool * @throws Exception */ protected function fileExists($fileName) { $file = new Varien_Io_File(); $file->cd($this->getImportDir()); return $file->fileExists($fileName); }
/** * Delete theme by id * * @param $themeId * @return bool */ public function deleteTheme($themeId) { $result = false; $ioFile = new Varien_Io_File(); $ioFile->cd($this->getMediaThemePath()); $themeFile = basename($themeId . '.xml'); if ($ioFile->fileExists($themeFile)) { $result = $ioFile->rm($themeFile); } return $result; }
* Please refer to http://www.magentocommerce.com for more information. * * @category Mirasvit * @package Follow Up Email * @version 1.0.2 * @revision 269 * @copyright Copyright (C) 2014 Mirasvit (http://mirasvit.com/) */ $installer = $this; $installer->startSetup(); $installer->run("\n DROP TABLE IF EXISTS `{$installer->getTable('emaildesign/design')}`;\n CREATE TABLE `{$installer->getTable('emaildesign/design')}` (\n `design_id` int(11) NOT NULL AUTO_INCREMENT,\n `title` varchar(255) NOT NULL,\n `description` text NULL,\n `template_type` varchar(255) NOT NULL,\n `styles` text NULL,\n `template` text NULL,\n\n `created_at` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',\n `updated_at` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',\n PRIMARY KEY (`design_id`)\n ) ENGINE=InnoDb DEFAULT CHARSET=utf8;\n\n DROP TABLE IF EXISTS `{$installer->getTable('emaildesign/template')}`;\n CREATE TABLE `{$installer->getTable('emaildesign/template')}` (\n `template_id` int(11) NOT NULL AUTO_INCREMENT,\n `design_id` int(11) NULL,\n `title` varchar(255) NOT NULL,\n `description` text NULL,\n `subject` varchar(255) NOT NULL,\n `areas_content` longtext NULL,\n\n `created_at` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',\n `updated_at` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',\n PRIMARY KEY (`template_id`)\n ) ENGINE=InnoDb DEFAULT CHARSET=utf8;\n"); $installer->endSetup(); // populate data $designPath = Mage::getSingleton('emaildesign/config')->getDesignPath(); $templatePath = Mage::getSingleton('emaildesign/config')->getTemplatePath(); $ioFile = new Varien_Io_File(); $ioFile->open(); $ioFile->cd($designPath); foreach ($ioFile->ls(Varien_Io_File::GREP_FILES) as $fl) { if ($fl['filetype'] == 'xml') { $design = Mage::getModel('emaildesign/design'); $design->import($designPath . DS . $fl['text']); } } $ioFile->cd($templatePath); foreach ($ioFile->ls(Varien_Io_File::GREP_FILES) as $fl) { if ($fl['filetype'] == 'xml') { $template = Mage::getModel('emaildesign/template'); $template->import($templatePath . DS . $fl['text']); } }
/** * Directory structure initializing */ protected function _initFilesystem() { $this->_createWriteableDir($this->getTargetDir()); $this->_createWriteableDir($this->getQuoteTargetDir()); $this->_createWriteableDir($this->getOrderTargetDir()); // Directory listing and hotlink secure $io = new Varien_Io_File(); $io->cd($this->getTargetDir()); if (!$io->fileExists($this->getTargetDir() . DS . '.htaccess')) { $io->streamOpen($this->getTargetDir() . DS . '.htaccess'); $io->streamLock(true); $io->streamWrite("Order deny,allow\nDeny from all"); $io->streamUnlock(); $io->streamClose(); } }
/** * Delete tmp file * * @param string $fileName * @return true */ protected function _deleteFile($fileName) { $dir = $this->_getTmpDir(); $file = new Varien_Io_File(); if ($file->fileExists($dir . $fileName, true)) { $file->cd($dir); $file->rm($fileName); } return true; }
/** * Save file to storage * * @param string $filePath * @param string $content * @param bool $overwrite * @return bool */ public function saveFile($filePath, $content, $overwrite = false) { $filename = basename($filePath); $path = $this->getMediaBaseDirectory() . DS . str_replace('/', DS, dirname($filePath)); if (!file_exists($path) || !is_dir($path)) { @mkdir($path, 0777, true); } $ioFile = new Varien_Io_File(); $ioFile->cd($path); if (!$ioFile->fileExists($filename) || $overwrite && $ioFile->rm($filename)) { $ioFile->streamOpen($filename); $ioFile->streamLock(true); $result = $ioFile->streamWrite($content); $ioFile->streamUnlock(); $ioFile->streamClose(); if ($result !== false) { return true; } Mage::throwException(Mage::helper('core')->__('Unable to save file: %s', $filePath)); } return false; }
/** * Parse log folder filesystem and find all directories on third nesting level * * @param string $logPath * @param int $level * @return array */ protected function _getDirectoryList($logPath, $level = 1) { $result = array(); $logPath = rtrim($logPath, DS); $fs = new Varien_Io_File(); $fs->cd($logPath); foreach ($fs->ls() as $entity) { if ($entity['leaf']) { continue; } $childPath = $logPath . DS . $entity['text']; $mergePart = $level < 3 ? $this->_getDirectoryList($childPath, $level + 1) : array($childPath); $result = array_merge($result, $mergePart); } return $result; }