Issue Details (XML | Word | Printable)

Key: MODX-189
Type: Sub-task Sub-task
Status: Open Open
Priority: Major Major
Assignee: Unassigned
Reporter: Paul Bohman
Votes: 1
Watchers: 3
Operations

If you were logged in you would be able to see more operations.
MODx CMF
MODX-343

onBeforeDocFormUndelete and onDocFormUndelete don't exist

Created: 12/Jul/08 03:41 PM   Updated: 04/Aug/09 12:14 AM
Return to search
Component/s: Core Distribution
Affects Version/s: 0.9.6.1, Evolution-1.1.0
Fix Version/s: Evolution-1.1.0

Time Tracking:
Not Specified

File Attachments: 1. File undelete_content.processor.php (3 kB)

Environment: yes


 Description  « Hide
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



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Paul Bohman added a comment - 31/Aug/08 10:13 PM
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


Paul Bohman added a comment - 02/Sep/08 01:56 PM - edited
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)


Paul Bohman added a comment - 04/Sep/08 10:46 AM
See related issues MODX-308, MODX-312, MODX-313