瀏覽代碼

Agregado del comando para exportar datos desde una tabla a un archivo yaml

Agregado de los parametros where y action
Your Name 7 年之前
父節點
當前提交
8b39b8738e
共有 1 個文件被更改,包括 6 次插入3 次删除
  1. 6 3
      Command/CreateYamlForImportCommand.php

+ 6 - 3
Command/CreateYamlForImportCommand.php

@@ -21,7 +21,9 @@ class CreateYamlForImportCommand extends ContainerAwareCommand
             ->setDescription('Create yaml for import.')
             ->setHelp('Create yaml from table.')
             ->addArgument('table', InputArgument::REQUIRED, "Table name to export data.")
-            ->addArgument('file-name', InputArgument::REQUIRED, "Name of the file.");
+            ->addArgument('file-name', InputArgument::REQUIRED, "Name of the file.")
+            ->addOption("where", null, InputOption::VALUE_OPTIONAL, "Where for sql sentece.", "")
+            ->addOption("action", null, InputOption::VALUE_OPTIONAL, "Action for sql sentencies. Options: INSERT, UPDATE, DELETE, REPLACE, INSERTORUPDATE, INSERTIGNORE", "INSERTORUPDATE");
     }
 
     protected function execute(InputInterface $input, OutputInterface $output)
@@ -30,10 +32,11 @@ class CreateYamlForImportCommand extends ContainerAwareCommand
         $table = $input->getArgument('table');
         $fileName = $input->getArgument('file-name');
 
-        $stmt = $em->getConnection()->executeQuery("select * from " . $table);
+        $stmt = $em->getConnection()->executeQuery("select * from " . $table .
+            (trim($input->getOption("where")) == '' ? '' : ' where ' . $input->getOption("where")));
         if ($stmt->rowCount() > 0) {
             $result = $stmt->fetchAll();
-            $str = "insertorupdate:\n";
+            $str = $input->getOption("action") . ":\n";
             $str .= "  $table:\n";
             foreach ($result as $row) {
                 $first = true;