/** * @expectedException \RuntimeException * @expectedExceptionMessage Exception */ public function testExecuteException() { $om = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $jobUpdate = $om->create('Magento\\Update\\Queue\\JobUpdate', ['composerApp' => $this->composerApp, 'status' => $this->status, 'params' => ['components' => [['name' => 'vendor/package', 'version' => '1.0']]], 'queue' => $this->queue, 'name' => 'setup:upgrade']); $this->status->expects($this->atLeastOnce())->method('add'); $this->composerApp->expects($this->at(0))->method('runComposerCommand')->with(['command' => 'require', 'packages' => ['vendor/package 1.0'], '--no-update' => true])->willReturn('Success'); $this->composerApp->expects($this->at(1))->method('runComposerCommand')->with(['command' => 'update'])->will($this->throwException(new \Exception('Exception'))); $this->status->expects($this->once())->method('setUpdateError')->with(true); $jobUpdate->execute(); }
/** * @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 }
/** * Test invalid queue file * * @expectedException /RuntimeException * @expectedExceptionMessage RuntimeException: Missing job params "params" field is missing for one or more jobs */ public function testInvalidQueue() { file_put_contents(MAGENTO_BP . '/var/.update_queue.json', '{ "jobs": [ { "name": "backup" } ], "ignored_field": "" }'); shell_exec('php -f ' . $this->cronScript); $jobStatus = $this->status->get(); $this->assertContains('"params" field is missing for one or more jobs', $jobStatus); }
/** * 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; }