/** * @param string $action * @dataProvider actionProvider */ public function testAction($action) { $this->_backupFactoryMock->expects($this->once())->method('create'); $rootDir = TESTS_TEMP_DIR . '/Magento/Backup/data'; $model = new \Magento\Framework\Backup\Nomedia($this->_filesystemMock, $this->_backupFactoryMock); $model->setRootDir($rootDir); $model->setBackupsDir($rootDir); $model->{$action}(); $this->assertTrue($model->getIsSuccess()); $this->assertEquals([$rootDir, $rootDir . '/media', $rootDir . '/pub/media'], $model->getIgnorePaths()); }
/** * 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; }
/** * @param string $action * @dataProvider actionProvider */ public function testAction($action) { $this->_backupFactoryMock->expects($this->once())->method('create'); $rootDir = str_replace('\\', '/', TESTS_TEMP_DIR) . '/Magento/Backup/data'; $model = new \Magento\Framework\Backup\Media($this->_filesystemMock, $this->_backupFactoryMock); $model->setRootDir($rootDir); $model->setBackupsDir($rootDir); $model->{$action}(); $this->assertTrue($model->getIsSuccess()); $this->assertTrue($model->{$action}()); $ignorePaths = $model->getIgnorePaths(); $expected = [$rootDir, $rootDir . '/app', $rootDir . '/var/log']; $ignored = array_intersect($expected, $ignorePaths); sort($ignored); $this->assertEquals($expected, $ignored); }
/** * 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; }
/** * @param string $action * @dataProvider actionProvider */ public function testAction($action) { $this->_backupFactoryMock->expects($this->once())->method('create'); $rootDir = TESTS_TEMP_DIR . '/Magento/Backup/data'; $model = new \Magento\Framework\Backup\Media($this->_filesystemMock, $this->_backupFactoryMock); $model->setRootDir($rootDir); $model->setBackupsDir($rootDir); $model->{$action}(); $this->assertTrue($model->getIsSuccess()); $this->assertTrue($model->{$action}()); $ignorePaths = $model->getIgnorePaths(); $rootDir = str_replace('\\', '/', $rootDir); foreach ($ignorePaths as &$path) { if (strpos($path, '~tmp-') || strpos($path, '_media')) { unlink($path); } $path = str_replace('\\', '/', $path); } $this->assertTrue(in_array($rootDir, $ignorePaths)); $this->assertTrue(in_array($rootDir . '/code', $ignorePaths)); $this->assertTrue(in_array($rootDir . '/var/log', $ignorePaths)); }
/** * @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)); }
/** * 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()); }
/** * 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()); }