예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function toOptionArray()
 {
     $backupTypes = [];
     foreach ($this->_backupData->getBackupTypes() as $type => $label) {
         $backupTypes[] = ['label' => $label, 'value' => $type];
     }
     return $backupTypes;
 }
예제 #2
0
 /**
  * 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;
 }
예제 #3
0
파일: Observer.php 프로젝트: aiesh/magento2
 /**
  * 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;
 }
예제 #4
0
 /**
  * @covers \Magento\Backup\Model\Backup::output
  * @param bool $isFile
  * @param string $result
  * @dataProvider outputDataProvider
  */
 public function testOutput($isFile, $result)
 {
     $path = '/path/to';
     $time = 1;
     $name = 'test';
     $type = 'db';
     $extension = 'sql';
     $relativePath = '/path/to/1_db_test.sql';
     $contents = 'test_result';
     $this->directoryMock->expects($this->atLeastOnce())->method('isFile')->with($relativePath)->willReturn($isFile);
     $this->directoryMock->expects($this->any())->method('getRelativePath')->with($relativePath)->willReturn($relativePath);
     $this->directoryMock->expects($this->any())->method('readFile')->with($relativePath)->willReturn($contents);
     $this->dataHelperMock->expects($this->any())->method('getExtensionByType')->with($type)->willReturn($extension);
     $this->backupModel->setPath($path);
     $this->backupModel->setName($name);
     $this->backupModel->setTime($time);
     $this->assertEquals($result, $this->backupModel->output());
 }
예제 #5
0
 /**
  * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
  * @param \Magento\Backup\Helper\Data $backupData
  * @param \Magento\Framework\Filesystem $filesystem
  * @param \Magento\Backup\Model\Backup $backup
  */
 public function __construct(\Magento\Framework\Data\Collection\EntityFactory $entityFactory, \Magento\Backup\Helper\Data $backupData, \Magento\Framework\Filesystem $filesystem, \Magento\Backup\Model\Backup $backup)
 {
     $this->_backupData = $backupData;
     parent::__construct($entityFactory);
     $this->_filesystem = $filesystem;
     $this->_backup = $backup;
     $this->_varDirectory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
     $this->_hideBackupsForApache();
     // set collection specific params
     $extensions = $this->_backupData->getExtensions();
     foreach ($extensions as $value) {
         $extensions[] = '(' . preg_quote($value, '/') . ')';
     }
     $extensions = implode('|', $extensions);
     $this->_varDirectory->create($this->_path);
     $path = rtrim($this->_varDirectory->getAbsolutePath($this->_path), '/') . '/';
     $this->setOrder('time', self::SORT_ORDER_DESC)->addTargetDir($path)->setFilesFilter('/^[a-z0-9\\-\\_]+\\.' . $extensions . '$/')->setCollectRecursively(false);
 }
예제 #6
0
파일: Backup.php 프로젝트: opexsw/magento2
 /**
  * Sets type of file
  *
  * @param string $value
  * @return $this
  */
 public function setType($value = 'db')
 {
     $possibleTypes = $this->_helper->getBackupTypesList();
     if (!in_array($value, $possibleTypes)) {
         $value = $this->_helper->getDefaultBackupType();
     }
     $this->_type = $value;
     $this->setData('type', $this->_type);
     return $this;
 }
예제 #7
0
 /**
  * @covers \Magento\Backup\Controller\Adminhtml\Index\Download::execute
  */
 public function testExecuteBackupFound()
 {
     $time = 1;
     $type = 'db';
     $filename = 'filename';
     $size = 10;
     $output = 'test';
     $this->backupModelMock->expects($this->atLeastOnce())->method('getTime')->willReturn($time);
     $this->backupModelMock->expects($this->atLeastOnce())->method('exists')->willReturn(true);
     $this->backupModelMock->expects($this->atLeastOnce())->method('getSize')->willReturn($size);
     $this->backupModelMock->expects($this->atLeastOnce())->method('output')->willReturn($output);
     $this->requestMock->expects($this->any())->method('getParam')->willReturnMap([['time', null, $time], ['type', null, $type]]);
     $this->backupModelFactoryMock->expects($this->once())->method('create')->with($time, $type)->willReturn($this->backupModelMock);
     $this->dataHelperMock->expects($this->once())->method('generateBackupDownloadName')->with($this->backupModelMock)->willReturn($filename);
     $this->objectManagerMock->expects($this->once())->method('get')->with('Magento\\Backup\\Helper\\Data')->willReturn($this->dataHelperMock);
     $this->fileFactoryMock->expects($this->once())->method('create')->with($filename, null, DirectoryList::VAR_DIR, 'application/octet-stream', $size)->willReturn($this->responseMock);
     $this->resultRawMock->expects($this->once())->method('setContents')->with($output);
     $this->resultRawFactoryMock->expects($this->once())->method('create')->willReturn($this->resultRawMock);
     $this->assertSame($this->resultRawMock, $this->downloadController->execute());
 }
예제 #8
0
 public function testGetRollbackIgnorePaths()
 {
     $this->assertEquals(['.svn', '.git', 'var/' . MaintenanceMode::FLAG_FILENAME, DirectoryList::SESSION, DirectoryList::LOG, DirectoryList::VAR_DIR . '/locks', DirectoryList::VAR_DIR . '/report', DirectoryList::ROOT . '/errors', DirectoryList::ROOT . '/index.php'], $this->helper->getRollbackIgnorePaths());
 }
예제 #9
0
 public function testGetRollbackIgnorePaths()
 {
     $this->filesystem->expects($this->any())->method('getPath')->will($this->returnValueMap([[MaintenanceMode::FLAG_DIR, MaintenanceMode::FLAG_DIR], [Filesystem::SESSION_DIR, Filesystem::SESSION_DIR], [Filesystem::ROOT_DIR, Filesystem::ROOT_DIR], [Filesystem::LOG_DIR, Filesystem::LOG_DIR], [Filesystem::VAR_DIR, Filesystem::VAR_DIR]]));
     $this->assertEquals(['.svn', '.git', 'var/maintenance.flag', Filesystem::SESSION_DIR, Filesystem::LOG_DIR, Filesystem::VAR_DIR . '/locks', Filesystem::VAR_DIR . '/report', Filesystem::ROOT_DIR . '/errors', Filesystem::ROOT_DIR . '/index.php'], $this->helper->getRollbackIgnorePaths());
 }
예제 #10
0
 /**
  * Return backup types array
  * @return array
  */
 public function toOptionArray()
 {
     return $this->_helper->getBackupTypes();
 }
예제 #11
0
 /**
  * Check permission for rollback
  *
  * @return bool
  */
 public function isDisplayed()
 {
     return $this->_backupHelper->isRollbackAllowed();
 }