Esempio n. 1
0
 public function rename($id, $title)
 {
     if (!$this->canDelete($id)) {
         throw new \RuntimeException("Outline '{$id}' cannot be renamed", 400);
     }
     $gantry = $this->container;
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     $path = $locator->findResource("gantry-config://{$id}", true, true);
     if (!$path || !is_dir($path)) {
         throw new \RuntimeException('Outline not found', 404);
     }
     $folder = trim(preg_replace('|[^a-z\\d_-]|ui', '_', $title), '_');
     if ($folder === 'default') {
         throw new \RuntimeException("Outline cannot use reserved name '{$folder}'", 400);
     }
     $newPath = $locator->findResource("gantry-config://{$folder}", true, true);
     if (is_dir($newPath)) {
         throw new \RuntimeException("Outline '{$id}' already exists.", 400);
     }
     try {
         Folder::move($path, $newPath);
     } catch (\Exception $e) {
         throw new \RuntimeException(sprintf('Renaming Outline failed: ', $e->getMessage()), 500, $e);
     }
 }