Add the ability for user to monitor changes to applications

This commit is contained in:
Tony Lambregts
2005-09-30 01:55:51 +00:00
committed by WineHQ
parent a66ae25f38
commit 2311d4d572
10 changed files with 266 additions and 30 deletions

View File

@@ -14,6 +14,7 @@ require(BASE."include/vote.php");
require(BASE."include/category.php"); require(BASE."include/category.php");
require(BASE."include/maintainer.php"); require(BASE."include/maintainer.php");
require(BASE."include/mail.php"); require(BASE."include/mail.php");
require(BASE."include/monitor.php");
$oApp = new Application($_REQUEST['appId']); $oApp = new Application($_REQUEST['appId']);
@@ -161,6 +162,24 @@ if ($_REQUEST['sub'])
redirect(apidb_fullurl("appview.php?versionId=".$_REQUEST['versionId'])); redirect(apidb_fullurl("appview.php?versionId=".$_REQUEST['versionId']));
exit; 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 @@ else if($_REQUEST['versionId'])
echo '<form method="post" name="message" action="maintainerdelete.php">'; echo '<form method="post" name="message" action="maintainerdelete.php">';
echo '<input type="submit" value="Remove yourself as a supermaintainer" class="button">'; 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="superMaintainer" value="1">';
echo "<input type=hidden name=\"appId\" value=\"".$oApp->iAppId."\">";
echo "<input type=hidden name=\"versionId\" value=\"".$oVersion->iVersionId."\">";
echo "</form>";
} else } else
{ {
/* are we already a maintainer? */ /* are we already a maintainer? */
@@ -405,16 +427,28 @@ else if($_REQUEST['versionId'])
echo '<form method="post" name="message" action="maintainerdelete.php">'; echo '<form method="post" name="message" action="maintainerdelete.php">';
echo '<input type="submit" value="Remove yourself as a maintainer" class=button>'; 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="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 */ } else /* nope */
{ {
echo '<form method="post" name="message" action="maintainersubmit.php">'; 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="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=\"appId\" value=\"".$oApp->iAppId."\">";
echo "<input type=hidden name=\"versionId\" value=\"".$oVersion->iVersionId."\">"; echo "<input type=hidden name=\"versionId\" value=\"".$oVersion->iVersionId."\">";
echo "</form>"; 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>";
}
}
}
} else } else
{ {
echo '<form method="post" name="message" action="account.php">'; echo '<form method="post" name="message" action="account.php">';
@@ -451,7 +485,19 @@ else if($_REQUEST['versionId'])
echo '</form>'; echo '</form>';
echo "</td></tr>"; 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"; echo "</table><td class=color2 valign=top width='100%'>\n";
// description // description

View File

@@ -136,7 +136,7 @@ class Application {
{ {
$this->iAppId = mysql_insert_id(); $this->iAppId = mysql_insert_id();
$this->application($this->iAppId); $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; return true;
} }
else else
@@ -210,7 +210,7 @@ class Application {
$this->iCatId = $iCatId; $this->iCatId = $iCatId;
} }
if($sWhatChanged) if($sWhatChanged)
$this->mailSupermaintainers("edit",$sWhatChanged); $this->SendNotificationMail("edit",$sWhatChanged);
return true; return true;
} }
@@ -252,7 +252,7 @@ class Application {
} }
if(!$bSilent) if(!$bSilent)
$this->mailSupermaintainers("delete"); $this->SendNotificationMail("delete");
} }
@@ -272,7 +272,7 @@ class Application {
$this->sQueued = 'false'; $this->sQueued = 'false';
// we send an e-mail to intersted people // we send an e-mail to intersted people
$this->mailSubmitter(); $this->mailSubmitter();
$this->mailSupermaintainers(); $this->SendNotificationMail();
// the application has been unqueued // the application has been unqueued
addmsg("The application has been unqueued.", "green"); addmsg("The application has been unqueued.", "green");
@@ -291,7 +291,7 @@ class Application {
$this->sQueued = 'rejected'; $this->sQueued = 'rejected';
// we send an e-mail to intersted people // we send an e-mail to intersted people
$this->mailSubmitter("reject"); $this->mailSubmitter("reject");
$this->mailSupermaintainers("reject"); $this->SendNotificationMail("reject");
// the application has been rejectedd // the application has been rejectedd
addmsg("The application has been rejected.", "green"); addmsg("The application has been rejected.", "green");
@@ -308,7 +308,7 @@ class Application {
{ {
$this->sQueued = 'true'; $this->sQueued = 'true';
// we send an e-mail to intersted people // we send an e-mail to intersted people
$this->mailSupermaintainers(); $this->SendNotificationMail();
// the application has been re-queued // the application has been re-queued
addmsg("The application has been re-queued.", "green"); addmsg("The application has been re-queued.", "green");
@@ -355,7 +355,7 @@ class Application {
} }
function mailSupermaintainers($sAction="add",$sMsg=null) function SendNotificationMail($sAction="add",$sMsg=null)
{ {
switch($sAction) switch($sAction)
{ {

View File

@@ -136,7 +136,7 @@ class Bug {
} }
/*End of Hack */ /*End of Hack */
$this->mailMaintainers(); $this->SendNotificationMail();
return true; return true;
}else }else
{ {
@@ -156,7 +156,7 @@ class Bug {
if($hResult = query_appdb($sQuery)) if($hResult = query_appdb($sQuery))
{ {
if(!$bSilent) if(!$bSilent)
$this->mailMaintainers(true); $this->SendNotificationMail(true);
} }
if($this->iSubmitterId) if($this->iSubmitterId)
{ {
@@ -181,7 +181,7 @@ class Bug {
$this->bQueued = false; $this->bQueued = false;
// we send an e-mail to intersted people // we send an e-mail to intersted people
$this->mailSubmitter(); $this->mailSubmitter();
$this->mailMaintainers(); $this->SendNotificationMail();
// the Bug has been unqueued // the Bug has been unqueued
addmsg("The Bug has been unqueued.", "green"); addmsg("The Bug has been unqueued.", "green");
} }
@@ -210,7 +210,7 @@ class Bug {
} }
function mailMaintainers($bDeleted=false) function SendNotificationMail($bDeleted=false)
{ {
if(!$bDeleted) if(!$bDeleted)
{ {

134
include/monitor.php Normal file
View File

@@ -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);
}
}
?>

View File

@@ -55,7 +55,7 @@ class Note {
{ {
$this->note(mysql_insert_id()); $this->note(mysql_insert_id());
$sWhatChanged = "Description is:\n".$sDescription.".\n\n"; $sWhatChanged = "Description is:\n".$sDescription.".\n\n";
$this->mailMaintainers("add", $sWhatChanged); $this->SendNotificationMail("add", $sWhatChanged);
return true; return true;
} }
else else
@@ -101,7 +101,7 @@ class Note {
$this->iAppId = $oVersionAfter->iAppId; $this->iAppId = $oVersionAfter->iAppId;
} }
if($sWhatChanged) if($sWhatChanged)
$this->mailMaintainers("edit",$sWhatChanged); $this->SendNotificationMail("edit",$sWhatChanged);
return true; return true;
} }
@@ -114,11 +114,11 @@ class Note {
{ {
$hResult = query_appdb("DELETE FROM appNotes WHERE noteId = '".$this->iNoteId."'"); $hResult = query_appdb("DELETE FROM appNotes WHERE noteId = '".$this->iNoteId."'");
if(!$bSilent) if(!$bSilent)
$this->mailMaintainers("delete"); $this->SendNotificationMail("delete");
} }
function mailMaintainers($sAction="add",$sMsg=null) function SendNotificationMail($sAction="add",$sMsg=null)
{ {
switch($sAction) switch($sAction)
{ {

View File

@@ -70,7 +70,7 @@ class Url {
{ {
$this->iUrlId = mysql_insert_id(); $this->iUrlId = mysql_insert_id();
$this->url($this->iUrlId,$this->bQueued); $this->url($this->iUrlId,$this->bQueued);
$this->mailMaintainers(); $this->SendNotificationMail();
return true; return true;
} }
else else
@@ -91,7 +91,7 @@ class Url {
if($hResult = query_appdb($sQuery)) if($hResult = query_appdb($sQuery))
{ {
if(!$bSilent) if(!$bSilent)
$this->mailMaintainers(true); $this->SendNotificationMail(true);
} }
if($this->iSubmitterId) if($this->iSubmitterId)
{ {
@@ -114,7 +114,7 @@ class Url {
{ {
// we send an e-mail to intersted people // we send an e-mail to intersted people
$this->mailSubmitter(); $this->mailSubmitter();
$this->mailMaintainers(); $this->SendNotificationMail();
// the url has been unqueued // the url has been unqueued
addmsg("The url has been unqueued.", "green"); addmsg("The url has been unqueued.", "green");
} }
@@ -170,7 +170,7 @@ class Url {
$this->iAppId = $iAppId; $this->iAppId = $iAppId;
} }
if($sWhatChanged) if($sWhatChanged)
$this->mailMaintainers("edit",$sWhatChanged); $this->SendNotificationMail("edit",$sWhatChanged);
return true; return true;
} }
@@ -197,7 +197,7 @@ class Url {
} }
function mailMaintainers($bDeleted=false) function SendNotificationMail($bDeleted=false)
{ {
if(!$bDeleted) if(!$bDeleted)
{ {

View File

@@ -794,6 +794,41 @@ function get_notify_email_address_list($iAppId = null, $iVersionId = null)
} }
} }
/*
* 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. * Retrieve administrators.
*/ */

View File

@@ -159,7 +159,7 @@ class Version {
{ {
$this->iVersionId = mysql_insert_id(); $this->iVersionId = mysql_insert_id();
$this->version($this->iVersionId); $this->version($this->iVersionId);
$this->mailMaintainers(); $this->SendNotificationMail();
return true; return true;
} }
else else
@@ -238,7 +238,7 @@ class Version {
$this->iAppId = $iAppId; $this->iAppId = $iAppId;
} }
if($sWhatChanged) if($sWhatChanged)
$this->mailMaintainers("edit",$sWhatChanged); $this->SendNotificationMail("edit",$sWhatChanged);
return true; return true;
} }
@@ -301,7 +301,7 @@ class Version {
} }
if(!$bSilent) if(!$bSilent)
$this->mailMaintainers("delete"); $this->SendNotificationMail("delete");
$this->mailSubmitter("delete"); $this->mailSubmitter("delete");
} }
@@ -328,7 +328,7 @@ class Version {
$this->sQueued = 'false'; $this->sQueued = 'false';
// we send an e-mail to intersted people // we send an e-mail to intersted people
$this->mailSubmitter("unQueue"); $this->mailSubmitter("unQueue");
$this->mailMaintainers(); $this->SendNotificationMail();
// the version has been unqueued // the version has been unqueued
addmsg("The version has been unqueued.", "green"); addmsg("The version has been unqueued.", "green");
@@ -355,7 +355,7 @@ class Version {
if(!$bSilent) if(!$bSilent)
{ {
$this->mailSubmitter("reject"); $this->mailSubmitter("reject");
$this->mailMaintainers("reject"); $this->SendNotificationMail("reject");
} }
// the version has been unqueued // the version has been unqueued
addmsg("The version has been rejected.", "green"); addmsg("The version has been rejected.", "green");
@@ -377,7 +377,7 @@ class Version {
{ {
$this->sQueued = 'true'; $this->sQueued = 'true';
// we send an e-mail to intersted people // we send an e-mail to intersted people
$this->mailMaintainers(); $this->SendNotificationMail();
// the version has been unqueued // the version has been unqueued
addmsg("The version has been re-submitted", "green"); addmsg("The version has been re-submitted", "green");
@@ -425,7 +425,7 @@ class Version {
} }
function mailMaintainers($sAction="add",$sMsg=null) function SendNotificationMail($sAction="add",$sMsg=null)
{ {
$oApp = new Application($this->iAppId); $oApp = new Application($this->iAppId);
switch($sAction) switch($sAction)

View File

@@ -27,3 +27,6 @@ mysql -p -u root < maintainers.sql
echo Adding bug links echo Adding bug links
mysql -p -u root < buglinks.sql mysql -p -u root < buglinks.sql
echo Adding monitors
mysql -p -u root < monitors.sql

18
tables/monitors.sql Normal file
View File

@@ -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)
);