From 4d986aa8332c94d128f73f84558b7b22ed413629 Mon Sep 17 00:00:00 2001
From: Roger Feese <rfeese@unl.edu>
Date: Wed, 27 Jan 2016 13:18:04 -0600
Subject: [PATCH] Add additional checks for existence of files when loading
 notes.

---
 .../bulletin/controllers/ViewController.php   | 32 +++++++++++--------
 .../bulletin/models/RepositoryModel.php       |  3 +-
 2 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/application/modules/bulletin/controllers/ViewController.php b/application/modules/bulletin/controllers/ViewController.php
index a01ef797..c6da5d62 100644
--- a/application/modules/bulletin/controllers/ViewController.php
+++ b/application/modules/bulletin/controllers/ViewController.php
@@ -146,22 +146,26 @@ class Bulletin_ViewController extends Requests_ViewController
 
             $parentCommit = $repo->getParentCommitForSection($section);
 
-            $contents = $repo->getFileNotes(
-                '/data/' . $repo->getFilePathForSection($section), $parentCommit
-            );
-
-            $originalFileContents = $repo->getFileContents('/data/' . $repo->getFilePathForSection($section), $parentCommit);
-	    $originalFileContents = Bulletin_SectionModel::getBodyHtml($originalFileContents);
-            //$originalFileContents = UNL_UndergraduateBulletin_EPUB_Utilities::format($originalFileContents);
-            $originalFileContents = UNL_UndergraduateBulletin_EPUB_Utilities::convertHeadings($originalFileContents);
+            // Original file content
+            $originalFileContents = "";
+            $originalFilePath = $repo->getFilePathForSection($section);
+            // Only attempt to get notes if getFilePathForSection actually returns a value
+            if(!empty($originalFilePath)){
+                $originalFileContents = $repo->getFileContents('/data/' . $originalFilePath, $parentCommit);
+                $originalFileContents = Bulletin_SectionModel::getBodyHtml($originalFileContents);
+                $originalFileContents = UNL_UndergraduateBulletin_EPUB_Utilities::convertHeadings($originalFileContents);
+            }
             $requestOriginalFileContents[$request->getId()] = $originalFileContents;
 
-            $proposedFileContents = $repo->getFileNotes(
-                '/data/' . $repo->getFilePathForSection($section), 'request-' . $request->getId()
-            );
-            $proposedFileContents = Bulletin_SectionModel::getBodyHtml($proposedFileContents);
-            //$proposedFileContents = UNL_UndergraduateBulletin_EPUB_Utilities::format($proposedFileContents);
-            $proposedFileContents = UNL_UndergraduateBulletin_EPUB_Utilities::convertHeadings($proposedFileContents);
+            // Proposed file content
+            $proposedFileContents = "";
+            $proposedFilePath = $repo->getFilePathForSection($section);
+            // Only attempt to get notes if getFilePathForSection actually returns a value
+            if(!empty($proposedFilePath)){
+                $proposedFileContents = $repo->getFileNotes('/data/' . $proposedFilePath, 'request-' . $request->getId());
+                $proposedFileContents = Bulletin_SectionModel::getBodyHtml($proposedFileContents);
+                $proposedFileContents = UNL_UndergraduateBulletin_EPUB_Utilities::convertHeadings($proposedFileContents);
+            }
             $requestProposedFileContents[$request->getId()] = $proposedFileContents;
         }
 
diff --git a/application/modules/bulletin/models/RepositoryModel.php b/application/modules/bulletin/models/RepositoryModel.php
index f0d79cee..8a53c4af 100644
--- a/application/modules/bulletin/models/RepositoryModel.php
+++ b/application/modules/bulletin/models/RepositoryModel.php
@@ -67,7 +67,8 @@ class Bulletin_RepositoryModel
         $filepath = $this->_repoPath . '/' . $path;
 
         $this->_checkout($branch);
-        if(file_exists($filepath)){
+        //make sure path exists and it is a file
+        if(file_exists($filepath) && is_file($filepath)){
             $this->_git_exec('hash-object ' . escapeshellarg($filepath), $object);
             $this->_git_exec('notes --ref=creq show ' .  escapeshellarg($object), $note);
         }
-- 
GitLab