[Appdb] Add the ability for user to monitor changes to applications

Tony Lambregts tony.lambregts at gmail.com
Wed Sep 28 23:21:14 CDT 2005


This patch adds a new table appMonitors. Please don't apply this without 
creating it!!!

use apidb;

create table appMonitors (
         monitorId       int not null auto_increment,
	appId           int not null,
	versionId       int not null,
	submitTime	timestamp(14) NOT NULL,
	userId	        int(11) NOT NULL default '0',
         key(monitorId),
	index(appid),
	index(versionId),
	index(userId)
);

Change Log: Add the ability for user to monitor changes to applications.

Files changed: appview.php include/application.php include/bugs.php 
include/note.php include/url.php  include/user.php include/version.php tables/php

Files added: tables/monitors.sql include/monitor.php
-------------- next part --------------
Index: appview.php
===================================================================
RCS file: /home/wine/appdb/appview.php,v
retrieving revision 1.72
diff -u -r1.72 appview.php
--- appview.php	29 Sep 2005 00:20:03 -0000	1.72
+++ appview.php	29 Sep 2005 03:58:33 -0000
@@ -14,6 +14,7 @@
 require(BASE."include/category.php");
 require(BASE."include/maintainer.php");
 require(BASE."include/mail.php");
+require(BASE."include/monitor.php");
 
 
 $oApp = new Application($_REQUEST['appId']);
@@ -161,6 +162,24 @@
         redirect(apidb_fullurl("appview.php?versionId=".$_REQUEST['versionId']));
         exit;
     }
+    if($_REQUEST['sub'] == 'StartMonitoring')
+    {
+        $oMonitor = new Monitor();
+        $oMonitor->create($_SESSION['current']->iUserId,$_REQUEST['appId'],$_REQUEST['versionId']);
+        redirect(apidb_fullurl("appview.php?versionId=".$_REQUEST['versionId']));
+        exit;
+    }
+    if($_REQUEST['sub'] == 'StopMonitoring')
+    {
+        $oMonitor = new Monitor();
+        $oMonitor->find($_SESSION['current']->iUserId,$_REQUEST['appId'],$_REQUEST['versionId']);
+        if($oMonitor->iMonitorId)
+        {
+            $oMonitor->delete();
+        }
+        redirect(apidb_fullurl("appview.php?versionId=".$_REQUEST['versionId']));
+        exit;
+    }
 
 }
 
@@ -397,6 +416,9 @@
             echo '<form method="post" name="message" action="maintainerdelete.php">';
             echo '<input type="submit" value="Remove yourself as a supermaintainer" class="button">';
             echo '<input type="hidden" name="superMaintainer" value="1">';
+            echo "<input type=hidden name=\"appId\" value=\"".$oApp->iAppId."\">";
+            echo "<input type=hidden name=\"versionId\" value=\"".$oVersion->iVersionId."\">";
+            echo "</form>";
         } else
         {
             /* are we already a maintainer? */
@@ -405,16 +427,28 @@
                 echo '<form method="post" name="message" action="maintainerdelete.php">';
                 echo '<input type="submit" value="Remove yourself as a maintainer" class=button>';
                 echo '<input type="hidden" name="superMaintainer" value="0">';
+                echo "<input type=hidden name=\"appId\" value=\"".$oApp->iAppId."\">";
+                echo "<input type=hidden name=\"versionId\" value=\"".$oVersion->iVersionId."\">";
+                echo "</form>";
             } else /* nope */
             {
                 echo '<form method="post" name="message" action="maintainersubmit.php">';
                 echo '<input type="submit" value="Be a maintainer for this app" class="button" title="Click here to know more about maintainers.">';
+                echo "<input type=hidden name=\"appId\" value=\"".$oApp->iAppId."\">";
+                echo "<input type=hidden name=\"versionId\" value=\"".$oVersion->iVersionId."\">";
+                echo "</form>";
+                $oMonitor = new Monitor();
+                $oMonitor->find($_SESSION['current']->iUserId,$oApp->iAppId,$oVersion->iVersionId);
+                if(!$oMonitor->iMonitorId)
+                {
+                    echo '<form method=post name=message action=appview.php?versionId='.$oVersion->iVersionId.'&appId='.$oApp->iAppId.'>';
+                    echo '<input type=hidden name="sub" value="StartMonitoring" />';
+                    echo '<input type=submit value="Monitor Version" class="button" />';
+                    echo "</form>";
+                }
             }
         }
 
-        echo "<input type=hidden name=\"appId\" value=\"".$oApp->iAppId."\">";
-        echo "<input type=hidden name=\"versionId\" value=\"".$oVersion->iVersionId."\">";
-        echo "</form>";
     } else
     {
         echo '<form method="post" name="message" action="account.php">';
@@ -451,7 +485,19 @@
         echo '</form>';
         echo "</td></tr>";
     }
+    $oMonitor = new Monitor();
+    $oMonitor->find($_SESSION['current']->iUserId,$oApp->iAppId,$oVersion->iVersionId);
+    if($oMonitor->iMonitorId)
+    {
 
+        echo '<tr><td colspan="2" align="center">';
+        echo '</form>';
+        echo '<form method=post name=message action=appview.php?versionId='.$oVersion->iVersionId.'>';
+        echo '<input type=hidden name="sub" value="StopMonitoring" />';
+        echo '<input type=submit value="Stop Monitoring Version" class="button" />';
+        echo '</form>';
+        echo "</td></tr>";
+    } 
     echo "</table><td class=color2 valign=top width='100%'>\n";
 
     // description
Index: include/application.php
===================================================================
RCS file: /home/wine/appdb/include/application.php,v
retrieving revision 1.31
diff -u -r1.31 application.php
--- include/application.php	21 Sep 2005 01:26:10 -0000	1.31
+++ include/application.php	29 Sep 2005 03:58:33 -0000
@@ -136,7 +136,7 @@
         {
             $this->iAppId = mysql_insert_id();
             $this->application($this->iAppId);
-            $this->mailSupermaintainers();  // Only administrators will be mailed as no supermaintainers exist for this app.
+            $this->SendNotificationMail();  // Only administrators will be mailed as no supermaintainers exist for this app.
             return true;
         }
         else
@@ -210,7 +210,7 @@
             $this->iCatId = $iCatId;
         }
         if($sWhatChanged)
-            $this->mailSupermaintainers("edit",$sWhatChanged);
+            $this->SendNotificationMail("edit",$sWhatChanged);
         return true;
     }
 
@@ -252,7 +252,7 @@
         }
 
         if(!$bSilent)
-            $this->mailSupermaintainers("delete");
+            $this->SendNotificationMail("delete");
     }
 
 
@@ -272,7 +272,7 @@
             $this->sQueued = 'false';
             // we send an e-mail to intersted people
             $this->mailSubmitter();
-            $this->mailSupermaintainers();
+            $this->SendNotificationMail();
 
             // the application has been unqueued
             addmsg("The application has been unqueued.", "green");
@@ -291,7 +291,7 @@
             $this->sQueued = 'rejected';
             // we send an e-mail to intersted people
             $this->mailSubmitter("reject");
-            $this->mailSupermaintainers("reject");
+            $this->SendNotificationMail("reject");
 
             // the application has been rejectedd
             addmsg("The application has been rejected.", "green");
@@ -308,7 +308,7 @@
         {
             $this->sQueued = 'true';
             // we send an e-mail to intersted people
-            $this->mailSupermaintainers();
+            $this->SendNotificationMail();
 
             // the application has been re-queued
             addmsg("The application has been re-queued.", "green");
@@ -355,7 +355,7 @@
     }
 
  
-    function mailSupermaintainers($sAction="add",$sMsg=null)
+    function SendNotificationMail($sAction="add",$sMsg=null)
     {
         switch($sAction)
         {
Index: include/bugs.php
===================================================================
RCS file: /home/wine/appdb/include/bugs.php,v
retrieving revision 1.4
diff -u -r1.4 bugs.php
--- include/bugs.php	13 Aug 2005 01:54:15 -0000	1.4
+++ include/bugs.php	29 Sep 2005 03:58:34 -0000
@@ -136,7 +136,7 @@
             }
             /*End of Hack */
 
-            $this->mailMaintainers();
+            $this->SendNotificationMail();
             return true;
         }else
         {
@@ -156,7 +156,7 @@
         if($hResult = query_appdb($sQuery))
         {
             if(!$bSilent)
-                $this->mailMaintainers(true);
+                $this->SendNotificationMail(true);
         }
         if($this->iSubmitterId)
         {
@@ -181,7 +181,7 @@
             $this->bQueued = false;
             // we send an e-mail to intersted people
             $this->mailSubmitter();
-            $this->mailMaintainers();
+            $this->SendNotificationMail();
             // the Bug has been unqueued
             addmsg("The Bug has been unqueued.", "green");
         }
@@ -210,7 +210,7 @@
     }
 
  
-    function mailMaintainers($bDeleted=false)
+    function SendNotificationMail($bDeleted=false)
     {
         if(!$bDeleted)
         {
Index: include/note.php
===================================================================
RCS file: /home/wine/appdb/include/note.php,v
retrieving revision 1.5
diff -u -r1.5 note.php
--- include/note.php	27 May 2005 23:53:26 -0000	1.5
+++ include/note.php	29 Sep 2005 03:58:34 -0000
@@ -55,7 +55,7 @@
         {
             $this->note(mysql_insert_id());
             $sWhatChanged = "Description is:\n".$sDescription.".\n\n";
-            $this->mailMaintainers("add", $sWhatChanged);
+            $this->SendNotificationMail("add", $sWhatChanged);
             return true;
         }
         else
@@ -101,7 +101,7 @@
             $this->iAppId = $oVersionAfter->iAppId;
         }
         if($sWhatChanged)
-            $this->mailMaintainers("edit",$sWhatChanged);       
+            $this->SendNotificationMail("edit",$sWhatChanged);       
         return true;
     }
 
@@ -114,11 +114,11 @@
     {
         $hResult = query_appdb("DELETE FROM appNotes WHERE noteId = '".$this->iNoteId."'");
         if(!$bSilent)
-            $this->mailMaintainers("delete");
+            $this->SendNotificationMail("delete");
     }
 
 
-    function mailMaintainers($sAction="add",$sMsg=null)
+    function SendNotificationMail($sAction="add",$sMsg=null)
     {
         switch($sAction)
         {
Index: include/url.php
===================================================================
RCS file: /home/wine/appdb/include/url.php,v
retrieving revision 1.1
diff -u -r1.1 url.php
--- include/url.php	11 Feb 2005 01:33:25 -0000	1.1
+++ include/url.php	29 Sep 2005 03:58:34 -0000
@@ -70,7 +70,7 @@
         {
             $this->iUrlId = mysql_insert_id();
             $this->url($this->iUrlId,$this->bQueued);
-            $this->mailMaintainers();
+            $this->SendNotificationMail();
             return true;
         }
         else
@@ -91,7 +91,7 @@
         if($hResult = query_appdb($sQuery))
         {
             if(!$bSilent)
-                $this->mailMaintainers(true);
+                $this->SendNotificationMail(true);
         }
         if($this->iSubmitterId)
         {
@@ -114,7 +114,7 @@
         {
             // we send an e-mail to intersted people
             $this->mailSubmitter();
-            $this->mailMaintainers();
+            $this->SendNotificationMail();
             // the url has been unqueued
             addmsg("The url has been unqueued.", "green");
         }
@@ -170,7 +170,7 @@
             $this->iAppId = $iAppId;
         }
         if($sWhatChanged)
-            $this->mailMaintainers("edit",$sWhatChanged);       
+            $this->SendNotificationMail("edit",$sWhatChanged);       
         return true;
     }
 
@@ -197,7 +197,7 @@
     }
 
  
-    function mailMaintainers($bDeleted=false)
+    function SendNotificationMail($bDeleted=false)
     {
         if(!$bDeleted)
         {
Index: include/user.php
===================================================================
RCS file: /home/wine/appdb/include/user.php,v
retrieving revision 1.52
diff -u -r1.52 user.php
--- include/user.php	28 Sep 2005 00:32:48 -0000	1.52
+++ include/user.php	29 Sep 2005 03:58:34 -0000
@@ -766,6 +766,41 @@
     }
 
     /*
+     * Retrieve version Monitors.
+     */
+    /*
+     * If versionId was supplied we fetch superMonitors of application and Monitors of version.
+     */
+    if($iVersionId)
+    {
+        $sQuery = "SELECT appMonitors.userId 
+                   FROM appMonitors, appVersion
+                   WHERE appVersion.appId = appMonitors.appId 
+                   AND appVersion.versionId = '".$iVersionId."'";
+    } 
+    /*
+     * If versionId was not supplied we fetch superMonitors of application and Monitors of all versions.
+     */
+    elseif($iAppId)
+    {
+        $sQuery = "SELECT userId 
+                   FROM appMonitors
+                   WHERE appId = '".$iAppId."'";
+    }
+    if($sQuery)
+    {
+        $hResult = query_appdb($sQuery);
+        if(mysql_num_rows($hResult) > 0)
+        {
+            while($oRow = mysql_fetch_object($hResult))
+            {
+                $aUserId[$c] = array($oRow->userId);
+                $c++;
+            }
+        }
+    }
+
+    /*
      * Retrieve administrators.
      */
     $hResult = query_appdb("SELECT * FROM user_privs WHERE priv  = 'admin'");
Index: include/version.php
===================================================================
RCS file: /home/wine/appdb/include/version.php,v
retrieving revision 1.32
diff -u -r1.32 version.php
--- include/version.php	21 Sep 2005 01:26:10 -0000	1.32
+++ include/version.php	29 Sep 2005 03:58:35 -0000
@@ -159,7 +159,7 @@
         {
             $this->iVersionId = mysql_insert_id();
             $this->version($this->iVersionId);
-            $this->mailMaintainers();
+            $this->SendNotificationMail();
             return true;
         }
         else
@@ -238,7 +238,7 @@
             $this->iAppId = $iAppId;
         }
         if($sWhatChanged)
-            $this->mailMaintainers("edit",$sWhatChanged);
+            $this->SendNotificationMail("edit",$sWhatChanged);
         return true;
     }
 
@@ -301,7 +301,7 @@
         }
 
         if(!$bSilent)
-            $this->mailMaintainers("delete");
+            $this->SendNotificationMail("delete");
 
         $this->mailSubmitter("delete");
     }
@@ -328,7 +328,7 @@
             $this->sQueued = 'false';
             // we send an e-mail to intersted people
             $this->mailSubmitter("unQueue");
-            $this->mailMaintainers();
+            $this->SendNotificationMail();
 
             // the version has been unqueued
             addmsg("The version has been unqueued.", "green");
@@ -355,7 +355,7 @@
             if(!$bSilent)
             {
                 $this->mailSubmitter("reject");
-                $this->mailMaintainers("reject");
+                $this->SendNotificationMail("reject");
             }
             // the version has been unqueued
             addmsg("The version has been rejected.", "green");
@@ -377,7 +377,7 @@
         {
             $this->sQueued = 'true';
             // we send an e-mail to intersted people
-            $this->mailMaintainers();
+            $this->SendNotificationMail();
 
             // the version has been unqueued
             addmsg("The version has been re-submitted", "green");
@@ -425,7 +425,7 @@
     }
 
  
-    function mailMaintainers($sAction="add",$sMsg=null)
+    function SendNotificationMail($sAction="add",$sMsg=null)
     {
         $oApp = new Application($this->iAppId);
         switch($sAction)
Index: tables/create_tables
===================================================================
RCS file: /home/wine/appdb/tables/create_tables,v
retrieving revision 1.6
diff -u -r1.6 create_tables
--- tables/create_tables	13 Jul 2005 01:12:54 -0000	1.6
+++ tables/create_tables	29 Sep 2005 03:58:35 -0000
@@ -27,3 +27,6 @@
 echo Adding bug links
 mysql -p -u root < buglinks.sql
 
+echo Adding monitors
+mysql -p -u root < monitors.sql
+
--- /dev/null	2005-07-16 05:32:20.814944808 -0600
+++ tables/monitors.sql	2005-09-28 21:57:42.000000000 -0600
@@ -0,0 +1,18 @@
+use apidb;
+
+drop table if exists appMonitors;
+
+/*
+ * Let users monitor changes to applications
+ */
+create table appMonitors (
+        monitorId       int not null auto_increment,
+	appId           int not null,
+	versionId       int not null,
+	submitTime	timestamp(14) NOT NULL,
+	userId	        int(11) NOT NULL default '0',
+        key(monitorId),
+	index(appid),
+	index(versionId),
+	index(userId)
+);
--- /dev/null	2005-07-16 05:32:20.814944808 -0600
+++ include/monitor.php	2005-09-28 21:25:53.000000000 -0600
@@ -0,0 +1,134 @@
+<?php
+/***************************************/
+/* Monitor class and related functions */
+/***************************************/
+
+
+/**
+ * Monitor class for handling Monitors
+ */
+class Monitor {
+    var $iMonitorId;
+    var $iAppId;
+    var $iVersionId;
+    var $iUserId;
+
+    /**
+     * Constructor.
+     * If $iMonitorId is provided, fetches Monitor.
+     */
+    function Monitor($iMonitorId="")
+    {
+        if($iMonitorId)
+        {
+            $sQuery = "SELECT *
+                       FROM appMonitors
+                       WHERE MonitorId = '".$iMonitorId."'";
+            $hResult = query_appdb($sQuery);
+            $oRow = mysql_fetch_object($hResult);
+            $this->iMonitorId = $oRow->monitorId;
+            $this->iAppId = $oRow->appId;
+            $this->iVersionId = $oRow->versionId;
+            $this->iUserId = $oRow->userId;
+
+        }
+    }
+
+    function find($iUserId, $iAppId=0, $iVersionId=0)
+    {
+        if($iUserId)
+        {
+            if($iVersionId)
+            {
+                $sQuery = "SELECT *
+                          FROM appMonitors
+                          WHERE userId = '".$iUserId."'
+                          AND versionId = '".$iVersionId."'";
+                $hResult = query_appdb($sQuery);
+                $oRow = mysql_fetch_object($hResult);
+                $this->iMonitorId = $oRow->monitorId;
+                $this->iAppId = $oRow->appId;
+                $this->iVersionId = $oRow->versionId;
+                $this->iUserId = $oRow->userId;
+            }
+        }
+    }
+
+    /*
+     * Creates a new Monitor.
+     * Informs interested people about the creation.
+     * Returns true on success, false on failure
+     */
+    function create($iUserId, $iAppId=0, $iVersionId=0)
+    {
+        $aInsert = compile_insert_string(array( 'versionId' => $iVersionId,
+                                                'appId' => $iAppId,
+                                                'userId' => $iUserId ));
+
+        $sFields = "({$aInsert['FIELDS']})";
+        $sValues = "({$aInsert['VALUES']})";
+        if(query_appdb("INSERT INTO appMonitors $sFields VALUES $sValues", "Error while creating a new Monitor."))
+        {
+            $this->Monitor(mysql_insert_id());
+            $sWhatChanged = "New monitor\n\n";
+            $this->SendNotificationMail("add", $sWhatChanged);
+            return true;
+        }
+        else
+            return false;
+    }
+
+
+   /**
+     * Removes the current Monitor from the database.
+     * Informs interested people about the deletion.
+     */
+    function delete($bSilent=false)
+    {
+        $hResult = query_appdb("DELETE FROM appMonitors WHERE MonitorId = '".$this->iMonitorId."'");
+        if(!$bSilent)
+            $this->SendNotificationMail("delete");
+    }
+
+
+    function SendNotificationMail($sAction="add",$sMsg=null)
+    {
+        switch($sAction)
+        {
+            case "add":
+                if (isset($this->iVersionId))
+                {
+                    $oVersion = new Version($this->iVersionId);
+                    $sSubject = "Monitor for ".lookup_app_name($oVersion->iAppId)." ".lookup_version_name($this->iVersionId);
+                    $sSubject .= " added: ".$_SESSION['current']->sRealname;
+                    $sMsg .= APPDB_ROOT."appview.php?versionId=".$this->iVersionId."\n";
+                    addmsg("You will now recieve an email whenever changes are made to this Application version.", "green");
+                } else
+                {
+                    $sSubject = "Monitor for ".lookup_app_name($this->iAppId)." added: ".$_SESSION['current']->sRealname;
+                    $sMsg .= APPDB_ROOT."appview.php?appId=".$this->iAppid."\n";
+                    addmsg("You will now recieve an email whenever changes are made to this Application.", "green");
+                } 
+            break;
+            case "delete":
+                if (isset($this->iVersionId))
+                {
+                    $oVersion = new Version($this->iVersionId);
+                    $sSubject = "Monitor for ".lookup_app_name($oVersion->iAppId)." ".lookup_version_name($this->iVersionId);
+                    $sSubject .= " removed: ".$_SESSION['current']->sRealname;
+                    $sMsg .= APPDB_ROOT."appview.php?versionId=".$this->iVersionId."\n";
+                    addmsg("You will no longer recieve an email whenever changes are made to this Application version.", "green");
+                } else
+                {
+                    $sSubject = "Monitor for ".lookup_app_name($this->iAppId)." removed: ".$_SESSION['current']->sRealname;
+                    $sMsg .= APPDB_ROOT."appview.php?appId=".$this->iAppid."\n";
+                    addmsg("You will no longer recieve an email whenever changes are made to this Application.", "green");
+                } 
+            break;
+        }
+        $sEmail = get_notify_email_address_list(null, $this->iVersionId);
+        if($sEmail)
+            mail_appdb($sEmail, $sSubject ,$sMsg);
+    } 
+}
+?>


More information about the wine-patches mailing list