Exemplo n.º 1
0
 /**
  * @param Mageplace_Backup_Model_Backup $backup
  * @param null                          $bytes
  *
  * @throws Mageplace_Backup_Exception|Mage_Core_Exception
  * @return bool|int
  */
 public function getMemoryLimit($backup, $bytes = null)
 {
     if (is_null($bytes)) {
         $mBytes = Mageplace_Backup_Model_Backup::MEMORY_LIMIT;
     } else {
         $mBytes = intval($bytes);
     }
     if (!$mBytes || !$backup instanceof Mageplace_Backup_Model_Backup) {
         throw Mage::exception('Mageplace_Backup', $this->__('Wrong input data'));
     }
     $secret = $backup->getBackupSecret();
     $client = new Varien_Http_Client();
     $client->setUri(Mage::helper('mpbackup/url')->getCheckMemoryLimitUrl())->setConfig(array('timeout' => 30))->setHeaders('accept-encoding', '')->setParameterPost(array('backup_secret' => $secret, 'mbytes' => $mBytes))->setMethod(Zend_Http_Client::POST);
     if ($backup->getProfileData(Mageplace_Backup_Model_Profile::COLUMN_AUTH_ENABLE) && ($user = $backup->getProfileData(Mageplace_Backup_Model_Profile::COLUMN_AUTH_USER))) {
         $client->setAuth($user, $backup->getProfileData(Mageplace_Backup_Model_Profile::COLUMN_AUTH_PASSWORD));
     }
     $response = $client->request();
     $body = $response->getRawBody();
     if ($body == Mageplace_Backup_Helper_Const::MEMORY_LIMIT_OK) {
         return true;
     } elseif ($body == Mageplace_Backup_Helper_Const::MEMORY_LIMIT_FALSE) {
         throw Mage::exception('Mageplace_Backup', $this->__('Extension can\'t get memory limit'));
     } else {
         $memoryLimitFile = $this->getCheckMemoryLimitFileLocation($backup);
         if (!file_exists($memoryLimitFile)) {
             if ($body) {
                 $backup->addBackupProcessMessage($body, Mageplace_Backup_Model_Backup::LOG_LEVEL_WARNING);
             }
             throw Mage::exception('Mageplace_Backup', $this->__('Extension can\'t get memory limit'));
         }
         $steps = @file($this->getCheckMemoryLimitFileLocation($backup), FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
         if (empty($steps) || !is_array($steps)) {
             if ($body) {
                 $backup->addBackupProcessMessage($body, Mageplace_Backup_Model_Backup::LOG_LEVEL_WARNING);
             }
             throw Mage::exception('Mageplace_Backup', $this->__('Extension can\'t get memory limit'));
         }
         $last = array_pop($steps);
         @(list($iterator, $mpu) = explode('-', $last));
         if ($mpu) {
             $memoryLimit = $mpu / 1024 / 1024;
         } else {
             $memoryLimit = $iterator;
         }
         $memoryLimit = (int) $memoryLimit;
         if ($memoryLimit <= Mageplace_Backup_Model_Backup::MEMORY_LIMIT_LOW) {
             throw Mage::exception('Mageplace_Backup', $this->__('Memory limit too low (%s Mb)', $memoryLimit));
         }
         return $memoryLimit;
     }
 }
Exemplo n.º 2
0
 /**
  * @param Mageplace_Backup_Model_Backup $backup
  *
  * @return $this
  */
 public function setBackup(Mageplace_Backup_Model_Backup $backup)
 {
     $this->_backup = $backup;
     $this->_backupId = $backup->getId();
     $this->_backupSecret = $backup->getBackupSecret();
     $this->_request = $backup->getRequest();
     return $this;
 }