objectManager: Support purging rejected entries
This commit is contained in:
committed by
Chris Morgan
parent
5db7f0f7fb
commit
70e4306e2b
@@ -1180,6 +1180,16 @@ class Application {
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function objectAllowPurgingRejected()
|
||||||
|
{
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function objectGetSubmitTime()
|
||||||
|
{
|
||||||
|
return mysqltimestamp_to_unixtimestamp($this->sSubmitTime);
|
||||||
|
}
|
||||||
|
|
||||||
public function objectGetId()
|
public function objectGetId()
|
||||||
{
|
{
|
||||||
return $this->iAppId;
|
return $this->iAppId;
|
||||||
|
|||||||
@@ -400,6 +400,16 @@ class application_queue
|
|||||||
return application::allowAnonymousSubmissions();
|
return application::allowAnonymousSubmissions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function objectAllowPurgingRejected()
|
||||||
|
{
|
||||||
|
return $this->oApp->objectAllowPurgingRejected();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function objectGetSubmitTime()
|
||||||
|
{
|
||||||
|
return $this->oApp->objectGetSubmitTime();
|
||||||
|
}
|
||||||
|
|
||||||
function objectGetId()
|
function objectGetId()
|
||||||
{
|
{
|
||||||
return $this->oApp->objectGetId();
|
return $this->oApp->objectGetId();
|
||||||
|
|||||||
@@ -220,6 +220,15 @@ class ObjectManager
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Show a link to the 'purge rejected entries' page if we are an admin */
|
||||||
|
if($_SESSION['current']->hasPriv('admin') && $this->getOptionalSetting('objectAllowPurgingRejected', FALSE))
|
||||||
|
{
|
||||||
|
echo '<div align="center">';
|
||||||
|
$oM = new objectManager($this->sClass, 'Purge Rejected Entries');
|
||||||
|
echo '<a href="'.$oM->makeUrl('purgeRejected').'">Purge rejected entries</a><br /><br />';
|
||||||
|
echo '</div>';
|
||||||
|
}
|
||||||
|
|
||||||
/* output the header */
|
/* output the header */
|
||||||
echo '<table width="100%" border="0" cellpadding="3" cellspacing="0">';
|
echo '<table width="100%" border="0" cellpadding="3" cellspacing="0">';
|
||||||
|
|
||||||
@@ -520,8 +529,9 @@ class ObjectManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Delete the object associated with the given id */
|
/* Delete the object associated with the given id
|
||||||
public function delete_entry($sReplyText)
|
bStandAlone determines whether this is a stand alone delete operation, where we want to output messages and return */
|
||||||
|
public function delete_entry($sReplyText, $bStandAlone = true)
|
||||||
{
|
{
|
||||||
$this->checkMethods(array("delete", "canEdit"));
|
$this->checkMethods(array("delete", "canEdit"));
|
||||||
|
|
||||||
@@ -603,19 +613,25 @@ class ObjectManager
|
|||||||
if($oSubmitterMail)
|
if($oSubmitterMail)
|
||||||
$oSubmitterMail->send("delete", $sReplyText);
|
$oSubmitterMail->send("delete", $sReplyText);
|
||||||
|
|
||||||
addmsg("Entry deleted", "green");
|
if($bStandAlone)
|
||||||
|
{
|
||||||
|
addmsg("Entry deleted", "green");
|
||||||
|
|
||||||
if($iDeleted)
|
if($iDeleted)
|
||||||
addmsg("Deleted $iDeleted child entries", "green");
|
addmsg("Deleted $iDeleted child entries", "green");
|
||||||
|
|
||||||
if($iFailed)
|
if($iFailed)
|
||||||
addmsg("Failed to delete $iFailed child entries", "red");
|
addmsg("Failed to delete $iFailed child entries", "red");
|
||||||
|
|
||||||
$this->return_to_url($this->makeUrl("view", false));
|
$this->return_to_url($this->makeUrl("view", false));
|
||||||
} else
|
}
|
||||||
{
|
return TRUE;
|
||||||
addmsg("Failed to delete entry", "red");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($bStandAlone)
|
||||||
|
addmsg("Failed to delete entry", "red");
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the user to the url specified in the objectManager object. Fall back to a
|
/* Return the user to the url specified in the objectManager object. Fall back to a
|
||||||
@@ -667,6 +683,94 @@ class ObjectManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Purge rejected entries, optionally by date */
|
||||||
|
public function purgeRejected($aClean)
|
||||||
|
{
|
||||||
|
if(!$_SESSION['current']->hasPriv("admin"))
|
||||||
|
{
|
||||||
|
addmsg("Insufficient privileges", "red");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$this->getOptionalSetting("objectAllowPurgingRejected", FALSE))
|
||||||
|
{
|
||||||
|
addmsg("Purging rejected entries is not allowed for this object type");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
$oObject = $this->getObject();
|
||||||
|
|
||||||
|
$hResult = $oObject->objectGetEntries(true, true);
|
||||||
|
|
||||||
|
if(!$hResult)
|
||||||
|
{
|
||||||
|
addmsg("Failed to get list of rejected entries", "red");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($aClean['bTimeLimit'] == 'true')
|
||||||
|
$iSubmittedBefore = mysqltimestamp_to_unixtimestamp($aClean['sSubmittedBefore']);
|
||||||
|
else
|
||||||
|
$iSubmittedBefore = 0;
|
||||||
|
|
||||||
|
$iDeleted = 0;
|
||||||
|
$iFailed = 0;
|
||||||
|
|
||||||
|
if($sSubmittedBefore)
|
||||||
|
$sMailWord = "old";
|
||||||
|
else
|
||||||
|
$sMailWord = "all";
|
||||||
|
|
||||||
|
while($oRow = mysql_fetch_object($hResult))
|
||||||
|
{
|
||||||
|
$oObject = new $this->sClass(null, $oRow);
|
||||||
|
|
||||||
|
if(!$iSubmittedBefore || $oObject->objectGetSubmitTime() < $iSubmittedBefore)
|
||||||
|
{
|
||||||
|
$oM = new objectManager($this->sClass, "", $oObject->objectGetId());
|
||||||
|
if($oM->delete_entry("Purging $sMailWord rejected entries", false))
|
||||||
|
$iDeleted++;
|
||||||
|
else
|
||||||
|
$iFailed++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($iFailed)
|
||||||
|
addmsg("Failed to delete $iFailed entries", 'red');
|
||||||
|
|
||||||
|
$sNoun = ($iDeleted == 1) ? 'entry' : 'entries';
|
||||||
|
|
||||||
|
if($iDeleted)
|
||||||
|
addmsg("Deleted $iDeleted $sNoun", 'green');
|
||||||
|
|
||||||
|
$this->return_to_url(APPDB_ROOT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function displayPurgeRejected()
|
||||||
|
{
|
||||||
|
if(!$_SESSION['current']->hasPriv("admin"))
|
||||||
|
{
|
||||||
|
$this->error_exit('Only admins can do this');
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$this->getOptionalSetting("objectAllowPurgingRejected", FALSE))
|
||||||
|
{
|
||||||
|
$this->error_exit('Purging rejected entries is not allowed for this object type');
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo '<form action="objectManager.php" action="post" />';
|
||||||
|
echo 'Purge rejected entries of this type<br />';
|
||||||
|
echo '<input type="checkbox" value="true" name="bTimeLimit" /> ';
|
||||||
|
echo 'Only entries submitted before ';
|
||||||
|
echo '<input type="text" name="sSubmittedBefore" size="25" value="'.date('Y-m-d H:i:s').'" /><br /><br />';
|
||||||
|
echo '<input type="hidden" name="sAction" value="doPurgeRejected" />';
|
||||||
|
echo $this->makeUrlFormData();
|
||||||
|
echo '<input type="submit" value="Purge" />';
|
||||||
|
echo '</form>';
|
||||||
|
}
|
||||||
|
|
||||||
/* Move all the object's children to another object of the same type, and
|
/* Move all the object's children to another object of the same type, and
|
||||||
delete the original object afterwards */
|
delete the original object afterwards */
|
||||||
public function move_children($iNewId)
|
public function move_children($iNewId)
|
||||||
|
|||||||
@@ -1213,6 +1213,16 @@ class testData{
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function objectAllowPurgingRejected()
|
||||||
|
{
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function objectGetSubmitTime()
|
||||||
|
{
|
||||||
|
return mysqltimestamp_to_unixtimestamp($this->sSubmitTime);
|
||||||
|
}
|
||||||
|
|
||||||
function objectGetItemsPerPage($bQueued = false)
|
function objectGetItemsPerPage($bQueued = false)
|
||||||
{
|
{
|
||||||
$aItemsPerPage = array(25, 50, 100, 200);
|
$aItemsPerPage = array(25, 50, 100, 200);
|
||||||
|
|||||||
@@ -173,6 +173,16 @@ class testData_queue
|
|||||||
return testData::allowAnonymousSubmissions();
|
return testData::allowAnonymousSubmissions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function objectAllowPurgingRejected()
|
||||||
|
{
|
||||||
|
return $this->oTestData->objectAllowPurgingRejected();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function objectGetSubmitTime()
|
||||||
|
{
|
||||||
|
return $this->oTestData->objectGetSubmitTime();
|
||||||
|
}
|
||||||
|
|
||||||
function objectGetItemsPerPage($bQueued = false)
|
function objectGetItemsPerPage($bQueued = false)
|
||||||
{
|
{
|
||||||
return testData::objectGetItemsPerPage($bQueued);
|
return testData::objectGetItemsPerPage($bQueued);
|
||||||
|
|||||||
@@ -1796,6 +1796,16 @@ class version {
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function objectAllowPurgingRejected()
|
||||||
|
{
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function objectGetSubmitTime()
|
||||||
|
{
|
||||||
|
return mysqltimestamp_to_unixtimestamp($this->sSubmitTime);
|
||||||
|
}
|
||||||
|
|
||||||
public function objectGetId()
|
public function objectGetId()
|
||||||
{
|
{
|
||||||
return $this->iVersionId;
|
return $this->iVersionId;
|
||||||
|
|||||||
@@ -299,6 +299,16 @@ class version_queue
|
|||||||
return version::allowAnonymousSubmissions();
|
return version::allowAnonymousSubmissions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function objectAllowPurgingRejected()
|
||||||
|
{
|
||||||
|
return $this->oVersion->objectAllowPurgingRejected();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function objectGetSubmitTime()
|
||||||
|
{
|
||||||
|
return $this->oVersion->objectGetSubmitTime();
|
||||||
|
}
|
||||||
|
|
||||||
function objectGetId()
|
function objectGetId()
|
||||||
{
|
{
|
||||||
return $this->oVersion->objectGetId();
|
return $this->oVersion->objectGetId();
|
||||||
|
|||||||
@@ -95,6 +95,11 @@ if($sAction)
|
|||||||
if($oObject->getId() && $aClean['iNewId'])
|
if($oObject->getId() && $aClean['iNewId'])
|
||||||
$oObject->move_children($aClean['iNewId']);
|
$oObject->move_children($aClean['iNewId']);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'doPurgeRejected':
|
||||||
|
/* Purge some or all rejected entries */
|
||||||
|
$oObject->purgeRejected($aClean);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,6 +145,10 @@ if($oObject->getId() && $sAction != "add")
|
|||||||
$oObject->add_entry($aClean, $sErrors);
|
$oObject->add_entry($aClean, $sErrors);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'purgeRejected':
|
||||||
|
$oObject->displayPurgeRejected();
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
$oObject->display_table($aClean);
|
$oObject->display_table($aClean);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user