コード例 #1
0
ファイル: Cloud.php プロジェクト: CE-Webmaster/CE-Hub
 public function getInstance($appName)
 {
     if (!$appName || in_array($appName, self::$WRONG_APP_NAMES)) {
         $appName = self::DEFAULT_CLOUD_APP;
     }
     $signature = $appName = strtolower($appName);
     $model = Mage::registry('mpbackup_cloud_' . $signature);
     if (empty($model)) {
         $model = Mage::getModel('mpbackup/cloud_' . $appName);
         if (empty($model)) {
             Mage::throwException($this->_helper->__('Invalid model "%s"', 'mpbackup/cloud_' . $appName));
         }
         $model->setData('app_name', $appName);
         $settings = $this->_helper->getAppConfig($signature);
         $model->setData('settings', $settings);
         Mage::unregister('mpbackup_cloud_' . $signature);
         Mage::register('mpbackup_cloud_' . $signature, $model);
     }
     return $model;
 }
コード例 #2
0
ファイル: File.php プロジェクト: CE-Webmaster/CE-Hub
 public function prepareFileToUpload($size = self::DEFAULT_FILE_PART_SIZE)
 {
     if ($size < 0.001) {
         $size = 0;
     }
     $sizeByte = round($size * 1024 * 1024);
     if (!$sizeByte || Mageplace_Backup_Model_File::filesize($this->getFileLocation()) <= $sizeByte) {
         return array(array('filename' => $this->getFileName(), 'filelocation' => $this->getFileLocation()));
     }
     $this->_addBackupProcessMessage($this->_helper->__('Start splitting "%s" file into parts', $this->getFileName()), Mageplace_Backup_Model_Backup::LOG_LEVEL_INFO);
     $readFilePartSize = $size < self::READ_FILE_PART_SIZE ? self::READ_FILE_PART_SIZE / 1024 : self::READ_FILE_PART_SIZE;
     $counter = 0;
     $return = array();
     $handle = fopen($this->getFileLocation(), 'r');
     while (!feof($handle)) {
         $counter++;
         $filename = $this->getFileName(null, $counter);
         $fileLoc = $this->getPath() . DS . $this->getFileName(null, $counter);
         $sizeCounter = 0;
         $handle_w = fopen($fileLoc, 'a');
         $this->getBackup()->addFilesForDelete($fileLoc);
         $wrote = true;
         do {
             $filePart = fread($handle, $readFilePartSize);
             if (fwrite($handle_w, $filePart) === false) {
                 $wrote = false;
                 break;
             }
             $sizeCounter += $readFilePartSize;
         } while ($sizeCounter < $sizeByte && !feof($handle));
         fclose($handle_w);
         if ($wrote == false) {
             $this->_addBackupProcessMessage($this->_helper->__("Write file \"%s\" error. Split process was stopped.", $fileLoc), Mageplace_Backup_Model_Backup::LOG_LEVEL_WARNING);
             break;
         } else {
             $return[] = array('filename' => $filename, 'filelocation' => $fileLoc);
         }
     }
     fclose($handle);
     $this->setFileParts($counter);
     $this->_addBackupProcessMessage($this->_helper->__('Finish splitting "%s" file into parts', $this->getFileName()), Mageplace_Backup_Model_Backup::LOG_LEVEL_INFO);
     return $return;
 }
コード例 #3
0
ファイル: Tar.php プロジェクト: CE-Webmaster/CE-Hub
 protected function _packFile($file, $bytes = null)
 {
     if (is_string($file)) {
         if (($v_file = @fopen($file, "rb")) == 0) {
             $this->_addBackupProcessMessage('Unable to open file "' . $file . '" in binary read mode', Mageplace_Backup_Model_Backup::LOG_LEVEL_WARNING);
             return true;
         }
     } elseif (is_resource($file)) {
         $v_file = $file;
         $file = stream_get_meta_data($v_file);
         $file = $file['uri'];
     } else {
         $this->_addBackupProcessMessage('Error input data', Mageplace_Backup_Model_Backup::LOG_LEVEL_WARNING);
         return false;
     }
     $bytes = (double) $bytes;
     if ($bytes > 0) {
         $this->fseek($v_file, $bytes);
     } else {
         $relDir = strtr($file, array($this->_baseDir => ''));
         $this->_addBackupProcessMessage($this->_helper->__('Adding "%s" file to archive', $relDir));
     }
     while (($v_buffer = fread($v_file, 512)) != '') {
         /*if ($bytes > 0 && !isset($first)) {
             Mage::log('#');Mage::log($v_buffer);Mage::log('#');
               $first = true;
           }*/
         $this->_writeBlock(pack("a512", "{$v_buffer}"));
         $bytes += 512;
         if ($this->timeIsUp()) {
             $this->_timeIsUp = true;
             $this->setStepParams($file, $bytes);
             /*Mage::log('#');Mage::log($v_buffer);Mage::log('#');*/
             break;
         }
     }
     fclose($v_file);
     if (!$this->_timeIsUp) {
         $this->setStepParams(null, null);
     }
     return true;
 }