Split maintainer::notifyMaintainerOfQueuedData() into two parts.
maintainer::fetchNotificationUpdate() that retrieves much of the email to the maintainer and the target notification level, and maintainer::processNotificationUpdate() that acts on the target notification level and completes and optionally sends the email to the maintainer. Add admin/maintainerNotification.php to aid in debugging the notification system.
This commit is contained in:
61
admin/maintainerNotification.php
Normal file
61
admin/maintainerNotification.php
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require("path.php");
|
||||||
|
require(BASE."include/incl.php");
|
||||||
|
|
||||||
|
|
||||||
|
// module used to debug the maintainer notification system
|
||||||
|
// TODO: integrate this properly in with the objectManager system
|
||||||
|
// and with the normal admin menus on the site
|
||||||
|
|
||||||
|
apidb_header("Maintiner notification info");
|
||||||
|
|
||||||
|
// display all currently notified maintainers
|
||||||
|
$hResult = maintainer::objectGetEntries(false, false);
|
||||||
|
echo "Maintainers with a non-zero notification level<br />\n";
|
||||||
|
|
||||||
|
$bFoundNonZero = false;
|
||||||
|
while($oRow = mysql_fetch_object($hResult))
|
||||||
|
{
|
||||||
|
$oMaintainer = new maintainer(null, $oRow);
|
||||||
|
|
||||||
|
if($oMaintainer->iNotificationLevel != 0)
|
||||||
|
{
|
||||||
|
$bFoundNonZero = true;
|
||||||
|
echo "iMaintainerId: $oMaintainer->iMaintainerId<br />";
|
||||||
|
echo "iNotificationLevel: $oMaintainer->iNotificationLevel<br />";
|
||||||
|
echo "<br />\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$bFoundNonZero)
|
||||||
|
{
|
||||||
|
echo "No maintainers have a non-zero notification level<br />\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
echo "<br />\n";
|
||||||
|
echo "<br />\n";
|
||||||
|
|
||||||
|
|
||||||
|
// retrieve all of the maintainers
|
||||||
|
echo "Maintainers with notification iTargetLevel != 0<br />\n";
|
||||||
|
$hResult = maintainer::objectGetEntries(false, false);
|
||||||
|
while($oRow = mysql_fetch_object($hResult))
|
||||||
|
{
|
||||||
|
$oMaintainer = new maintainer(null, $oRow);
|
||||||
|
|
||||||
|
$oNotificationUpdate = $oMaintainer->fetchNotificationUpdate();
|
||||||
|
|
||||||
|
if($oNotificationUpdate->iTargetLevel != 0)
|
||||||
|
{
|
||||||
|
echo "iMaintainerId: $oMaintainer->iMaintainerId<br />\n";
|
||||||
|
echo "iNotificationLevel: $oMaintainer->iNotificationLevel<br />\n";
|
||||||
|
echo "iTargetLevel: $oNotificationUpdate->iTargetLevel<br />\n";
|
||||||
|
echo "<br />\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
apidb_footer();
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -136,6 +136,26 @@ class queuedEntries
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// contains the results of a notification update so other logic
|
||||||
|
// can act on these results
|
||||||
|
class notificationUpdate
|
||||||
|
{
|
||||||
|
var $sEmail;
|
||||||
|
var $sSubject;
|
||||||
|
var $sMsg; // contents of the email we will send to the maintainer
|
||||||
|
var $iTargetLevel; // the target notification level based upon the
|
||||||
|
// maintiners queued entries
|
||||||
|
|
||||||
|
function notificationUpdate($sEmail, $sSubject, $sMsg, $iTargetLevel)
|
||||||
|
{
|
||||||
|
$this->sEmail = $sEmail;
|
||||||
|
$this->sSubject = $sSubject;
|
||||||
|
$this->sMsg = $sMsg;
|
||||||
|
$this->iTargetLevel = $iTargetLevel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class maintainer
|
class maintainer
|
||||||
{
|
{
|
||||||
var $iMaintainerId;
|
var $iMaintainerId;
|
||||||
@@ -816,11 +836,7 @@ class maintainer
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// level 0 is from 0 to iNotificationIntervalDays
|
function fetchNotificationUpdate()
|
||||||
// level 1 is from (iNotificationIntervalDays + 1) to (iNotificationIntervalDays * 2)
|
|
||||||
// level 2 is from (iNotificationIntervalDays * 2 + 1) to (iNotificationIntervalDays * 3)
|
|
||||||
// level 3 is beyond (iNotificationIntervalDays * 3)
|
|
||||||
function notifyMaintainerOfQueuedData()
|
|
||||||
{
|
{
|
||||||
$bDebugOutputEnabled = false;
|
$bDebugOutputEnabled = false;
|
||||||
|
|
||||||
@@ -1022,20 +1038,34 @@ class maintainer
|
|||||||
echo "iTargetLevel is ".$iTargetLevel."\n";
|
echo "iTargetLevel is ".$iTargetLevel."\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$oNotificationUpdate = new notificationUpdate($oUser->sEmail, $sSubject,
|
||||||
|
$sMsg, $iTargetLevel);
|
||||||
|
|
||||||
|
return $oNotificationUpdate;
|
||||||
|
}
|
||||||
|
|
||||||
|
// level 0 is from 0 to iNotificationIntervalDays
|
||||||
|
// level 1 is from (iNotificationIntervalDays + 1) to (iNotificationIntervalDays * 2)
|
||||||
|
// level 2 is from (iNotificationIntervalDays * 2 + 1) to (iNotificationIntervalDays * 3)
|
||||||
|
// level 3 is beyond (iNotificationIntervalDays * 3)
|
||||||
|
function processNotificationUpdate($oNotificationUpdate)
|
||||||
|
{
|
||||||
|
$bDebugOutputEnabled = false;
|
||||||
|
|
||||||
// if the target level is less than the current level, adjust the current level
|
// if the target level is less than the current level, adjust the current level
|
||||||
// This takes into account the entries in the users queue that may have been processed
|
// This takes into account the entries in the users queue that may have been processed
|
||||||
if($iTargetLevel < $this->iNotificationLevel)
|
if($oNotificationUpdate->iTargetLevel < $this->iNotificationLevel)
|
||||||
{
|
{
|
||||||
if($bDebugOutputEnabled)
|
if($bDebugOutputEnabled)
|
||||||
echo "Using iTargetLevel of $iTargetLevel\n";
|
echo "Using iTargetLevel of $oNotificationUpdate->iTargetLevel\n";
|
||||||
$this->iNotificationLevel = $iTargetLevel;
|
$this->iNotificationLevel = $oNotificationUpdate->iTargetLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the target level is higher than the current level then adjust the
|
// if the target level is higher than the current level then adjust the
|
||||||
// current level up by 1
|
// current level up by 1
|
||||||
// NOTE: we adjust up by one because we want to ensure that we go through
|
// NOTE: we adjust up by one because we want to ensure that we go through
|
||||||
// notification levels one at a time
|
// notification levels one at a time
|
||||||
if($iTargetLevel > $this->iNotificationLevel)
|
if($oNotificationUpdate->iTargetLevel > $this->iNotificationLevel)
|
||||||
{
|
{
|
||||||
if($bDebugOutputEnabled)
|
if($bDebugOutputEnabled)
|
||||||
echo "Increasing notification level of $this->iNotificationLevel by 1\n";
|
echo "Increasing notification level of $this->iNotificationLevel by 1\n";
|
||||||
@@ -1049,19 +1079,19 @@ class maintainer
|
|||||||
break;
|
break;
|
||||||
case 1: // send the first notification
|
case 1: // send the first notification
|
||||||
// nothing to do here, the first notification is just a reminder
|
// nothing to do here, the first notification is just a reminder
|
||||||
$sMsg.= "\n\nThanks,\n";
|
$oNotificationUpdate->sMsg.= "\n\nThanks,\n";
|
||||||
$sMsg.= "Appdb Admins";
|
$oNotificationUpdate->sMsg.= "Appdb Admins";
|
||||||
break;
|
break;
|
||||||
case 2: // send the second notification, notify them that if the queued entries aren't
|
case 2: // send the second notification, notify them that if the queued entries aren't
|
||||||
// processed after another $iNotificationIntervalDays that
|
// processed after another $iNotificationIntervalDays that
|
||||||
// we'll have to remove their maintainership for this application/version
|
// we'll have to remove their maintainership for this application/version
|
||||||
// so a more active person can fill the spot
|
// so a more active person can fill the spot
|
||||||
$sMsg.= "\nThis your second notification of queued entries. If the queued entries are";
|
$oNotificationUpdate->sMsg.= "\nThis your second notification of queued entries. If the queued entries are";
|
||||||
$sMsg.= " not processed within the next ".iNotificationIntervalDays. "we will remove";
|
$oNotificationUpdate->sMsg.= " not processed within the next ".iNotificationIntervalDays. "we will remove";
|
||||||
$sMsg.= " your maintainership for this application/version so a more active person";
|
$oNotificationUpdate->sMsg.= " your maintainership for this application/version so a more active person";
|
||||||
$sMsg.= " can fill the spot.";
|
$oNotificationUpdate->sMsg.= " can fill the spot.";
|
||||||
$sMsg.= "\n\nThanks,\n";
|
$oNotificationUpdate->sMsg.= "\n\nThanks,\n";
|
||||||
$sMsg.= "Appdb Admins";
|
$oNotificationUpdate->sMsg.= "Appdb Admins";
|
||||||
break;
|
break;
|
||||||
case 3: // remove their maintainership
|
case 3: // remove their maintainership
|
||||||
$this->delete(); // delete ourselves from the database
|
$this->delete(); // delete ourselves from the database
|
||||||
@@ -1070,12 +1100,11 @@ class maintainer
|
|||||||
|
|
||||||
// save the notification level and notification time back into the database
|
// save the notification level and notification time back into the database
|
||||||
$sQuery = "update appMaintainers set notificationLevel = '?', notificationTime = ?".
|
$sQuery = "update appMaintainers set notificationLevel = '?', notificationTime = ?".
|
||||||
" where maintainerId = '?'";
|
" where maintainerId = '?'";
|
||||||
query_parameters($sQuery, $this->iNotificationLevel, "NOW()", $this->iMaintainerId);
|
query_parameters($sQuery, $this->iNotificationLevel, "NOW()", $this->iMaintainerId);
|
||||||
|
|
||||||
//TODO: we probably want to copy the mailing list on each of these emails
|
//TODO: we probably want to copy the mailing list on each of these emails
|
||||||
$sEmail = $oUser->sEmail;
|
$oNotificationUpdate->sEmail.=" cmorgan@alum.wpi.edu"; // FIXME: for debug append my email address
|
||||||
$sEmail.=" cmorgan@alum.wpi.edu"; // FIXME: for debug append my email address
|
|
||||||
|
|
||||||
if($this->iNotificationLevel == 0)
|
if($this->iNotificationLevel == 0)
|
||||||
{
|
{
|
||||||
@@ -1085,17 +1114,27 @@ class maintainer
|
|||||||
{
|
{
|
||||||
if($bDebugOutputEnabled)
|
if($bDebugOutputEnabled)
|
||||||
{
|
{
|
||||||
echo "Email: ".$sEmail."\n";
|
echo "Email: ".$oNotificationUpdate->sEmail."\n";
|
||||||
echo "Subject: ".$sSubject."\n";
|
echo "Subject: ".$oNotificationUpdate->sSubject."\n";
|
||||||
echo "Msg: ".$sMsg."\n\n";
|
echo "Msg: ".$oNotificationUpdate->sMsg."\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
mail_appdb($sEmail, $sSubject, $sMsg);
|
mail_appdb($oNotificationUpdate->sEmail, $oNotificationUpdate->sSubject, $oNotificationUpdate->sMsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function notifyMaintainerOfQueuedData()
|
||||||
|
{
|
||||||
|
$oNotificationUpdate = $this->fetchNotificationUpdate();
|
||||||
|
|
||||||
|
// if we have a valid notificationUpdate then process it, otherwise skip it
|
||||||
|
if($oNotificationUpdate != NULL)
|
||||||
|
$this->processNotificationUpdate($oNotificationUpdate);
|
||||||
|
}
|
||||||
|
|
||||||
// static method called by the cron maintenance script to notify
|
// static method called by the cron maintenance script to notify
|
||||||
// maintainers of data pending for their applications and versions
|
// maintainers of data pending for their applications and versions
|
||||||
|
//TODO: php5 make this static when we have php5
|
||||||
function notifyMaintainersOfQueuedData()
|
function notifyMaintainersOfQueuedData()
|
||||||
{
|
{
|
||||||
// retrieve all of the maintainers
|
// retrieve all of the maintainers
|
||||||
@@ -1103,11 +1142,11 @@ class maintainer
|
|||||||
|
|
||||||
// echo "Processing ".mysql_num_rows($hResult)." maintainers\n";
|
// echo "Processing ".mysql_num_rows($hResult)." maintainers\n";
|
||||||
|
|
||||||
|
// notify this user, the maintainer, of queued data, if any exists
|
||||||
while($oRow = mysql_fetch_object($hResult))
|
while($oRow = mysql_fetch_object($hResult))
|
||||||
{
|
{
|
||||||
// notify this user, the maintainer, of queued data, if any exists
|
|
||||||
$oMaintainer = new maintainer(null, $oRow);
|
$oMaintainer = new maintainer(null, $oRow);
|
||||||
$oMaintainer->notifyMaintainerOfQueuedData($this);
|
$oMaintainer->notifyMaintainerOfQueuedData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user