本文整理匯總了PHP中Varien_Io_File::rmdir方法的典型用法代碼示例。如果您正苦於以下問題:PHP Varien_Io_File::rmdir方法的具體用法?PHP Varien_Io_File::rmdir怎麽用?PHP Varien_Io_File::rmdir使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Varien_Io_File
的用法示例。
在下文中一共展示了Varien_Io_File::rmdir方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: cleanImageCache
/**
* Flush the media/slider/resized folder, when the catalog image cache is flushed
*
* @param Varien_Event_Observer $observer
* @return Soon_Image_Model_Observer
*/
public function cleanImageCache(Varien_Event_Observer $observer)
{
$directory = Mage::getBaseDir('media') . DS . 'slider' . DS . 'resized' . DS;
$io = new Varien_Io_File();
$io->rmdir($directory, true);
return $this;
}
示例2: uninstall
final function uninstall(Varien_Event_Observer $observer)
{
$module = $observer->getEvent()->getModule();
if (0 !== strpos(get_class($this), $module)) {
return false;
}
$this->run();
$manifestPath = str_replace('_', '/', $module) . '/etc/manifest.xml';
foreach (explode(PS, get_include_path()) as $includePath) {
if (file_exists($includePath . DS . $manifestPath)) {
$manifestPath = $includePath . DS . $manifestPath;
break;
}
}
if (!file_exists($manifestPath)) {
throw new Exception('Manifest path "' . $manifestPath . '" does not exist');
}
$manifestXml = new SimpleXMLElement($manifestPath, null, true);
$paths = $manifestXml->xpath('/manifest/' . $module . '/paths/path');
$file = new Varien_Io_File();
foreach ($paths as $path) {
$path = BP . DS . $path;
if (file_exists($path)) {
if (is_dir($path)) {
$file->rmdir($path, true);
} else {
$file->rm($path);
}
}
}
$this->_removeResources($module);
}
示例3: _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);
}
}
示例4: removeDownloadsFile
public function removeDownloadsFile($fileId, $isRemoveFolder = true)
{
$dir = Mage::helper('downloads')->getDownloadsPath($fileId);
$files = Mage::helper('downloads')->getFiles($dir);
if ($files) {
foreach ($files as $value) {
unlink($value);
}
if ($isRemoveFolder === true) {
$io = new Varien_Io_File();
$io->rmdir($dir);
}
}
}
示例5: cleanCache
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);
}
}
}
示例6: moveImageFromTemp
/**
*
* Move option image from Temp directory to Media directory
*
* @param string $fileName
* @param int $attributeId
* @param int $optionId
* @return string
*/
public function moveImageFromTemp($fileName, $attributeId, $optionId)
{
$ioObject = new Varien_Io_File();
$targetDirectory = $this->_optionImageBasePath . $attributeId . DS . $optionId;
try {
$ioObject->rmdir($targetDirectory, true);
$ioObject->mkdir($targetDirectory, 0777, true);
$ioObject->open(array('path' => $targetDirectory));
} catch (Exception $e) {
return false;
}
$fileName = trim($fileName, '.tmp');
$targetFile = Varien_File_Uploader::getNewFileName($fileName);
$path = $targetDirectory . DS . $targetFile;
$ioObject->mv(Mage::getSingleton('catalog/product_media_config')->getTmpMediaPath($fileName), $path);
return $targetFile;
}
示例7: deleteExtensionFolderFiles
/**
* 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());
}
}
示例8: flushImagesCache
/**
* Removes folder with cached images
*
* @return boolean
*/
public function flushImagesCache()
{
$cacheDir = $this->getBaseDir() . DS . 'cache' . DS;
$io = new Varien_Io_File();
if ($io->fileExists($cacheDir, false)) {
return $io->rmdir($cacheDir, true);
}
return true;
}
示例9: removeOptionFile
public function removeOptionFile($groupId, $optionId, $valueId = false, $isRemoveFolder = true)
{
$dir = Mage::helper('customoptions')->getCustomOptionsPath($groupId, $optionId, $valueId);
$files = Mage::helper('customoptions')->getFiles($dir);
if ($files) {
foreach ($files as $value) {
@unlink($value);
}
if ($isRemoveFolder === true) {
$io = new Varien_Io_File();
$io->rmdir($dir);
}
}
}
示例10: saveAction
public function saveAction()
{
if ($data = $this->getRequest()->getPost()) {
$_model = Mage::getModel('smvendors/banner');
if (isset($data['position'])) {
$data['position'] = implode(',', $data['position']);
}
if ($this->getRequest()->getParam('id')) {
$_model->setData($data)->setId($this->getRequest()->getParam('id'));
} else {
$_model->setData($data);
}
$imagedata = array();
if (!empty($_FILES['image']['name'])) {
try {
$ext = substr($_FILES['image']['name'], strrpos($_FILES['image']['name'], '.') + 1);
$fname = 'File-' . time() . '.' . $ext;
$uploader = new Varien_File_Uploader('image');
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
// or pdf or anything
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(false);
$path = Mage::getBaseDir('media') . DS . 'vendor' . DS . 'banners';
$uploader->save($path, $fname);
$imagedata['image'] = 'vendor/banners/' . $fname;
$_model->setData('image', $imagedata['image']);
} catch (Exception $e) {
Mage::logException($e);
}
}
if (empty($imagedata['image'])) {
$vendorLogo = $this->getRequest()->getPost('image');
if (isset($vendorLogo['delete']) && $vendorLogo['delete'] == 1) {
if ($vendorLogo['value'] != '') {
$_helper = Mage::helper('smvendors');
$file = Mage::getBaseDir('media') . DS . $_helper->updateDirSepereator($vendorLogo['value']);
try {
$io = new Varien_Io_File();
$result = $io->rmdir($file, true);
} catch (Exception $e) {
Mage::logException($e);
}
}
$imagedata['image'] = '';
$_model->setData('image', $imagedata['image']);
} else {
$_model->setData('image', $vendorLogo['value']);
}
}
try {
$_model->save();
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('smvendors')->__('Banner was successfully saved'));
Mage::getSingleton('adminhtml/session')->setFormData(false);
if ($this->getRequest()->getParam('back')) {
$this->_redirect('*/*/edit', array('id' => $_model->getId()));
return;
}
$this->_redirect('*/*/');
return;
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
Mage::getSingleton('adminhtml/session')->setFormData($data);
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
return;
}
}
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('smvendors')->__('Unable to find banner to save'));
$this->_redirect('*/*/');
}
示例11: clearCache
public function clearCache()
{
$directory = Mage::getBaseDir('media') . '/catalog/product/cache/';
$io = new Varien_Io_File();
$io->rmdir($directory, true);
}
示例12: create
/**
* Create new image for product and return image filename
*
* @param int|string $productId
* @param array $data
* @param string|int $store
* @return string
*/
public function create($productId, $data, $store = null)
{
$product = $this->_initProduct($productId, $store);
$gallery = $this->_getGalleryAttribute($product);
if (!isset($data->file) || !isset($data->file->mime) || !isset($data->file->content)) {
$this->_fault('data_invalid', AO::helper('catalog')->__('Image not specified.'));
}
if (!isset($this->_mimeTypes[$data->file->mime])) {
$this->_fault('data_invalid', AO::helper('catalog')->__('Invalid image type.'));
}
$fileContent = @base64_decode($data->file->content, true);
if (!$fileContent) {
$this->_fault('data_invalid', AO::helper('catalog')->__('Image content is not valid base64 data.'));
}
unset($data->file->content);
$tmpDirectory = AO::getBaseDir('var') . DS . 'api' . DS . $this->_getSession()->getSessionId();
$fileName = 'image.' . $this->_mimeTypes[$data->file->mime];
$ioAdapter = new Varien_Io_File();
try {
// Create temporary directory for api
$ioAdapter->checkAndCreateFolder($tmpDirectory);
$ioAdapter->open(array('path' => $tmpDirectory));
// Write image file
$ioAdapter->write($fileName, $fileContent, 0666);
unset($fileContent);
// Adding image to gallery
$file = $gallery->getBackend()->addImage($product, $tmpDirectory . DS . $fileName, null, true);
// Remove temporary directory
$ioAdapter->rmdir($tmpDirectory, true);
$_imageData = $this->_prepareImageData($data);
$gallery->getBackend()->updateImage($product, $file, $_imageData);
if (isset($data->types)) {
$gallery->getBackend()->setMediaAttribute($product, $data->types, $file);
}
$product->save();
} catch (Mage_Core_Exception $e) {
$this->_fault('not_created', $e->getMessage());
} catch (Exception $e) {
$this->_fault('not_created', AO::helper('catalog')->__('Can\'t create image.'));
}
return $gallery->getBackend()->getRenamedImage($file);
}
示例13: downloadProductImages
/**
* Download products media
*
* @param Varien_Object|null $item
* @return array
*/
public function downloadProductImages($item = null)
{
$ioAdapter = new Varien_Io_File();
$tmpDirectory = Mage::getBaseDir('var') . DS . 'api' . DS . uniqid();
$ioAdapter->checkAndCreateFolder($tmpDirectory);
$ioAdapter->open(array('path' => $tmpDirectory));
if (!$item) {
$items = Mage::getModel('retailops_api/catalog_media_item')->getCollection();
$limit = $this->getHelper()->getConfig('media_processing_products_limit');
if (!is_numeric($limit)) {
$limit = self::CRON_DOWNLOAD_LIMIT;
}
$items->getSelect()->limit($limit);
} else {
$items = array($item);
}
$result = array();
/** @var $item RetailOps_Api_Model_Catalog_Media_Item */
foreach ($items as $item) {
$productId = $item->getProductId();
$product = Mage::getModel('catalog/product')->load($productId);
$product->setStoreId(0);
//using default store for images import
$gallery = $this->_getGalleryAttribute($product);
$data = json_decode($item->getMediaData(), true);
$allImages = $this->_getResource()->getProductMedia($productId);
$this->_mediaKeys = array();
$this->_fileNames = array();
foreach ($allImages as $image) {
$this->_mediaKeys[] = $image['retailops_mediakey'];
$this->_fileNames[] = $image['value'];
}
$sku = $product->getSku();
$result[$sku] = array();
try {
$imageResult = array();
$newImages = array();
foreach ($data as $newImage) {
if ($this->_imageExists($newImage)) {
continue;
}
try {
$url = $newImage['download_url'];
if (!$this->_httpFileExists($url)) {
Mage::throwException('Image does not exist.');
}
$fileName = $this->_getFileName($url, $newImage['mediakey']);
$fileName = $tmpDirectory . DS . $fileName;
$ioAdapter->cp($url, $fileName);
// Adding image to gallery
$file = $gallery->getBackend()->addImage($product, $fileName, null, true);
// Remove temporary directory
$ioAdapter->rmdir($tmpDirectory, true);
$newImages[$file] = $newImage['mediakey'];
$gallery->getBackend()->updateImage($product, $file, $newImage);
if (isset($newImage['types'])) {
$gallery->getBackend()->setMediaAttribute($product, $newImage['types'], $file);
}
} catch (Exception $e) {
$imageResult[] = sprintf('Could not save image %s, error message: %s', $newImage['mediakey'], $e->getMessage());
}
}
if ($imageResult) {
$result[$sku]['images'] = $imageResult;
}
$product->save();
$this->_updateMediaKeys($product->getId(), $newImages);
if ($item->getId()) {
$item->delete();
}
$product->clearInstance();
} catch (Exception $e) {
$result[$sku]['general'] = $e->getMessage();
}
}
return $result;
}
示例14: clearCache
public function clearCache()
{
$directory = Mage::getSingleton('mstcore/media_config')->getBaseMediaPath() . DS . 'content' . DS . 'cache' . DS;
$io = new Varien_Io_File();
$io->rmdir($directory, true);
}
示例15: clearSwatchesCache
/**
* Cleans out the swatch image cache dir
*/
public function clearSwatchesCache()
{
$directory = Mage::getBaseDir(Mage_Core_Model_Store::URL_TYPE_MEDIA) . DS . self::SWATCH_CACHE_DIR;
$io = new Varien_Io_File();
$io->rmdir($directory, true);
Mage::helper('core/file_storage_database')->deleteFolder($directory);
}