/** * @param string $content * @return void */ public function updateTranslationFileContent($content) { $translationDir = $this->directoryList->getPath(DirectoryList::STATIC_VIEW) . \DIRECTORY_SEPARATOR . $this->assetRepo->getStaticViewFileContext()->getPath(); if (!$this->driverFile->isExists($this->getTranslationFileFullPath())) { $this->driverFile->createDirectory($translationDir, \Magento\Framework\Filesystem\Driver\File::WRITEABLE_DIRECTORY_MODE); } $this->driverFile->filePutContents($this->getTranslationFileFullPath(), $content); }
/** * @param string $content * @return void */ public function updateTranslationFileContent($content) { $translationDir = $this->directoryList->getPath(DirectoryList::STATIC_VIEW) . \DIRECTORY_SEPARATOR . $this->assetRepo->getStaticViewFileContext()->getPath(); if (!$this->driverFile->isExists($this->getTranslationFileFullPath())) { $this->driverFile->createDirectory($translationDir); } $this->driverFile->filePutContents($this->getTranslationFileFullPath(), $content); }
/** * gets current js-translation.json timestamp * * @return string|void */ public function getTranslationFileTimestamp() { $translationFilePath = $this->getTranslationFileFullPath(); if ($this->driverFile->isExists($translationFilePath)) { $statArray = $this->driverFile->stat($translationFilePath); if (array_key_exists('mtime', $statArray)) { return $statArray['mtime']; } } }
/** * Retrieve the shop version * * @return string */ public function getShopVersion() { $directory = $this->_filesystem->getDirectoryRead(DirectoryList::CONFIG); $path = $directory->getAbsolutePath() . 'version.txt'; if (!$this->filesystemDriver->isExists($path)) { return false; } $version = $this->filesystemDriver->fileGetContents($path); $version = trim($version); return $version; }
/** * @param string $logFile * @return string */ protected function getFilePath($logFile) { $logFileDir = dirname($logFile); if (!$this->filesystem->getRealPath($logFileDir)) { if (substr($logFileDir, 0, 1) != '/') { $logFileDir = __DIR__ . '/../../../' . $logFileDir; $logFile = $logFileDir . '/' . basename($logFile); } if (!$this->filesystem->isExists($logFileDir)) { $this->filesystem->createDirectory($logFileDir, $this->permissions); } } return $logFile; }
/** * 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.'); }
/** * @param string $logFile * @return string */ protected function getFilePath($logFile) { $logFileDir = dirname($logFile); if (!$this->file->getRealPath($logFileDir)) { if (substr($logFileDir, 0, 1) != '/') { $logFileDir = $this->filesystem->getDirectoryRead(DirectoryList::VAR_DIR)->getAbsolutePath() . $logFileDir; $logFile = $logFileDir . DIRECTORY_SEPARATOR . basename($logFile); } if (!$this->file->isExists($logFileDir)) { $this->file->createDirectory($logFileDir, $this->permissions); } } elseif ($logFileDir == '.') { $logFile = $this->filesystem->getDirectoryRead(DirectoryList::VAR_DIR)->getAbsolutePath() . basename($logFile); } return $logFile; }
/** * Determine whether a CLI command is for compilation, and if so, clear the directory * * @throws \Magento\Framework\Exception\FileSystemException * @return void */ public function handleCompilerEnvironment() { $compilationCommands = [DiCompileCommand::NAME, DiCompileMultiTenantCommand::NAME]; $cmdName = $this->input->getFirstArgument(); $isHelpOption = $this->input->hasParameterOption('--help') || $this->input->hasParameterOption('-h'); if (!in_array($cmdName, $compilationCommands) || $isHelpOption) { return; } $generationDir = $cmdName === DiCompileMultiTenantCommand::NAME ? $this->input->getParameterOption(DiCompileMultiTenantCommand::INPUT_KEY_GENERATION) : null; if (!$generationDir) { $mageInitParams = $this->serviceManager->get(InitParamListener::BOOTSTRAP_PARAM); $mageDirs = isset($mageInitParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS]) ? $mageInitParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] : []; $generationDir = (new DirectoryList(BP, $mageDirs))->getPath(DirectoryList::GENERATION); } if ($this->filesystemDriver->isExists($generationDir)) { $this->filesystemDriver->deleteDirectory($generationDir); } }
/** * Determine whether a CLI command is for compilation, and if so, clear the directory * * @throws \Magento\Framework\Exception\FileSystemException * @return void */ public function handleCompilerEnvironment() { $compilationCommands = [DiCompileCommand::NAME]; $cmdName = $this->input->getFirstArgument(); $isHelpOption = $this->input->hasParameterOption('--help') || $this->input->hasParameterOption('-h'); if (!in_array($cmdName, $compilationCommands) || $isHelpOption) { return; } $compileDirList = []; $mageInitParams = $this->serviceManager->get(InitParamListener::BOOTSTRAP_PARAM); $mageDirs = isset($mageInitParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS]) ? $mageInitParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] : []; $directoryList = new DirectoryList(BP, $mageDirs); $compileDirList[] = $directoryList->getPath(DirectoryList::GENERATION); $compileDirList[] = $directoryList->getPath(DirectoryList::DI); foreach ($compileDirList as $compileDir) { if ($this->filesystemDriver->isExists($compileDir)) { $this->filesystemDriver->deleteDirectory($compileDir); } } }
/** * Change permissions for directories by their code * * @param array $directoryCodeList * @param int $dirPermissions * @param int $filePermissions * @return void * @deprecated */ protected function changePermissions($directoryCodeList, $dirPermissions, $filePermissions) { foreach ($directoryCodeList as $code) { $directoryPath = $this->directoryList->getPath($code); if ($this->driverFile->isExists($directoryPath)) { $this->filesystem->getDirectoryWrite($code)->changePermissionsRecursively('', $dirPermissions, $filePermissions); } else { $this->driverFile->createDirectory($directoryPath, $dirPermissions); } } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $backupsDir = $this->directoryList->getPath(DirectoryList::VAR_DIR) . '/' . BackupRollback::DEFAULT_BACKUP_DIRECTORY; if ($this->file->isExists($backupsDir)) { $contents = $this->file->readDirectoryRecursively($backupsDir); $tempTable = []; foreach ($contents as $path) { $partsOfPath = explode('/', str_replace('\\', '/', $path)); $fileName = $partsOfPath[count($partsOfPath) - 1]; // if filename starts with '.' skip, e.g. '.git' if (!(strpos($fileName, '.') === 0)) { $filenameWithoutExtension = explode('.', $fileName); // actually first part of $filenameWithoutExtension contains only the filename without extension // and filename contains the type of backup separated by '_' $fileNameParts = explode('_', $filenameWithoutExtension[0]); if (in_array(Factory::TYPE_MEDIA, $fileNameParts)) { $tempTable[$fileName] = Factory::TYPE_MEDIA; } elseif (in_array(Factory::TYPE_DB, $fileNameParts)) { $tempTable[$fileName] = Factory::TYPE_DB; } elseif (in_array('code', $fileNameParts)) { $tempTable[$fileName] = 'code'; } } } if (empty($tempTable)) { $output->writeln('<info>No backup files found.</info>'); return; } $output->writeln("<info>Showing backup files in {$backupsDir}.</info>"); /** @var \Symfony\Component\Console\Helper\Table $table */ $table = $this->getHelperSet()->get('table'); $table->setHeaders(['Backup Filename', 'Backup Type']); asort($tempTable); foreach ($tempTable as $key => $value) { $table->addRow([$key, $value]); } $table->render($output); } else { $output->writeln('<info>No backup files found.</info>'); } }
/** * @param string $fileName * @return bool */ public function fileExists($fileName) { return $this->filesystemDriver->isExists($fileName); }