jump to correct hash after renaming a file
authorChristian Weiske <cweiske@cweiske.de>
Tue, 14 Jul 2015 06:05:03 +0000 (08:05 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Tue, 14 Jul 2015 06:05:03 +0000 (08:05 +0200)
src/phorkie/Repository/Post.php
www/edit.php

index 7a373aa..b9489e7 100644 (file)
@@ -13,6 +13,12 @@ class Repository_Post
      */
     public $newfileName;
 
+    /**
+     * List of files that have been renamed.
+     *
+     * @var array
+     */
+    public $renameMap = array();
 
 
     public function __construct(Repository $repo = null)
@@ -48,6 +54,9 @@ class Repository_Post
             $bChanged = true;
         }
 
+        $this->renameMap   = array();
+        $this->newfileName = null;
+
         foreach ($postData['files'] as $num => $arFile) {
             $bUpload = false;
             if ($_FILES['files']['error'][$num]['upload'] == 0) {
@@ -102,6 +111,7 @@ class Repository_Post
                         ->addArgument($name)
                         ->execute();
                     $bCommit = true;
+                    $this->renameMap[$originalName] = $name;
                 } else {
                     $name = $originalName;
                 }
index e7e6fbc..1ced7b6 100644 (file)
@@ -22,7 +22,14 @@ $repopo = new Repository_Post($repo);
 if ($repopo->process($_POST, $_SESSION)) {
     $anchor = '';
     if ($file instanceof File) {
-        $anchor = '#' . $file->getAnchorName();
+        if (isset($repopo->renameMap[$file->getFilename()])) {
+            $anchor = '#'
+                . $repo->getFileByName(
+                    $repopo->renameMap[$file->getFilename()]
+                )->getAnchorName();
+        } else {
+            $anchor = '#' . $file->getAnchorName();
+        }
     } else if ($file === 'newfile' && $repopo->newfileName) {
         $anchor = '#' . $repo->getFileByName($repopo->newfileName)->getAnchorName();
     }