示例#1
0
文件: Job.php 项目: mygento/cdn
 /**
  * Upload file to CDN async
  */
 public function uploadFile()
 {
     $adapter = Mage::getModel('mycdn/adapter');
     if (!$adapter) {
         return;
     }
     $ioObject = new Varien_Io_File();
     $ioObject->setAllowCreateFolders(true);
     $ioObject->open(array('path' => $ioObject->dirname($this->getData('filename'))));
     if (!$ioObject->fileExists($this->getData('filename'), true)) {
         Mage::helper('mycdn')->addLog('[CRON] No file ' . $this->getData('filename'));
         $this->delete();
         return;
     }
     //Mage::helper('mycdn')->addLog('[CRON] processing id = ' . $this->getId());
     //Mage::helper('mycdn')->addLog($this->getData());
     $result = $adapter->uploadFile($this->getData('filename'), $this->getData('uploadname'), $this->getData('content_type'));
     if ($result && $this->getData('delete')) {
         $ioObject->rm($this->getData('filename'));
         Mage::helper('mycdn')->addLog('[DELETE] CRON delete for ' . $this->getData('filename'));
     }
     if ($result) {
         Mage::helper('mycdn')->addLog('[JOB] CRON delete job for ' . $this->getData('filename') . "\n");
         $this->delete();
     }
 }
示例#2
0
文件: Data.php 项目: mygento/cdn
 public function isFileExists($fileName)
 {
     $ioObject = new Varien_Io_File();
     $ioObject->setAllowCreateFolders(true);
     $ioObject->open(array('path' => $ioObject->dirname($fileName)));
     if ($ioObject->fileExists($fileName, true)) {
         return true;
     }
     return false;
 }
示例#3
0
 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();
 }
 /**
  * Use to load the patches array with applied patches.
  *
  * @return void
  */
 protected function _loadPatchFile()
 {
     $ioAdapter = new Varien_Io_File();
     if (!$ioAdapter->fileExists($this->patchFile)) {
         return;
     }
     $ioAdapter->open(array('path' => $ioAdapter->dirname($this->patchFile)));
     $ioAdapter->streamOpen($this->patchFile, 'r');
     while ($buffer = $ioAdapter->streamRead()) {
         if (stristr($buffer, '|')) {
             list($date, $patch) = array_map('trim', explode('|', $buffer));
             $this->appliedPatches[] = $patch;
         }
     }
     $ioAdapter->streamClose();
 }
示例#5
0
 /**
  * Declare headers and content file in response for file download
  *
  * @param string $fileName
  * @param string|array $content set to null to avoid starting output, $contentLength should be set explicitly in
  *                              that case
  * @param string $contentType
  * @param int $contentLength    explicit content length, if strlen($content) isn't applicable
  * @return Mage_Core_Controller_Varien_Action
  */
 protected function _prepareDownloadResponse($fileName, $content, $contentType = 'application/octet-stream', $contentLength = null)
 {
     $session = Mage::getSingleton('admin/session');
     if ($session->isFirstPageAfterLogin()) {
         $this->_redirect($session->getUser()->getStartupPageUrl());
         return $this;
     }
     $isFile = false;
     $file = null;
     if (is_array($content)) {
         if (!isset($content['type']) || !isset($content['value'])) {
             return $this;
         }
         if ($content['type'] == 'filename') {
             $isFile = true;
             $file = $content['value'];
             $contentLength = filesize($file);
         }
     }
     $this->getResponse()->setHttpResponseCode(200)->setHeader('Pragma', 'public', true)->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)->setHeader('Content-type', $contentType, true)->setHeader('Content-Length', is_null($contentLength) ? strlen($content) : $contentLength, true)->setHeader('Content-Disposition', 'attachment; filename="' . $fileName . '"', true)->setHeader('Last-Modified', date('r'), true);
     if (!is_null($content)) {
         if ($isFile) {
             $this->getResponse()->clearBody();
             $this->getResponse()->sendHeaders();
             $ioAdapter = new Varien_Io_File();
             $ioAdapter->open(array('path' => $ioAdapter->dirname($file)));
             $ioAdapter->streamOpen($file, 'r');
             while ($buffer = $ioAdapter->streamRead()) {
                 print $buffer;
             }
             $ioAdapter->streamClose();
             if (!empty($content['rm'])) {
                 $ioAdapter->rm($file);
             }
             exit(0);
         } else {
             $this->getResponse()->setBody($content);
         }
     }
     return $this;
 }
示例#6
0
 /**
  * Debug write to file process
  *
  * @param string $str
  */
 protected function _debugWriteToFile($str)
 {
     $str = '## ' . date('Y-m-d H:i:s') . "\r\n" . $str;
     if (!$this->_debugIoAdapter) {
         $this->_debugIoAdapter = new Varien_Io_File();
         $dir = Mage::getBaseDir() . DS . $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();
 }
示例#7
0
 /**
  * Retrieve file content from file container array
  *
  * @param array $fileData
  * @return string
  */
 protected function _getFileContainerContent(array $fileData)
 {
     $io = new Varien_Io_File();
     $path = $io->dirname($fileData['value']);
     $io->open(array('path' => $path));
     return $io->read($fileData['value']);
 }
示例#8
0
 /**
  * Redirect customer to parent directory of current request.
  *
  * If the current redirect is to the top level (matches the base URL), don't do a redirect.
  *
  * @param $targetRouteSetting
  * @return bool Redirect was applied
  */
 protected function _applyEntityRedirectParentDirectory($targetRouteSetting)
 {
     $currectUrl = $this->_getCurrentUrl();
     $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, Mage::app()->getStore()->isCurrentlySecure());
     // Cut off query string at the end if present
     if (($pos = strpos($currectUrl, '?')) !== false) {
         $currectUrl = substr($currectUrl, 0, $pos);
     }
     // Paranoid check - _getCurrentUrl() should always be within the current base URL ;)
     if (strpos($currectUrl, $baseUrl) === 0) {
         // Remove base URL from beginning
         $path = substr($currectUrl, strlen($baseUrl));
         if (strlen($path) > 0) {
             // Only apply dirname() if there is a parent directory
             $io = new Varien_Io_File();
             if (($path = $io->dirname($path)) === '.') {
                 $path = '';
             }
             // Append configured category file suffix if this still isn't a top level request
             if (strlen($path) > 0) {
                 $path .= Mage::helper('catalog/category')->getCategoryUrlSuffix();
             }
             $targetUrl = $baseUrl . $path;
             if ($targetUrl != $currectUrl) {
                 $this->_sendRedirectHeaders($targetUrl, false);
                 return true;
             }
         }
     }
     // Don't display configured message if we already are requesting the target (top level) url.
     $this->_addMessage = false;
     return false;
 }
示例#9
0
 /**
  * Declare headers and content file in response for file download
  *
  * @param string $fileName
  * @param string|array $content set to null to avoid starting output, $contentLength should be set explicitly in
  *                              that case
  * @param string $contentType
  * @param int $contentLength    explicit content length, if strlen($content) isn't applicable
  * @return Mage_Core_Controller_Varien_Action
  */
 protected function _prepareDownloadResponse($fileName, $content, $contentType = 'application/octet-stream', $contentLength = null)
 {
     $isFile = false;
     $file = null;
     if (is_array($content)) {
         if (!isset($content['type']) || !isset($content['value'])) {
             return $this;
         }
         if ($content['type'] == 'filename') {
             $isFile = true;
             $file = $content['value'];
             $contentLength = filesize($file);
         }
     }
     $this->getResponse()->setHttpResponseCode(200)->setHeader('Pragma', 'public', true)->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)->setHeader('Content-type', $contentType, true)->setHeader('Content-Length', is_null($contentLength) ? strlen($content) : $contentLength, true)->setHeader('Content-Disposition', 'attachment; filename="' . $fileName . '"', true)->setHeader('Last-Modified', date('r'), true);
     if (!is_null($content)) {
         if ($isFile) {
             $this->getResponse()->clearBody();
             $this->getResponse()->sendHeaders();
             $ioAdapter = new Varien_Io_File();
             if (!$ioAdapter->fileExists($file)) {
                 Mage::throwException(Mage::helper('Mage_Core_Helper_Data')->__('File not found'));
             }
             $ioAdapter->open(array('path' => $ioAdapter->dirname($file)));
             $ioAdapter->streamOpen($file, 'r');
             while ($buffer = $ioAdapter->streamRead()) {
                 print $buffer;
             }
             $ioAdapter->streamClose();
             if (!empty($content['rm'])) {
                 $ioAdapter->rm($file);
             }
             exit(0);
         } else {
             $this->getResponse()->setBody($content);
         }
     }
     return $this;
 }