/** * 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; }
public function testTurnOnMaintenanceModeFailed() { $this->getDirectory(); $this->directoryWrite->expects($this->once())->method('writeFile')->with(MaintenanceMode::FLAG_FILENAME, 'data')->will($this->throwException(new \Magento\Framework\Filesystem\FilesystemException('failed'))); $this->assertFalse($this->model->turnOn('data')); }