/**
  * Create Backup
  *
  * @return $this
  */
 public function execute()
 {
     if (!$this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_ENABLED, ScopeInterface::SCOPE_STORE)) {
         return $this;
     }
     if ($this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_MAINTENANCE_MODE, ScopeInterface::SCOPE_STORE)) {
         $this->maintenanceMode->set(true);
     }
     $type = $this->_scopeConfig->getValue(self::XML_PATH_BACKUP_TYPE, ScopeInterface::SCOPE_STORE);
     $this->_errors = [];
     try {
         $backupManager = $this->_backupFactory->create($type)->setBackupExtension($this->_backupData->getExtensionByType($type))->setTime(time())->setBackupsDir($this->_backupData->getBackupsDir());
         $this->_coreRegistry->register('backup_manager', $backupManager);
         if ($type != \Magento\Framework\Backup\Factory::TYPE_DB) {
             $backupManager->setRootDir($this->_filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath())->addIgnorePaths($this->_backupData->getBackupIgnorePaths());
         }
         $backupManager->create();
         $message = $this->_backupData->getCreateSuccessMessageByType($type);
         $this->_logger->info($message);
     } catch (\Exception $e) {
         $this->_errors[] = $e->getMessage();
         $this->_errors[] = $e->getTrace();
         $this->_logger->info($e->getMessage());
         $this->_logger->critical($e);
     }
     if ($this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_MAINTENANCE_MODE, ScopeInterface::SCOPE_STORE)) {
         $this->maintenanceMode->set(false);
     }
     return $this;
 }
Esempio n. 2
0
 /**
  * Create Backup
  *
  * @return \Magento\Log\Model\Cron
  */
 public function scheduledBackup()
 {
     if (!$this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_ENABLED, ScopeInterface::SCOPE_STORE)) {
         return $this;
     }
     if ($this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_MAINTENANCE_MODE, ScopeInterface::SCOPE_STORE)) {
         $this->maintenanceMode->turnOn();
     }
     $type = $this->_scopeConfig->getValue(self::XML_PATH_BACKUP_TYPE, ScopeInterface::SCOPE_STORE);
     $this->_errors = array();
     try {
         $backupManager = $this->_backupFactory->create($type)->setBackupExtension($this->_backupData->getExtensionByType($type))->setTime(time())->setBackupsDir($this->_backupData->getBackupsDir());
         $this->_coreRegistry->register('backup_manager', $backupManager);
         if ($type != \Magento\Framework\Backup\Factory::TYPE_DB) {
             $backupManager->setRootDir($this->_filesystem->getPath(\Magento\Framework\App\Filesystem::ROOT_DIR))->addIgnorePaths($this->_backupData->getBackupIgnorePaths());
         }
         $backupManager->create();
         $message = $this->_backupData->getCreateSuccessMessageByType($type);
         $this->_logger->log($message);
     } catch (\Exception $e) {
         $this->_errors[] = $e->getMessage();
         $this->_errors[] = $e->getTrace();
         $this->_logger->log($e->getMessage(), \Zend_Log::ERR);
         $this->_logger->logException($e);
     }
     if ($this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_MAINTENANCE_MODE, ScopeInterface::SCOPE_STORE)) {
         $this->maintenanceMode->turnOff();
     }
     return $this;
 }
Esempio n. 3
0
 /**
  * @param string $type
  * @dataProvider allowedTypesDataProvider
  */
 public function testCreate($type)
 {
     $this->_objectManager->expects($this->once())->method('create')->will($this->returnValue('ModelInstance'));
     $this->assertEquals('ModelInstance', $this->_model->create($type));
 }
Esempio n. 4
0
 /**
  * Create Db Instance
  *
  * @return BackupInterface
  */
 protected function _createDbBackupInstance()
 {
     return $this->_backupFactory->create(Factory::TYPE_DB)->setBackupExtension('gz')->setTime($this->getTime())->setBackupsDir($this->_filesystem->getDirectoryWrite(DirectoryList::VAR_DIR)->getAbsolutePath())->setResourceModel($this->getResourceModel());
 }
Esempio n. 5
0
 /**
  * Create Db Instance
  *
  * @return \Magento\Framework\Backup\BackupInterface
  */
 protected function _createDbBackupInstance()
 {
     return $this->_backupFactory->create(\Magento\Framework\Backup\Factory::TYPE_DB)->setBackupExtension('gz')->setTime($this->getTime())->setBackupsDir($this->_filesystem->getPath(\Magento\Framework\App\Filesystem::VAR_DIR))->setResourceModel($this->getResourceModel());
 }