/** * Roll back database * * @param string $rollbackFile * @return void * @throws LocalizedException */ public function dbRollback($rollbackFile) { if (preg_match('/[0-9]_(db)(.*?).(sql)$/', $rollbackFile) !== 1) { throw new LocalizedException(new Phrase('Invalid rollback file.')); } if (!$this->file->isExists($this->backupsDir . '/' . $rollbackFile)) { throw new LocalizedException(new Phrase('The rollback file does not exist.')); } /** @var \Magento\Framework\Backup\Db $dbRollback */ $dbRollback = $this->objectManager->create('Magento\\Framework\\Backup\\Db'); $dbRollback->setRootDir($this->directoryList->getRoot()); $dbRollback->setBackupsDir($this->backupsDir); $dbRollback->setBackupExtension('sql'); $time = explode('_', $rollbackFile); if (count($time) === 3) { $thirdPart = explode('.', $time[2]); $dbRollback->setName($thirdPart[0]); } $dbRollback->setTime($time[0]); $this->log->log('DB rollback is starting...'); $dbRollback->setResourceModel($this->objectManager->create('Magento\\Backup\\Model\\ResourceModel\\Db')); $dbRollback->rollback(); $this->log->log('DB rollback filename: ' . $dbRollback->getBackupFilename()); $this->log->log('DB rollback path: ' . $dbRollback->getBackupPath()); $this->log->logSuccess('DB rollback completed successfully.'); }
private function setupDbBackupRollback() { $this->database->expects($this->once())->method('setBackupsDir'); $this->database->expects($this->once())->method('setBackupExtension'); $this->database->expects($this->once())->method('setTime'); $this->database->expects($this->once())->method('getBackupFilename')->willReturn('RollbackFile_A.gz'); $this->database->expects($this->atLeastOnce())->method('getBackupPath')->willReturn('pathToFile/12345_db.tgz'); $this->log->expects($this->once())->method('logSuccess'); }
public function testCleanupDb() { $this->config->expects($this->once())->method('get')->with(ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT)->willReturn(self::$dbConfig); $this->connection->expects($this->at(0))->method('quoteIdentifier')->with('magento')->willReturn('`magento`'); $this->connection->expects($this->at(1))->method('query')->with('DROP DATABASE IF EXISTS `magento`'); $this->connection->expects($this->at(2))->method('query')->with('CREATE DATABASE IF NOT EXISTS `magento`'); $this->logger->expects($this->once())->method('log')->with('Cleaning up database `magento`'); $this->object->cleanupDb(); }
/** * Clear var/generation and reset object manager * * @return void */ private function cleanupGeneratedFiles() { $this->log->log('File system cleanup:'); $messages = $this->cleanupFiles->clearCodeGeneratedFiles(); // unload Magento autoloader because it may be using compiled definition foreach (spl_autoload_functions() as $autoloader) { if ($autoloader[0] instanceof \Magento\Framework\Code\Generator\Autoloader) { spl_autoload_unregister([$autoloader[0], $autoloader[1]]); break; } } // Corrected Magento autoloader will be loaded upon next get() call on $this->objectManagerProvider $this->objectManagerProvider->reset(); foreach ($messages as $message) { $this->log->log($message); } }
/** * Removes deployment configuration * * @return void */ private function deleteDeploymentConfig() { $configDir = $this->filesystem->getDirectoryWrite(DirectoryList::CONFIG); $configFiles = $this->deploymentConfigReader->getFiles(); foreach ($configFiles as $configFile) { $absolutePath = $configDir->getAbsolutePath($configFile); if (!$configDir->isFile($configFile)) { $this->log->log("The file '{$absolutePath}' doesn't exist - skipping cleanup"); continue; } try { $this->log->log($absolutePath); $configDir->delete($configFile); } catch (FileSystemException $e) { $this->log->log($e->getMessage()); } } }