public function setUp() { parent::setUp(); $conn = $this->getConnection(); $options = array('disable_fks' => $conn->getDatabasePlatform() instanceof SqlitePlatform); $schema = new RepositorySchema($options, $conn); // do not use reset as we want to ignore exceptions on drop foreach ($schema->toDropSql($conn->getDatabasePlatform()) as $statement) { try { $conn->exec($statement); } catch (\Exception $e) { // ignore } } foreach ($schema->toSql($conn->getDatabasePlatform()) as $statement) { $conn->exec($statement); } $transport = $this->getTransport(); $repository = new \Jackalope\Repository(null, $transport); $session = $repository->login(new \PHPCR\SimpleCredentials("user", "passwd"), $GLOBALS['phpcr.workspace']); $a = $session->getNode('/')->addNode('node-a'); $a->addNode('child-a')->setProperty('prop', 'aa'); $a->addNode('child-b')->setProperty('prop', 'ab'); $b = $session->getNode('/')->addNode('node-b'); $b->addNode('child-a')->setProperty('prop', 'ba'); $b->addNode('child-b')->setProperty('prop', 'bb'); $session->save(); }
public function setUp() { parent::setUp(); $conn = $this->getConnection(); $options = array('disable_fks' => $conn->getDatabasePlatform() instanceof SqlitePlatform); $schema = new RepositorySchema($options, $conn); // do not use reset as we want to ignore exceptions on drop foreach ($schema->toDropSql($conn->getDatabasePlatform()) as $statement) { try { $conn->exec($statement); } catch (\Exception $e) { // ignore } } foreach ($schema->toSql($conn->getDatabasePlatform()) as $statement) { $conn->exec($statement); } $this->transport = new \Jackalope\Transport\DoctrineDBAL\Client(new \Jackalope\Factory(), $conn); $this->transport->createWorkspace('default'); $this->repository = new \Jackalope\Repository(null, $this->transport); try { $this->transport->createWorkspace($GLOBALS['phpcr.workspace']); } catch (\PHPCR\RepositoryException $e) { if ($e->getMessage() != "Workspace '" . $GLOBALS['phpcr.workspace'] . "' already exists") { // if the message is not that the workspace already exists, something went really wrong throw $e; } } $this->session = $this->repository->login(new \PHPCR\SimpleCredentials("user", "passwd"), $GLOBALS['phpcr.workspace']); }
/** * {@inheritDoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $connection = $this->getHelper('jackalope-doctrine-dbal')->getConnection(); if (!$connection instanceof Connection) { $output->write(PHP_EOL . '<error>The provided connection is not an instance of the Doctrine DBAL connection.</error>' . PHP_EOL); throw new \InvalidArgumentException('The provided connection is not an instance of the Doctrine DBAL connection.'); } if (true !== $input->getOption('dump-sql') && !$input->getOption('force')) { $output->write('ATTENTION: This operation should not be executed in a production environment. Please use "--force" to execute the command.' . PHP_EOL . PHP_EOL); return self::RETURN_CODE_NO_FORCE; } $schema = new RepositorySchema(); try { if ($input->getOption('drop')) { try { foreach ($schema->toDropSql($connection->getDatabasePlatform()) as $sql) { if (true === $input->getOption('dump-sql')) { $output->writeln($sql); } else { $connection->exec($sql); } } } catch (TableNotFoundException $e) { if (false === $input->getOption('force')) { throw $e; } // remove this once we require Doctrine DBAL 2.5+ } catch (DBALException $e) { if (false === $input->getOption('force')) { throw $e; } else { $output->writeln($e->getMessage()); } } } foreach ($schema->toSql($connection->getDatabasePlatform()) as $sql) { if (true === $input->getOption('dump-sql')) { $output->writeln($sql); } else { $connection->exec($sql); } } } catch (\PDOException $e) { if ("42S01" === $e->getCode()) { $output->write(PHP_EOL . '<error>The tables already exist. Nothing was changed.</error>' . PHP_EOL . PHP_EOL); return self::RETURN_CODE_NOT_DROP; } throw $e; } if (true !== $input->getOption('dump-sql')) { $output->writeln("Jackalope Doctrine DBAL tables have been initialized successfully."); } return 0; }
/** * {@inheritDoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $connection = $this->getHelper('jackalope-doctrine-dbal')->getConnection(); if (!$connection instanceof Connection) { $output->write(PHP_EOL.'<error>The provided connection is not an instance of the Doctrine DBAL connection.</error>'.PHP_EOL); throw new \InvalidArgumentException('The provided connection is not an instance of the Doctrine DBAL connection.'); } if (true !== $input->getOption('dump-sql')) { $output->write('ATTENTION: This operation should not be executed in a production environment.' . PHP_EOL . PHP_EOL); } $schema = new RepositorySchema; try { if ($input->getOption('drop')) { foreach ($schema->toDropSql($connection->getDatabasePlatform()) as $sql) { if (true === $input->getOption('dump-sql')) { $output->writeln($sql); } else { try { $connection->exec($sql); } catch (\Exception $e) { $output->writeln($e->getMessage()); } } } } foreach ($schema->toSql($connection->getDatabasePlatform()) as $sql) { if (true === $input->getOption('dump-sql')) { $output->writeln($sql); } else { $connection->exec($sql); } } } catch (\PDOException $e) { if ("42S01" == $e->getCode()) { $output->write(PHP_EOL.'<error>The tables already exist. Nothing was changed.</error>'.PHP_EOL.PHP_EOL); // TODO: add a parameter to drop old scheme first return; } throw $e; } if (true !== $input->getOption('dump-sql')) { $output->writeln("Jackalope Doctrine DBAL tables have been initialized successfully."); } }