コード例 #1
0
ファイル: BackupCommand.php プロジェクト: jousch/clitools
 /**
  * Add filter to command
  *
  * @param CommandBuilderInterface $command  Command
  * @param string                  $database Database
  * @param string                  $filter   Filter name
  *
  * @return CommandBuilderInterface
  */
 protected function addFilterArguments(CommandBuilderInterface $commandDump, $database, $filter)
 {
     $command = $commandDump;
     // get filter
     $filterList = $this->getApplication()->getConfigValue('mysql-backup-filter', $filter);
     if (empty($filterList)) {
         throw new \RuntimeException('MySQL dump filters "' . $filter . '" not available"');
     }
     $this->output->writeln('<comment>Using filter "' . $filter . '"</comment>');
     // Get filtered tables
     $tableList = DatabaseConnection::tableList($database);
     $ignoredTableList = FilterUtility::mysqlIgnoredTableFilter($tableList, $filterList, $database);
     // Dump only structure
     $commandStructure = clone $command;
     $commandStructure->addArgument('--no-data');
     // Dump only data (only filtered tables)
     $commandData = clone $command;
     $commandData->addArgument('--no-create-info');
     if (!empty($ignoredTableList)) {
         $commandData->addArgumentTemplateMultiple('--ignore-table=%s', $ignoredTableList);
     }
     // Combine both commands to one
     $command = new \CliTools\Shell\CommandBuilder\OutputCombineCommandBuilder();
     $command->addCommandForCombinedOutput($commandStructure)->addCommandForCombinedOutput($commandData);
     return $command;
 }
コード例 #2
0
ファイル: AbstractCommand.php プロジェクト: jousch/clitools
 /**
  * Add mysqldump filter to command
  *
  * @param CommandBuilderInterface $commandDump  Command
  * @param string                  $database     Database
  * @param boolean                 $isRemote     Remote filter
  *
  * @return CommandBuilderInterface
  */
 protected function addMysqlDumpFilterArguments(CommandBuilderInterface $commandDump, $database, $isRemote = true)
 {
     $command = $commandDump;
     $filter = $this->contextConfig->get('mysql.filter');
     // get filter
     if (is_array($filter)) {
         $filterList = (array) $filter;
         $filter = 'custom table filter';
     } else {
         $filterList = $this->getApplication()->getConfigValue('mysql-backup-filter', $filter);
     }
     if (empty($filterList)) {
         throw new \RuntimeException('MySQL dump filters "' . $filter . '" not available"');
     }
     $this->output->writeln('<p>Using filter "' . $filter . '"</p>');
     // Get table list (from cloned mysqldump command)
     if ($isRemote) {
         $tableListDumper = $this->createRemoteMySqlCommand($database);
     } else {
         $tableListDumper = $this->createLocalMySqlCommand($database);
     }
     $tableListDumper->addArgumentTemplate('-e %s', 'show tables;');
     // wrap with ssh (for remote execution)
     if ($isRemote) {
         $tableListDumper = $this->wrapRemoteCommand($tableListDumper);
     }
     $tableList = $tableListDumper->execute()->getOutput();
     // Filter table list
     $ignoredTableList = FilterUtility::mysqlIgnoredTableFilter($tableList, $filterList, $database);
     // Dump only structure
     $commandStructure = clone $command;
     $commandStructure->addArgument('--no-data')->clearPipes();
     // Dump only data (only filtered tables)
     $commandData = clone $command;
     $commandData->addArgument('--no-create-info')->clearPipes();
     if (!empty($ignoredTableList)) {
         $commandData->addArgumentTemplateMultiple('--ignore-table=%s', $ignoredTableList);
     }
     $commandPipeList = $command->getPipeList();
     // Combine both commands to one
     $command = new OutputCombineCommandBuilder();
     $command->addCommandForCombinedOutput($commandStructure)->addCommandForCombinedOutput($commandData);
     // Read compression pipe
     if (!empty($commandPipeList)) {
         $command->setPipeList($commandPipeList);
     }
     return $command;
 }