本文整理汇总了PHP中Varien_Io_File::checkAndCreateFolder方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Io_File::checkAndCreateFolder方法的具体用法?PHP Varien_Io_File::checkAndCreateFolder怎么用?PHP Varien_Io_File::checkAndCreateFolder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_Io_File
的用法示例。
在下文中一共展示了Varien_Io_File::checkAndCreateFolder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: open
protected function open($write = false)
{
$ioAdapter = new Varien_Io_File();
try {
$path = $ioAdapter->getCleanPath($this->getPath());
$ioAdapter->checkAndCreateFolder($path);
$filePath = $path . DS . $this->getFileName();
} catch (Exception $e) {
Mage::helper('mailchimp')->addException($e);
}
if ($write && $ioAdapter->fileExists($filePath)) {
$ioAdapter->rm($filePath);
}
if (!$write && !$ioAdapter->fileExists($filePath)) {
$message = Mage::helper('mailchimp')->__('File "%s" does not exist.', $this->getFileName());
Mage::getSingleton('adminhtml/session')->addError($this->__('Mailchimp General Error: ') . $message);
}
$mode = $write ? 'wb' . self::COMPRESS_RATE : 'rb';
try {
$this->_handler = gzopen($filePath, $mode);
} catch (Exception $e) {
Mage::helper('mailchimp')->addException($e);
}
return $this;
}
示例2: 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;
}
示例3: fileUploadAction
/**
* @todo better subdirectories
* saves a file in the dir: media/wysiwyg/markdown/....
*
* @return $this
*/
public function fileUploadAction()
{
$return = array('err' => TRUE, 'msg' => 'An error occurred.', 'fileUrl' => '');
$binaryData = base64_decode($this->getRequest()->getParam('binaryData', ''));
$file = json_decode($this->getRequest()->getParam('file', '[]'), TRUE);
if (!(isset($file['extra']['nameNoExtension']) && isset($file['extra']['extension'])) || empty($binaryData)) {
$return['msg'] = 'Either fileName or binaryData or file is empty ...';
return $this->_setReturn($return, TRUE);
}
$fileName = $file['extra']['nameNoExtension'] . '.' . $file['extra']['extension'];
if (strpos(strtolower($fileName), 'clipboard') !== FALSE) {
$fileName = 'clipboard_' . date('Ymd-His') . '_' . str_replace('clipboard', '', strtolower($fileName));
}
$fileName = preg_replace('~[^\\w\\.]+~i', '_', $fileName);
$savePath = $this->_getStorageRoot() . $this->_getStorageSubDirectory();
$io = new Varien_Io_File();
if ($io->checkAndCreateFolder($savePath)) {
$result = (int) file_put_contents($savePath . $fileName, $binaryData);
// io->write will not work :-(
if ($result > 10) {
$return['err'] = FALSE;
$return['msg'] = '';
$return['fileUrl'] = Mage::helper('markdown')->getTemplateMediaUrl($this->_getStorageSubDirectory() . $fileName);
}
}
$this->_setReturn($return, TRUE);
}
示例4: _saveFile
/**
* Create/update file in file system
*
* @return bool|int
*/
protected function _saveFile()
{
$filePath = $this->getFilePath(true);
$this->_ioFile->checkAndCreateFolder(dirname($filePath));
$result = $this->_ioFile->write($filePath, $this->getContent());
$this->_design->cleanMergedJsCss();
return $result;
}
示例5: 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 '';
}
示例6: createExtensionFolders
/**
* Create extension folders.
* @param $folderName
* @throws Exception
*/
protected function createExtensionFolders($folderName)
{
try {
$this->_filesystem->checkAndCreateFolder($folderName);
} catch (Exception $e) {
Mage::log($e->getMessage(), null, $this->_helper->getLogFilename());
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
}
}
示例7: _createCertFile
/**
* Create physical certificate file based on DB data
*
* @param string $file
*/
protected function _createCertFile($file)
{
$certDir = $this->_getBaseDir();
if (!is_dir($certDir)) {
$ioAdapter = new Varien_Io_File();
$ioAdapter->checkAndCreateFolder($certDir);
} else {
$this->_removeOutdatedCertFile();
}
file_put_contents($file, Mage::helper('core')->decrypt($this->getContent()));
}
示例8: saveFile
/**
* @param $file
* @param $filename
* @throws Exception
*/
public function saveFile($file, $filename)
{
$varienFile = new Varien_Io_File();
$varienFile->open();
$path = $this->getFilePath($filename);
$varienFile->checkAndCreateFolder($path);
if ($varienFile->write($path . DS . $filename, $file) !== false) {
return $path . DS . $filename;
} else {
throw new Exception('Could not save PDF file');
}
}
示例9: createConfigFile
protected function createConfigFile()
{
$base_url = explode("/", Mage::getBaseUrl('js'));
$base_url = explode($base_url[count($base_url) - 2], Mage::getBaseUrl('js'));
$this->_base_url = $base_url[0];
$base_URLs = preg_replace('/http:\\/\\//is', 'https://', $base_url[0]);
/** Create file config for javascript */
$js = "var mw_baseUrl = '{BASE_URL}';\n";
$js = str_replace("{BASE_URL}", $base_url[0], $js);
$js .= "var mw_baseUrls = '{$base_URLs}';\n";
$js .= "var FACEBOOK_ID = '" . Mage::helper('mw_socialgift')->getFBID() . "';\n";
$file = new Varien_Io_File();
$file->checkAndCreateFolder($this->baseDir . "/media/mw_socialgift/js/");
$file->checkAndCreateFolder($this->baseDir . "/media/mw_socialgift/css/");
foreach ($this->_multi_path_js as $code => $path) {
if (!file_exists($path) && Mage::app()->getStore()->getCode() == $code) {
$file->write($path, $js);
$file->close();
}
}
return $js;
}
示例10: _rewriteGrid
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 <benoit.leulliette@gmail.com>
* @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;
}
示例11: _debugWriteToFile
protected function _debugWriteToFile($str)
{
if (!$this->_debugIoAdapter) {
$this->_debugIoAdapter = new Varien_Io_File();
$dir = $this->_debugIoAdapter->dirname($this->_debugFile);
$this->_debugIoAdapter->checkAndCreateFolder($dir);
$this->_debugIoAdapter->open(array('path' => $dir));
$this->_debugFile = basename($this->_debugFile);
}
$this->_debugIoAdapter->streamOpen($this->_debugFile, 'a');
$this->_debugIoAdapter->streamLock();
$this->_debugIoAdapter->streamWrite($str);
$this->_debugIoAdapter->streamUnlock();
$this->_debugIoAdapter->streamClose();
}
示例12: _create
/**
* Product image add
*
* @throws Mage_Api2_Exception
* @param array $data
* @return string
*/
protected function _create(array $data)
{
/* @var $validator Mage_Catalog_Model_Api2_Product_Image_Validator_Image */
$validator = Mage::getModel('Mage_Catalog_Model_Api2_Product_Image_Validator_Image');
if (!$validator->isValidData($data)) {
foreach ($validator->getErrors() as $error) {
$this->_error($error, Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
}
$this->_critical(self::RESOURCE_DATA_PRE_VALIDATION_ERROR);
}
$imageFileContent = @base64_decode($data['file_content'], true);
if (!$imageFileContent) {
$this->_critical('The image content must be valid base64 encoded data', Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
}
unset($data['file_content']);
$apiTempDir = Mage::getBaseDir('var') . DS . 'api' . DS . Mage::getSingleton('Mage_Api_Model_Session')->getSessionId();
$imageFileName = $this->_getFileName($data);
try {
$ioAdapter = new Varien_Io_File();
$ioAdapter->checkAndCreateFolder($apiTempDir);
$ioAdapter->open(array('path' => $apiTempDir));
$ioAdapter->write($imageFileName, $imageFileContent, 0666);
unset($imageFileContent);
// try to create Image object to check if image data is valid
try {
$adapter = Mage::helper('Mage_Core_Helper_Data')->getImageAdapterType();
new Varien_Image($apiTempDir . DS . $imageFileName, $adapter);
} catch (Exception $e) {
$ioAdapter->rmdir($apiTempDir, true);
$this->_critical($e->getMessage(), Mage_Api2_Model_Server::HTTP_INTERNAL_ERROR);
}
$product = $this->_getProduct();
$imageFileUri = $this->_getMediaGallery()->addImage($product, $apiTempDir . DS . $imageFileName, null, false, false);
$ioAdapter->rmdir($apiTempDir, true);
// updateImage() must be called to add image data that is missing after addImage() call
$this->_getMediaGallery()->updateImage($product, $imageFileUri, $data);
if (isset($data['types'])) {
$this->_getMediaGallery()->setMediaAttribute($product, $data['types'], $imageFileUri);
}
$product->save();
return $this->_getImageLocation($this->_getCreatedImageId($imageFileUri));
} catch (Mage_Core_Exception $e) {
$this->_critical($e->getMessage(), Mage_Api2_Model_Server::HTTP_INTERNAL_ERROR);
} catch (Exception $e) {
$this->_critical(self::RESOURCE_UNKNOWN_ERROR);
}
}
示例13: log
/**
* Log messages under a specific folder for easy grouping of all Bitloop
* module logs.
*
* @param string $message
* @param int $level
* @param bool $forceLog
*
* @return $this
* @throws Exception
*/
public function log($message, $level = null, $forceLog = false)
{
// Buld the log folder directory location, relative to Magento's root
// var/log folder
$_logFolder = Mage::getBaseDir('var') . DS . 'log' . DS . self::LOGS_SUBFOLDER;
// Check if the folder exists and if it doesn't create it.
// If it exists or it was created successfully, log inside that folder
// using the module name as the file name
$_io = new Varien_Io_File();
if ($_io->checkAndCreateFolder($_logFolder)) {
// Build the log file name.
$_logFile = self::LOGS_SUBFOLDER . $this->_getModuleName() . '.log';
// Log the message
Mage::log($message, $level, $_logFile, $forceLog);
}
return $this;
}
示例14: writeRewriteFile
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());
}
}
示例15: _createFile
/**
* Create temp csv file and write export
*
* @return mixed
*/
protected function _createFile()
{
$dir = $this->_getTmpDir();
$fileName = Mage::getStoreConfig(self::XML_PATH_SETTINGS_FINDFEED_FILENAME);
if (!$dir || !$fileName) {
return false;
}
if (!($attributes = $this->_getImportAttributes()) || count($attributes) <= 0) {
return false;
}
$headers = array_keys($attributes);
$file = new Varien_Io_File();
$file->checkAndCreateFolder($dir);
$file->cd($dir);
$file->streamOpen($fileName, 'w+');
$file->streamLock();
$file->streamWriteCsv($headers, self::SEPARATOR, self::ENCLOSURE);
$productCollectionPrototype = Mage::getResourceModel('catalog/product_collection');
$productCollectionPrototype->setPageSize(self::COLLECTION_PAGE_SIZE);
$pageNumbers = $productCollectionPrototype->getLastPageNumber();
unset($productCollectionPrototype);
for ($i = 1; $i <= $pageNumbers; $i++) {
$productCollection = Mage::getResourceModel('catalog/product_collection');
$productCollection->addAttributeToSelect($attributes);
$productCollection->addAttributeToFilter('is_imported', 1);
$productCollection->setPageSize(self::COLLECTION_PAGE_SIZE);
$productCollection->setCurPage($i)->load();
foreach ($productCollection as $product) {
$attributesRow = array();
foreach ($attributes as $key => $value) {
$attributesRow[$key] = $product->getData($value);
}
$file->streamWriteCsv($attributesRow, self::SEPARATOR, self::ENCLOSURE);
}
unset($productCollection);
}
$file->streamUnlock();
$file->streamClose();
if ($file->fileExists($fileName)) {
return $fileName;
}
return false;
}