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 7a373aaf9005e65343c831700db81d2ef327403f..b9489e77cd48bffbe6c22d66389b638b95198d2d 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 e7e6fbcc9422de965b928d162fb18d989f30c6ad..1ced7b6a64fc812745bebb7ec7b32ba3cafa3fd7 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();
     }