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; }
/** * Load the import data from the csv files * * @return array */ public function loadData() { $ioHandler = new Varien_Io_File(); $ioHandler->open(array('path' => $this->getImportDir())); $debitFiles = $ioHandler->ls(Varien_Io_File::GREP_FILES); $import = array(); foreach ($debitFiles as $debitFile) { if ($debitFile['filetype'] != 'csv') { continue; } $country = str_replace('.csv', '', $debitFile['text']); $country = strtoupper($country); $import[$country] = array(); $i = 1; $ioHandler->streamOpen($debitFile['text'], 'r'); while (($line = $ioHandler->streamReadCsv()) !== false) { if ($i == 1) { $i++; continue; } // Check if routing number already exists $swiftCode = trim($line[2]); if (array_key_exists($swiftCode, $import[$country]) || empty($swiftCode)) { continue; } // Add bank to array $import[$country][$swiftCode] = array('routing_number' => trim($line[0]), 'swift_code' => $swiftCode, 'bank_name' => trim($line[1])); } $ioHandler->streamClose(); } return $import; }
protected function _loadFiles() { if (!$this->_isLoaded) { $readPath = Mage::getBaseDir("var") . DS . "backups"; $ioProxy = new Varien_Io_File(); try { $ioProxy->open(array('path' => $readPath)); } catch (Exception $e) { $ioProxy->mkdir($readPath, 0755); $ioProxy->chmod($readPath, 0755); $ioProxy->open(array('path' => $readPath)); } if (!is_file($readPath . DS . ".htaccess")) { // Deny from reading in browser $ioProxy->write(".htaccess", "deny from all", 0644); } $list = $ioProxy->ls(Varien_Io_File::GREP_FILES); $fileExtension = constant($this->_itemObjectClass . "::BACKUP_EXTENSION"); foreach ($list as $entry) { if ($entry['filetype'] == $fileExtension) { $item = new $this->_itemObjectClass(); $item->load($entry['text'], $readPath); if ($this->_checkCondition($item)) { $this->addItem($item); } } } $this->_totalRecords = count($this->_items); if ($this->_totalRecords > 1) { usort($this->_items, array(&$this, 'compareByTypeOrDate')); } $this->_isLoaded = true; } return $this; }
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; }
/** * Returns the log files of the var/log directory * * @return array File List */ public function getLogFiles() { // Check if path exists $path = Mage::getBaseDir('var') . DS . 'log' . DS; if (!file_exists($path)) { return array(); } // Return file list $io = new Varien_Io_File(); $io->open(array('path' => $path)); return $io->ls(Varien_Io_File::GREP_FILES); }
public function ls($grep = null) { $directories = parent::ls($grep); if (is_array($directories)) { foreach ($directories as $key => $directory) { if (isset($directory['id']) === false) { $directories[$key]['id'] = $this->_cwd . DS . $directory['text']; } } } return $directories; }
protected function _getBiggestFiles() { $return = array(); $logDir = new Varien_Io_File(); $logDir->open(array('path' => Mage::getBaseDir('log'))); foreach ($logDir->ls(Varien_Io_File::GREP_FILES) as $file) { if (substr($file['text'], -4) == '.log') { $return[$file['text']] = $file['size'] / 1024; } } arsort($return); return array_slice($return, 0, 10); }
/** * 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; }
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; }
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); } } }
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; }
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; }
/** * 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()); } }
* 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']); } }
/** * Reset all theme color changes * Copy media/xmlconnect/themes/default/* to media/xmlconnect/themes/* * * @return void */ public function resetAllThemes() { $themeDir = Mage::getBaseDir('media') . DS . 'xmlconnect' . DS . 'themes'; $defaultThemeDir = Mage::getBaseDir('media') . DS . 'xmlconnect' . DS . 'themes' . DS . 'default'; $io = new Varien_Io_File(); $io->open(array('path' => $defaultThemeDir)); $fileList = $io->ls(Varien_Io_File::GREP_FILES); foreach ($fileList as $file) { $f = $file['text']; $src = $defaultThemeDir . DS . $f; $dst = $themeDir . DS . $f; if ($io->isWriteable($dst)) { try { if (!$io->cp($src, $dst)) { Mage::throwException(Mage::helper('xmlconnect')->__('Can\\t copy file "%s" to "%s".', $src, $dst)); } else { $io->chmod($dst, 0755); } } catch (Exception $e) { Mage::logException($e); } } } }
/** * Reset themes color changes * Copy /xmlconnect/etc/themes/* to media/xmlconnect/themes/* * * @throws Mage_Core_Exception * @param null $theme * @return null */ public function resetTheme($theme = null) { $themeDir = $this->getMediaThemePath(); $defaultThemeDir = $this->_getDefaultThemePath(); $ioFile = new Varien_Io_File(); $ioFile->open(array('path' => $defaultThemeDir)); $fileList = $ioFile->ls(Varien_Io_File::GREP_FILES); foreach ($fileList as $file) { $f = $file['text']; $src = $defaultThemeDir . DS . $f; $dst = $themeDir . DS . $f; if ($theme && $theme . '.xml' != $f) { continue; } if (!$ioFile->cp($src, $dst)) { Mage::throwException(Mage::helper('xmlconnect')->__('Can\'t copy file "%s" to "%s".', $src, $dst)); } else { $ioFile->chmod($dst, 0755); } } }
public function filteredLs() { $result = parent::ls(); return Mage::getSingleton('udbatch/io')->filterLs($result, $this); }
/** * 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; }