Пример #1
0
 /**
  * Delete all service folders from var directory
  */
 public function cleanVarFolder()
 {
     foreach ($this->getVarSubFolders() as $folder) {
         try {
             $this->_filesystem->delete($folder);
         } catch (Magento_Filesystem_Exception $e) {
         }
     }
 }
Пример #2
0
 /**
  * Delete Expired Captcha Images
  *
  * @return Mage_Captcha_Model_Observer
  */
 public function deleteExpiredImages()
 {
     foreach (Mage::app()->getWebsites(true) as $website) {
         $expire = time() - Mage::helper('Mage_Captcha_Helper_Data')->getConfigNode('timeout', $website->getDefaultStore()) * 60;
         $imageDirectory = Mage::helper('Mage_Captcha_Helper_Data')->getImgDir($website);
         foreach ($this->_filesystem->getNestedKeys($imageDirectory) as $filePath) {
             if ($this->_filesystem->isFile($filePath) && pathinfo($filePath, PATHINFO_EXTENSION) == 'png' && $this->_filesystem->getMTime($filePath) < $expire) {
                 $this->_filesystem->delete($filePath);
             }
         }
     }
     return $this;
 }
Пример #3
0
 /**
  * Delete file (and its thumbnail if exists) from storage
  *
  * @param string $target File path to be deleted
  * @return Mage_Cms_Model_Wysiwyg_Images_Storage
  */
 public function deleteFile($target)
 {
     if ($this->_filesystem->isFile($target)) {
         $this->_filesystem->delete($target);
     }
     Mage::helper('Mage_Core_Helper_File_Storage_Database')->deleteFile($target);
     $thumb = $this->getThumbnailPath($target, true);
     if ($thumb) {
         if ($this->_filesystem->isFile($thumb)) {
             $this->_filesystem->delete($thumb);
         }
         Mage::helper('Mage_Core_Helper_File_Storage_Database')->deleteFile($thumb);
     }
     return $this;
 }
Пример #4
0
 /**
  * Uninstall the application
  *
  * @return bool
  */
 public function uninstall()
 {
     if (!Mage::isInstalled()) {
         return false;
     }
     $this->_cleanUpDatabase();
     /* Remove temporary directories */
     $configOptions = Mage::app()->getConfig()->getOptions();
     $dirsToRemove = array($configOptions->getCacheDir(), $configOptions->getSessionDir(), $configOptions->getExportDir(), $configOptions->getLogDir(), $configOptions->getVarDir() . '/report');
     foreach ($dirsToRemove as $dir) {
         $this->_filesystem->delete($dir);
     }
     /* Remove local configuration */
     $this->_filesystem->delete($configOptions->getEtcDir() . '/local.xml');
     return true;
 }
Пример #5
0
 /**
  * Save file to storage
  *
  * @param string $filePath
  * @param string $content
  * @param bool $overwrite
  * @return bool
  */
 public function saveFile($filePath, $content, $overwrite = false)
 {
     if (strpos($filePath, $this->getMediaBaseDirectory()) !== 0) {
         $filePath = $this->getMediaBaseDirectory() . DS . $filePath;
     }
     try {
         if (!$this->_filesystem->isFile($filePath) || $overwrite && $this->_filesystem->delete($filePath)) {
             $this->_filesystem->write($filePath, $content);
             return true;
         }
     } catch (Magento_Filesystem_Exception $e) {
         $this->_logger->log($e->getMessage());
         Mage::throwException($this->_helper->__('Unable to save file: %s', $filePath));
     }
     return false;
 }
Пример #6
0
 /**
  * Copy image and return new filename.
  *
  * @param string $file
  * @return string
  */
 protected function _copyImage($file)
 {
     try {
         $destinationFile = $this->_getUniqueFileName($file);
         if (!$this->_filesystem->isFile($this->_getConfig()->getMediaPath($file), $this->_baseMediaPath)) {
             throw new Exception();
         }
         if (Mage::helper('Mage_Core_Helper_File_Storage_Database')->checkDbUsage()) {
             Mage::helper('Mage_Core_Helper_File_Storage_Database')->copyFile($this->_getConfig()->getMediaShortUrl($file), $this->_getConfig()->getMediaShortUrl($destinationFile));
             $this->_filesystem->delete($this->_getConfig()->getMediaPath($destinationFile), $this->_baseMediaPath);
         } else {
             $this->_filesystem->copy($this->_getConfig()->getMediaPath($file), $this->_getConfig()->getMediaPath($destinationFile), $this->_baseMediaPath);
         }
         return str_replace(DS, '/', $destinationFile);
     } catch (Exception $e) {
         $file = $this->_getConfig()->getMediaPath($file);
         Mage::throwException(Mage::helper('Mage_Catalog_Helper_Data')->__('Failed to copy file %s. Please, delete media with non-existing images and try again.', $file));
     }
 }
Пример #7
0
 /**
  * Open backup file (write or read mode)
  *
  * @param bool $write
  * @return Mage_Backup_Model_Backup
  * @throws Mage_Backup_Exception_NotEnoughPermissions
  */
 public function open($write = false)
 {
     if (is_null($this->getPath())) {
         Mage::exception('Mage_Backup', $this->_helper->__('Backup file path was not specified.'));
     }
     if ($write && $this->_filesystem->isFile($this->_getFilePath())) {
         $this->_filesystem->delete($this->_getFilePath());
     }
     if (!$write && !$this->_filesystem->isFile($this->_getFilePath())) {
         Mage::exception('Mage_Backup', $this->_helper->__('Backup file "%s" does not exist.', $this->getFileName()));
     }
     $mode = $write ? 'wb' . self::COMPRESS_RATE : 'rb';
     try {
         $compressStream = 'compress.zlib://';
         $workingDirectory = $this->_filesystem->getWorkingDirectory();
         $this->_stream = $this->_filesystem->createAndOpenStream($compressStream . $this->_getFilePath(), $mode, $compressStream . $workingDirectory);
     } catch (Magento_Filesystem_Exception $e) {
         throw new Mage_Backup_Exception_NotEnoughPermissions($this->_helper->__('Backup file "%s" cannot be read from or written to.', $this->getFileName()));
     }
     return $this;
 }
Пример #8
0
 public function clearCache()
 {
     $directory = Mage::getBaseDir('media') . DS . 'catalog' . DS . 'product' . DS . 'cache' . DS;
     $this->_filesystem->delete($directory);
     Mage::helper('Mage_Core_Helper_File_Storage_Database')->deleteFolder($directory);
 }
Пример #9
0
 /**
  * Turn off store maintenance mode
  */
 public function turnOffMaintenanceMode()
 {
     $maintenanceFlagFile = $this->getMaintenanceFlagFilePath();
     $this->_filesystem->delete($maintenanceFlagFile, Mage::getBaseDir());
 }
Пример #10
0
 /**
  * Remove all merged js/css files
  *
  * @return bool
  */
 public function cleanMergedJsCss()
 {
     $dir = $this->_buildPublicViewFilename(self::PUBLIC_MERGE_DIR);
     try {
         $this->_filesystem->delete($dir);
         $deleted = true;
     } catch (Magento_Filesystem_Exception $e) {
         $deleted = false;
     }
     return $deleted && Mage::helper('Mage_Core_Helper_File_Storage_Database')->deleteFolder($dir);
 }
Пример #11
0
 /**
  * Delete preview image
  *
  * @return Mage_Core_Model_Theme
  */
 public function removePreviewImage()
 {
     $previewImage = $this->getPreviewImage();
     $this->setPreviewImage('');
     if ($previewImage) {
         $this->_filesystem->delete($this->_getImagePathPreview() . DIRECTORY_SEPARATOR . $previewImage);
     }
     return $this;
 }