/** * {@inheritdoc} */ public function execute(InputInterface $input, OutputInterface $output) { $webspaceKey = $input->getArgument('webspaceKey'); $locale = $input->getArgument('locale'); $basePath = $input->getOption('base-path'); $dryRun = $input->getOption('dry-run'); $this->session = $this->getContainer()->get('doctrine_phpcr')->getManager()->getPhpcrSession(); $this->sessionManager = $this->getContainer()->get('sulu.phpcr.session'); $this->output = $output; $path = $this->sessionManager->getRoutePath($webspaceKey, $locale); $relativePath = $basePath !== null ? '/' . ltrim($basePath, '/') : '/'; $fullPath = rtrim($path . $relativePath, '/'); if (!$this->session->nodeExists($fullPath)) { $this->output->write('<error>Resource-Locator "' . $relativePath . '" not found</error>'); return; } $node = $this->session->getNode($fullPath); $this->cleanup($node, $path, $dryRun); if (false === $dryRun) { $this->output->writeln('<info>Saving ...</info>'); $this->session->save(); $this->output->writeln('<info>Done</info>'); } else { $this->output->writeln('<info>Dry run complete</info>'); } }
/** * {@inheritDoc} */ public function match(EventInterface $event) { if (!$event->getPath()) { // Some events (like PERSIST) don't have a path return false; } // An event might have been raised for a node that does not exist anymore if (!$this->session->nodeExists($event->getPath())) { return false; } $node = $this->session->getNode($event->getPath()); foreach ($this->nodeTypes as $type) { if ($node->isNodeType($type)) { return true; } } return false; }
/** * Implement the workspace clone method. It is dispatched immediately. * http://www.day.com/specs/jcr/2.0/3_Repository_Model.html#3.10%20Corresponding%20Nodes * http://www.day.com/specs/jcr/2.0/10_Writing.html#10.8%20Cloning%20and%20Updating%20Nodes * * @param string $srcWorkspace the name of the workspace from which the copy is to be made. * @param string $srcAbsPath the path of the node to be cloned. * @param string $destAbsPath the location to which the node at srcAbsPath is to be cloned in this workspace. * @param boolean $removeExisting * * @throws \PHPCR\UnsupportedRepositoryOperationException * @throws \PHPCR\ItemExistsException * * @see Workspace::cloneFrom() */ public function cloneFromImmediately($srcWorkspace, $srcAbsPath, $destAbsPath, $removeExisting) { if (!$this->transport instanceof WritingInterface) { throw new UnsupportedRepositoryOperationException('Transport does not support writing'); } $srcAbsPath = PathHelper::normalizePath($srcAbsPath); $destAbsPath = PathHelper::normalizePath($destAbsPath, true); if (!$removeExisting && $this->session->nodeExists($destAbsPath)) { throw new ItemExistsException('Node already exists at destination and removeExisting is false'); } $this->transport->cloneFrom($srcWorkspace, $srcAbsPath, $destAbsPath, $removeExisting); }
/** * Implement the workspace copy method. It is dispatched immediately. * * @param string $srcAbsPath the path of the node to be copied. * @param string $destAbsPath the location to which the node at srcAbsPath * is to be copied in this workspace. * @param string $srcWorkspace the name of the workspace from which the * copy is to be made. * * @return void * * @see Workspace::copy() */ public function copyNodeImmediately($srcAbsPath, $destAbsPath, $srcWorkspace) { if (!$this->transport instanceof WritingInterface) { throw new UnsupportedRepositoryOperationException('Transport does not support writing'); } $this->verifyAbsolutePath($srcAbsPath); $this->verifyAbsolutePath($destAbsPath); if ($this->session->nodeExists($destAbsPath)) { throw new ItemExistsException('Node already exists at destination (update-on-copy is currently not supported)'); // to support this, we would have to update the local cache of nodes as well } $this->transport->copyNode($srcAbsPath, $destAbsPath, $srcWorkspace); }
/** * {@inheritDoc} * * @api */ public function unlock($absPath) { if (!$this->session->nodeExists($absPath)) { throw new PathNotFoundException("Unable to unlock unexisting node '{$absPath}'"); } if (!array_key_exists($absPath, $this->locks)) { throw new LockException("Unable to find an active lock for the node '{$absPath}'"); } $node = $this->session->getNode($absPath); $state = $node->getState(); if ($state === Item::STATE_NEW || $state === Item::STATE_MODIFIED) { throw new InvalidItemStateException("Cannot unlock the non-clean node '{$absPath}': current state = {$state}"); } $this->transport->unlock($absPath, $this->locks[$absPath]->getLockToken()); $this->locks[$absPath]->setIsLive(false); }
/** * Imports workspace. * * @param SessionInterface $session * @param string $path * @param string $fileName */ private function import(SessionInterface $session, $path, $fileName) { if ($session->nodeExists($path)) { $session->getNode($path)->remove(); $session->save(); } $session->importXML(PathHelper::getParentPath($path), $fileName, ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_THROW); $session->save(); }
private function cleanSession(OutputInterface $output, SessionInterface $session, $path, $dryRun) { $sessionName = $session->getWorkspace()->getName(); $output->writeln(sprintf('<info>Session</info> %s', $sessionName)); if (!$session->nodeExists($path)) { $output->write(sprintf('<error>Resource-Locator "%s" not found in session "%s"</error>', $path, $sessionName)); return; } $node = $session->getNode($path); $this->cleanup($output, $node, $path, $dryRun); $output->writeln(''); }