Jackalope\Transport\DoctrineDBAL\Client::createWorkspace PHP Method

createWorkspace() public method

{@inheritDoc}
public createWorkspace ( $name, $srcWorkspace = null )
    public function createWorkspace($name, $srcWorkspace = null)
    {
        if (null !== $srcWorkspace) {
            throw new NotImplementedException('Creating workspace as clone of existing workspace not supported');
        }
        if ($this->workspaceExists($name)) {
            throw new RepositoryException("Workspace '{$name}' already exists");
        }
        try {
            $this->getConnection()->insert('phpcr_workspaces', array('name' => $name));
        } catch (\Exception $e) {
            throw new RepositoryException("Couldn't create Workspace '{$name}': " . $e->getMessage(), 0, $e);
        }
        $this->getConnection()->insert('phpcr_nodes', array('path' => '/', 'parent' => '', 'workspace_name' => $name, 'identifier' => $this->generateUuid(), 'type' => 'nt:unstructured', 'local_name' => '', 'namespace' => '', 'props' => '<?xml version="1.0" encoding="UTF-8"?>
<sv:node xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:sv="http://www.jcp.org/jcr/sv/1.0" xmlns:rep="internal" />', 'depth' => 0));
    }

Usage Example

 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']);
 }
All Usage Examples Of Jackalope\Transport\DoctrineDBAL\Client::createWorkspace