/** * @param bool $isInProgress * @dataProvider progressStatusDataProvider */ public function testStatusCheckAjax($isInProgress) { $this->status->add($this->uniqueMessage); $this->status->setUpdateInProgress($isInProgress); $actualResponse = json_decode($this->getResponse(self::REQUEST_TYPE_AJAX), true); $this->assertInternalType('array', $actualResponse); $this->assertArrayHasKey('statusMessage', $actualResponse); $this->assertArrayHasKey('isUpdateInProgress', $actualResponse); $this->assertContains($this->uniqueMessage, $actualResponse['statusMessage']); $this->assertEquals($isInProgress, $actualResponse['isUpdateInProgress']); }
/** * Create backup archive using unix zip tool. * * @return $this * @throws \RuntimeException */ public function execute() { $backupFilePath = $this->backupInfo->getBackupPath() . $this->backupInfo->generateBackupFilename(); $command = $this->buildShellCommand($backupFilePath); $this->status->add(sprintf('Creating backup archive "%s" ...', $backupFilePath), \Psr\Log\LogLevel::INFO); exec($command, $output, $return); if ($return) { throw new \RuntimeException(sprintf('Cannot create backup with command "%s": %s', $command, implode("\n", $output), \Psr\Log\LogLevel::ERROR)); } $this->status->add(sprintf('Backup archive "%s" has been created.', $backupFilePath), \Psr\Log\LogLevel::INFO); return $this; }
/** * Unzip specified archive * * @param string $backupFilePath * @throws \RuntimeException * @return $this */ private function unzipArchive($backupFilePath) { $phar = new \PharData($backupFilePath); $tarFile = str_replace('.tgz', '.tar', $backupFilePath); if (@file_exists($tarFile)) { @unlink($tarFile); } $phar->decompress(); $tar = new \PharData($tarFile); if (strpos($backupFilePath, BackupInfo::BACKUP_MEDIA) > 0) { $this->deleteDirectory($this->restoreTargetDir . '/pub/media'); } elseif (strpos($backupFilePath, BackupInfo::BACKUP_CODE) > 0) { $blackListFolders = $this->backupInfo->getBlacklist(); $exclusions = []; foreach ($blackListFolders as $blackListFolder) { $exclusions[] = $this->restoreTargetDir . '/' . $blackListFolder; } try { $this->deleteDirectory($this->restoreTargetDir, $exclusions); } catch (\Exception $e) { $this->status->setUpdateError(); $this->status->add('Error during rollback ' . $e->getMessage(), \Psr\Log\LogLevel::ERROR); } } else { $this->status->setUpdateError(); $this->status->add('Invalid backup type', \Psr\Log\LogLevel::INFO); } $tar->extractTo($this->restoreTargetDir, null, true); @unlink($tarFile); //TODO Temporary solution, can be removed when MAGETWO-38589 is fixed. if (strpos($backupFilePath, BackupInfo::BACKUP_MEDIA) > 0) { $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->restoreTargetDir . '/pub/media'), \RecursiveIteratorIterator::SELF_FIRST); foreach ($iterator as $item) { @chmod($item, 0777); } } elseif (strpos($backupFilePath, BackupInfo::BACKUP_CODE) > 0) { $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->restoreTargetDir), \RecursiveIteratorIterator::SELF_FIRST); foreach ($iterator as $item) { @chmod($item, 0755); } $writeAccessFolders = ['/pub/media', '/pub/static', '/var']; foreach ($writeAccessFolders as $folder) { if (file_exists($this->restoreTargetDir . $folder)) { $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->restoreTargetDir . $folder), \RecursiveIteratorIterator::SELF_FIRST); foreach ($iterator as $item) { @chmod($item, 0777); } } } } //TODO Till here }
/** * Set maintenance mode. * * @param bool $isOn * @return $this * @throws \RuntimeException */ public function set($isOn) { if ($isOn) { if (touch($this->flagFile)) { $this->status->add("Magento maintenance mode is enabled.", \Psr\Log\LogLevel::INFO); } else { throw new \RuntimeException("Magento maintenance mode cannot be enabled."); } } else { if (file_exists($this->flagFile)) { if (file_exists($this->ipFile)) { /** Maintenance mode should not be unset from updater application if it was set manually by the admin */ $this->status->add("Magento maintenance mode was not disabled. It can be disabled from the Magento Backend.", \Psr\Log\LogLevel::INFO); } else { if (unlink($this->flagFile)) { $this->status->add("Magento maintenance mode is disabled.", \Psr\Log\LogLevel::INFO); } else { throw new \RuntimeException("Magento maintenance mode cannot be disabled."); } } } } return $this; }