_binary From 850fa3b088440cbd78a1c265838749205805d998 Mon Sep 17 00:00:00 2001
From: Yashi Kamboj <yashi.kamboj@gmail.com>
Date: Sun, 27 Nov 2016 23:37:15 -0800
Subject: [PATCH] Resolves Issue 184, revised previous patch

---
 src/controllers/components/SocialComponent.php |  3 ++-
 src/models/GroupModel.php                      | 14 ++++++++++++--
 src/views/elements/WikiElement.php             |  2 +-
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/controllers/components/SocialComponent.php b/src/controllers/components/SocialComponent.php
index f7bb905..2395675 100644
--- a/src/controllers/components/SocialComponent.php
+++ b/src/controllers/components/SocialComponent.php
@@ -2227,7 +2227,8 @@ class SocialComponent extends Component implements CrawlConstants
                 list($data["TOTAL_TO_PAGES"], $data["PAGES_THAT_LINK_TO"],
                     $data["TOTAL_FROM_PAGES"], $data["PAGES_THAT_LINK_FROM"]) =
                     $group_model->pagesLinkedWithRelationship($page_id,
-                    $rel_type, $limit, $num);
+                        $data["GROUP_ID"], $data["PAGE_NAME"], $rel_type,
+                        $limit, $num);
             }
         }
         if (!$page_name) {
diff --git a/src/models/GroupModel.php b/src/models/GroupModel.php
index 29a8dfa..5293844 100644
--- a/src/models/GroupModel.php
+++ b/src/models/GroupModel.php
@@ -1206,10 +1206,20 @@ class GroupModel extends Model implements MediaConstants
      * @return two arrays of elements which represent all pages linked
      *     to and from the given wiki page with a particular relationship
      */
-    public function pagesLinkedWithRelationship($page_id, $relationship, $limit,
-        $num)
+    public function pagesLinkedWithRelationship($page_id, $group_id, 
+        $page_name, $relationship, $limit, $num)
     {
         $db = $this->db;
+        //get data from group pre link and insert to group link
+        $sql = "INSERT INTO GROUP_PAGE_LINK (LINK_TYPE_ID, FROM_ID, TO_ID) ".
+            "SELECT LINK_TYPE_ID, FROM_ID, ?  FROM GROUP_PAGE_PRE_LINK ".
+            "WHERE TO_GROUP_ID = ? AND TO_PAGE_NAME = ?";
+        $db->execute($sql, [$page_id, $group_id, $page_name]);
+        $sql = "DELETE FROM GROUP_PAGE_PRE_LINK WHERE TO_GROUP_ID = ? AND " .
+            "TO_PAGE_NAME = ?";
+        $db->execute($sql, [$group_id, $page_name]);
+        $sql = "DELETE FROM GROUP_PAGE_PRE_LINK WHERE FROM_ID = ?";
+        $db->execute($sql, [$page_id]);
         //get the count of pages that link to the given page
         $sql = "SELECT COUNT(*) AS NUM
             FROM GROUP_PAGE_LINK L, PAGE_RELATIONSHIP P
diff --git a/src/views/elements/WikiElement.php b/src/views/elements/WikiElement.php
index d97d46a..154b78d 100644
--- a/src/views/elements/WikiElement.php
+++ b/src/views/elements/WikiElement.php
@@ -1261,7 +1261,7 @@ class WikiElement extends Element implements CrawlConstants
             $url = htmlentities(B\wikiUrl($var, true,
                 $data['CONTROLLER'], $data['GROUP_ID']));
             $url .= $csrf_token;
-            e("<td><a href='$url'>$var</a></td>");
+            e("<td><a href='$url'>$var</a><br/ ></td>");
         }
     }
     /**
-- 
1.9.5.msysgit.0

