如何在循环symfony中运行迁移命令?

时间:2018-08-21 06:05:13

标签: php symfony migration

在while循环中进行了尝试:

 $command = array(
                'command' => 'doctrine:migrations:execute',
                '--em' => "dynamic",
                'version' => $this->container->getParameter('migration_version')
 );
 $kernel = $this->getContainer()->get('kernel');
 $application = new Application($kernel);
 $application->setAutoExit(false);
 $input = new ArrayInput($command);
 $output = new BufferedOutput();
 $result = $application->run($input, $output);
 $s=$output->fetch();

得到的错误是:

  

迁移版本20171024105242已在课程中注册   学说\ DBAL \迁移\版本

请帮助我

public function switchDatabase($host, $user, $dbname)
    {
        //check the company database exist or not
        $password = getenv('DEFAULT_DB_PASSWORD');
        if (gettype($host) == 'resource') {
            $host = long2ip((int) stream_get_contents($host, -1, 0));
        }
        try {
            $conn = new PDO("mysql:host=" . $host . ";dbname=" . $dbname, $user, $password);

            // set the PDO error mode to exception
            $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

            $conn = null;
        } catch (\PDOException $e) {
            return $e->getMessage();
        }
        // dynamic DB switch
        $connection = $this->getContainer()->get(sprintf('doctrine.dbal.%s_connection', 'dynamic'));
        $connection->close();
        $refConn = new \ReflectionObject($connection);
        $refParams = $refConn->getProperty('_params');
        $refParams->setAccessible('public'); //we have to change it for a moment
        $params = $refParams->getValue($connection);
        $params['dbname'] = $dbname;
        $params['host'] = $host;
        $params['user'] = $user;
        $refParams->setAccessible('private');
        $refParams->setValue($connection, $params);
        $this->getContainer()->get('doctrine')->resetEntityManager('dynamic');

        return true;
    }

这是用于数据库切换的代码,数据库切换工作正常。但是上述错误是在第二次迁移循环后发生的

0 个答案:

没有答案