Bug #2213
onBeforeDocFormUndelete and onDocFormUndelete don't exist
| Status: | Open | Start date: | ||
|---|---|---|---|---|
| Priority: | Major | Due date: | ||
| Assignee: | % Done: | 0% |
||
| Category: | Core Distribution | |||
| Target version: | Evolution-1.1.0 | |||
| JiraID: | MODX-189 | Resolution: | Unresolved | |
| Environment: | yes | Affects Evolution Version: | Evolution-1.0.3 |
Description
The two events for undelete don't exist. As far as I can tell, these events can be added by
1. inserting two new entries in the database
2. altering the undelete_content.processor.php To insert the new entries in the database: INSERT INTO `law_modx`.`modx_system_eventnames` (
`id` ,
`name` ,
`service` ,
`groupname`
)
VALUES (
NULL , 'OnDocFormUndelete', '1', 'Documents'
), (
NULL , 'OnBeforeDocFormUndelete', '1', 'Documents'
); To alter the undelete_document.processor.php file, add the following code after the line that says
getChildren($id); // invoke OnBeforeDocFormUndelete event
$modx->invokeEvent("OnBeforeDocFormUndelete",
array(
"id"=>$id,
"children"=>$children
)); And add the following code: //'undelete' the document.
$sql = "UPDATE $dbase.`".$table_prefix."site_content` SET deleted=0, deletedby=0, deletedon=0 WHERE id=$id;";
$rs = mysql_query($sql);
if(!$rs) {
echo "Something went wrong while trying to set the document to undeleted status...";
exit;
} else {
// BEGIN NEW CODE:
// invoke OnDocFormUndelete event
$modx->invokeEvent("OnDocFormUndelete",
array(
"id"=>$id,
"children"=>$children
));
// END NEW CODE
History
Updated by Paul Bohman over 3 years ago
I've been using this modified file with the OnBeforeDocFormUndelete and OnDocFormUndelete events, and it has been working. Of course, the same events need to be added to the system_settings table: id = [some integer]
name = OnDocFormUndelete
service = 1
groupname = Documents id = [some integer]
name = OnBeforeDocFormUndelete
service = 1
groupname = Documents
Updated by Paul Bohman over 3 years ago
One more thing: In order to offer more complete functionality to the undelete function, we need to be able to retrieve the full document object of deleted documents. Right now this is not easily retrievable because the full document object is restricted to documents that aren't deleted. To make it work more completely, we need to add a $deleted variable to the getTemplateVars() and getTemplateVarOutput() functions in manager/includes/document.parser.class.inc.php: function getTemplateVars($idnames= array (), $fields= "*", $docid= "", $published= 1, $sort= "rank", $dir= "ASC",$deleted=0) {
/////////////////////////////////// THE LAST VARIABLE ABOVE ($deleted) WAS ADDED BY ME /////////////////////////////////////////////
if (($idnames != '*' && !is_array($idnames)) || count($idnames) == 0) { return false; } else {
$result= array ();
// get document record
if ($docid == "") { $docid= $this->documentIdentifier; $docRow= $this->documentObject; } else {
$docRow= $this->getDocument($docid, '*', $published,$deleted);
/////////////////////////// INCLUDE A REFERENCE TO THE VARIABLE ABOVE //////////////////////////////////
(... function truncated for brevity)
function getTemplateVarOutput($idnames= array (), $docid= "", $published= 1,$deleted=0) {
////////////////////////// THE LAST VARIABLE ABOVE ($deleted) WAS ADDED BY ME ///////////////////////////////////
if (count($idnames) == 0) { return false; } } else {
$output= array ();
$vars= ($idnames == '*' || is_array($idnames)) ? $idnames : array ($idnames);
$docid= intval($docid) ? intval($docid) : $this->documentIdentifier;
$result= $this->getTemplateVars($vars, "*", $docid, $published, "", "",$deleted); // remove sort for speed
////////////////////// NOTE THAT THE $deleted VARIABLE WAS ADDED IN THE LINE ABOVE /////////////////////////////////////////
(... function truncated for brevity)
Updated by Paul Bohman over 3 years ago
See related issues MODX-308 , MODX-312 , MODX-313