_binary From d088f6b4290f4f0397e723e7e14ca8d0c8d46d5e Mon Sep 17 00:00:00 2001
From: pomishra13 <pooja192009@gmail.com>
Date: Fri, 10 Apr 2015 14:49:41 -0700
Subject: [PATCH 1/2] MEDIA UPDATER UI CHANGES

---
 configs/createdb.php             |  2 ++
 controllers/admin_controller.php | 22 ++++++++++++++++++++--
 lib/upgrade_functions.php        | 15 +++++++++++++--
 models/machine_model.php         | 38 ++++++++++++++++++++++++++++++++++++++
 models/profile_model.php         |  3 +++
 scripts/basic.js                 | 22 +++++++++++++++++++++-
 views/machinestatus_view.php     | 35 ++++++++++++++++++++++++++++++++---
 7 files changed, 129 insertions(+), 8 deletions(-)

diff --git a/configs/createdb.php b/configs/createdb.php
index baa62c4..c0af002 100755
--- a/configs/createdb.php
+++ b/configs/createdb.php
@@ -383,6 +383,8 @@ $db->execute("INSERT INTO MEDIA_SOURCE VALUES ('1342634199',
 $db->execute("INSERT INTO MEDIA_SOURCE VALUES ('1342634200',
     'Yahoo News', 'rss', 'http://news.yahoo.com/rss/',
     '###//content/@url', 'en-US')");
+$db->execute("INSERT INTO MEDIA_UPDATER_PROPERTIES
+    VALUES ('Present_on_name_server','true')");
 $db->execute("INSERT INTO CRAWL_MIXES VALUES (2, 'images', ".ROOT_ID.", -1)");
 $db->execute("INSERT INTO MIX_FRAGMENTS VALUES(2, 0, 1)");
 $db->execute("INSERT INTO MIX_COMPONENTS VALUES(
diff --git a/controllers/admin_controller.php b/controllers/admin_controller.php
index 0751d60..acba845 100755
--- a/controllers/admin_controller.php
+++ b/controllers/admin_controller.php
@@ -57,14 +57,16 @@ class AdminController extends Controller implements CrawlConstants
      * components)
      * @var array
      */
-    var $activities = array("crawlStatus", "machineStatus");
+    var $activities = array("crawlStatus", "machineStatus",
+        "mediaUpdaterStatus");
     /**
      * An array of activities which are periodically updated within other
      * activities that they live. For example, within manage crawl,
      * the current crawl status is updated every 20 or so seconds.
      * @var array
      */
-    var $status_activities = array("crawlStatus", "machineStatus");
+    var $status_activities = array("crawlStatus", "machineStatus",
+        "mediaUpdaterStatus");
     /**
      * This is the main entry point for handling requests to administer the
      * Yioop/SeekQuarry site
@@ -429,6 +431,9 @@ class AdminController extends Controller implements CrawlConstants
         $profile =  $this->model("profile")->getProfile(WORK_DIRECTORY);
         $data['MEDIA_MODE'] = isset($profile['MEDIA_MODE']) ?
             $profile['MEDIA_MODE']: "";
+        $present_on_name_server =
+            $this->model('machine')->checkMediaUpdaterStatus();
+        $data['MEDIA_UPDATER_ON_NS']= $present_on_name_server;
         if($data['MEDIA_MODE'] == "media_process" &&
             $data['MACHINES']['NAME_SERVER']["media_updater"] == 0) {
             // try to restart news server if dead
@@ -578,5 +583,18 @@ class AdminController extends Controller implements CrawlConstants
         $data['PAGING'] = $paging;
         return $search_array;
     }
+    /**
+     * Used to call the updateMediaUpdaterStatus function from machine_model
+     * This function flips the Present_on_name_server field of
+     * MEDIA_UPDATER_PROPERTIES.
+     * If Present_on_name_server field_value is already set to true then
+     * updates it to false and vice-versa
+     */
+     function mediaUpdaterStatus()
+    {
+        $this->model('machine')->updateMediaUpdaterStatus();
+        echo "Updating the status of Media updater !";
+        exit();
+    }
 }
 ?>
diff --git a/lib/upgrade_functions.php b/lib/upgrade_functions.php
index 6e4c347..928af1d 100644
--- a/lib/upgrade_functions.php
+++ b/lib/upgrade_functions.php
@@ -118,8 +118,8 @@ function upgradeDatabaseWorkDirectoryCheck()
         $result = @$model->db->execute($sql);
         if($result !== false) {
             $row = $model->db->fetchArray($result);
-            if((isset($row['ID']) && $row['ID'] >= YIOOP_VERSION) ||
-                (isset($row['id']) && $row['id'] >= YIOOP_VERSION)) {
+            if((isset($row['ID']) && $row['ID'] >= YIOOP_VERSION1) ||
+                (isset($row['id']) && $row['id'] >= YIOOP_VERSION1)) {
                 return false;
             } else {
                 return true;
@@ -1059,6 +1059,17 @@ function upgradeDatabaseVersion29(&$db)
     }
 }
 /**
+ * Upgrades a Version 30 version of the Yioop! database to a Version 28 version
+ * @param object $db datasource to use to upgrade
+ */
+function upgradeDatabaseVersion30(&$db)
+{
+    $db->execute("CREATE TABLE MEDIA_UPDATER_PROPERTIES(
+        NAME TEXT NOT NULL,VALUE TEXT NOT NULL)");
+    $db->execute("INSERT INTO MEDIA_UPDATER_PROPERTIES
+        VALUES ('Present_on_name_server','true')");
+}
+/**
  * Reads the Help articles from default db and returns the array of pages.
  */
 function getWikiHelpPages()
diff --git a/models/machine_model.php b/models/machine_model.php
index 5d85a41..fad0d93 100644
--- a/models/machine_model.php
+++ b/models/machine_model.php
@@ -358,6 +358,44 @@ class MachineModel extends Model
             }
         }
     }
+    /**
+     * Used to check if there is media updater running on the Name server
+     *
+     * @return string containing the value for field Present_on_name_server
+     * (variable which is set to true or false depending on whether
+     * media_updater is present on Name server or not)
+     */
+    function checkMediaUpdaterStatus()
+    {
+        $db = $this->db;
+        $sql = "SELECT VALUE FROM MEDIA_UPDATER_PROPERTIES WHERE".
+            "NAME='Present_on_name_server'";
+        $result = $db->execute($sql);
+        $row =  $db->fetchArray($result);
+        if(!$row) {
+            return false;
+        }
+        return $row['VALUE'];
+    }
+    /**
+     * Used to update the Present_on_name_server field of MEDIA_UPDATER_STATUS
+     * Depending on the current status , this function flips it.
+     * If Present_on_name_server field_value is already set to true then 
+     * updates it to false and vice-versa
+     */
+    function updateMediaUpdaterStatus()
+    {
+        $db = $this->db;
+        $current_value=$this->checkMediaUpdaterStatus();
+        if($current_value=='true'){
+            $edit_status = 'false';
+        }else{
+            $edit_status = 'true';
+        }
+        $sql = "UPDATE MEDIA_UPDATER_PROPERTIES SET VALUE=? WHERE". 
+            "NAME='Present_on_name_server'";
+        $db->execute($sql, array($edit_status));
+    }
 }
 
  ?>
diff --git a/models/profile_model.php b/models/profile_model.php
index 5de4499..efaec25 100755
--- a/models/profile_model.php
+++ b/models/profile_model.php
@@ -193,6 +193,9 @@ class ProfileModel extends Model
                 TYPE VARCHAR(".NAME_LEN."),
                 SOURCE_URL VARCHAR(".MAX_URL_LEN."), AUX_INFO VARCHAR(".
                 MAX_URL_LEN."), LANGUAGE VARCHAR(".NAME_LEN."))",
+            "MEDIA_UPDATER_PROPERTIES" => "CREATE TABLE 
+                MEDIA_UPDATER_PROPERTIES(NAME TEXT NOT NULL,
+                VALUE TEXT NOT NULL)",
             "MS_TYPE_INDEX" => "CREATE INDEX MS_TYPE_INDEX ON
                 MEDIA_SOURCE(TYPE)",
             "MIX_COMPONENTS" => "CREATE TABLE MIX_COMPONENTS (
diff --git a/scripts/basic.js b/scripts/basic.js
index d69e6e9..7223e25 100755
--- a/scripts/basic.js
+++ b/scripts/basic.js
@@ -176,7 +176,7 @@ file_list = new Array();
  * @param String file_id id of form file input that dropped objects
  *      will be associated with
  * @param String drop_kind what kind of element drop_id is. One of text (for
- *      textfield), textarea will add text to textarea, image 
+ *      textfield), textarea will add text to textarea, image
  *      (will replace image with what's dropped), or all.
  * @param Array types what file types can be upload
  * @param Boolean multiple whether multiple items dan be dropped in one go
@@ -404,3 +404,23 @@ function toggleDisplay(id, display_type)
     }
     obj.style.display = value;
 }
+/*
+ * Make an AJAX request for a url
+ *
+ * @param String url  web page to fetch using AJAX
+ */
+function getPageWithMessage(url)
+{
+    var request = makeRequest();
+    if(request) {
+        var self = this;
+        request.onreadystatechange = function()
+        {
+            if(self.request.readyState == 4) {
+                    doMessage(self.request.responseText);
+            }
+        }
+        request.open("GET", url, true);
+        request.send();
+    }
+}
diff --git a/views/machinestatus_view.php b/views/machinestatus_view.php
index 272c034..c08682c 100644
--- a/views/machinestatus_view.php
+++ b/views/machinestatus_view.php
@@ -1,4 +1,4 @@
-<?php
+3<?php
 /**
  * SeekQuarry/Yioop --
  * Open Source Pure PHP Search Engine, Crawler, and Indexer
@@ -63,12 +63,21 @@ class MachinestatusView extends View
                 "mediamode&amp;media_mode=media_off";
             $caution = ($data['MACHINES']['NAME_SERVER']["media_updater"] == 0);
         ?></h3>
+        <button type="button"
+        onclick="getPageWithMessage('?c=admin&a=mediaUpdaterStatus&<?php
+        echo CSRF_TOKEN."=".$data[CSRF_TOKEN];?>'); machineStatusUpdate();">
+        <?php e(tl('Multiple Media Updaters'));?>
+        </button>
         <form id="mediaModeForm" method="post">
         <input type="hidden" name="c" value="admin" />
         <input type="hidden" name="<?php e(CSRF_TOKEN); ?>" value="<?php
             e($data[CSRF_TOKEN]); ?>" />
         <input type="hidden" name="a" value="manageMachines" />
         <input type="hidden" name="arg" value="mediamode" />
+        <?php
+        if($data['MEDIA_UPDATER_ON_NS']=='true') {
+        ?>
+        <div id="hidden_media_updater" >
         <table class="machine-table"><tr>
         <th><?php e(tl('machinestatus_view_media_updater'));?></th>
         <td>[<a href="<?php e($log_url);?>"><?php
@@ -79,7 +88,10 @@ class MachinestatusView extends View
         </td>
         </tr></table>
         </form>
+        </div>
         </div><br />
+        <?php } ?>
+
         <?php
         if(count($data['MACHINES']) > 1) {
             $data['TABLE_TITLE'] = "";
@@ -151,7 +163,24 @@ class MachinestatusView extends View
                 </table>
             <?php } else {
                 e("<h3>".tl('machinestatus_view_no_queue_server')."</h3>");
-            }?><?php
+            }?>
+            <?php if($data['MEDIA_UPDATER_ON_NS']=='false') {
+               ?>
+                <div id="hidden_media_updater_independent" >
+                <table class="machine-table">
+                <tr><th><?php e(tl('machinestatus_view_media_updater'));?>
+                </th><td>[<a href="<?php e($log_url);?>"><?php
+                    e(tl('machinestatus_view_log'));?>]</a>
+                    </td><td><?php
+                    $this->helper("toggle")->render(
+                        isset($m['STATUSES']["media_updater"]) ,
+                        $on_media_updater, $off_media_updater);
+                ?></td>
+                </tr>
+                </table>
+                </div>
+            <?php } ?>
+            <?php
             if($m['NUM_FETCHERS'] == 0) {
                 e("<h3>".tl('machinestatus_view_no_fetchers')."</h3>");
             } else {
@@ -197,4 +226,4 @@ class MachinestatusView extends View
     }
     }
 }
-?>
+?>
\ No newline at end of file
-- 
1.9.4.msysgit.1


From b3f7959ae4176f9860cccd949b46b9c7f8d03e02 Mon Sep 17 00:00:00 2001
From: pomishra13 <pooja192009@gmail.com>
Date: Fri, 10 Apr 2015 15:12:58 -0700
Subject: [PATCH 2/2] Updated database added

---
 data/default.db | Bin 221184 -> 227328 bytes
 1 file changed, 0 insertions(+), 0 deletions(-)

diff --git a/data/default.db b/data/default.db
index 13524f9f38da264f5bc78354d19c0e25401a7605..1afae883750e020fbaec16e95907a28c6e2e59dd 100644
GIT binary patch
-- 
1.9.4.msysgit.1

