Skip to content

Commit

Permalink
See ezsystems#404 - Add location addition, removal, and change of mai…
Browse files Browse the repository at this point in the history
…n location to the audit log
  • Loading branch information
thiago2509 committed Feb 3, 2017
1 parent 79c8393 commit 4560d33
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
21 changes: 21 additions & 0 deletions kernel/classes/ezaudit.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,27 @@ static function writeAudit( $auditName, $auditAttributes = array() )
if ( !isset( $auditNameSettings[$auditName] ) )
return false;

switch( $auditName )
{
case 'main-node-update':
{
$db = eZDB::instance();
$oldMainNodeArray = $db->arrayQuery(
"SELECT main_node_id, parent_node_id, ezcontentobject.name AS name FROM ezcontentobject_tree " .
"INNER JOIN eznode_assignment ON eznode_assignment.contentobject_id = ezcontentobject_tree.contentobject_id " .
"INNER JOIN ezcontentobject ON ezcontentobject.id = ezcontentobject_tree.contentobject_id " .
"WHERE ezcontentobject_tree.contentobject_id = {$auditAttributes['Content object ID']} " .
"AND eznode_assignment.is_main = 1 " .
"AND eznode_assignment.parent_node = ezcontentobject_tree.parent_node_id " .
"AND ezcontentobject.current_version = eznode_assignment.contentobject_version" );
$auditAttributes['Old Main Node ID'] = $oldMainNodeArray[0]['main_node_id'];
$auditAttributes['Old Main Parent Node ID'] = $oldMainNodeArray[0]['parent_node_id'];
$auditAttributes['Content object name'] = $oldMainNodeArray[0]['name'];
} break;

default:
}

$ip = eZSys::clientIP();
if ( !$ip )
$ip = eZSys::serverVariable( 'HOSTNAME', true );
Expand Down
10 changes: 9 additions & 1 deletion kernel/classes/ezcontentobjecttreenode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2888,6 +2888,15 @@ static function updateMainNodeID( $mainNodeID, $objectID, $version = false, $par

$db = eZDB::instance();
$db->begin();

eZAudit::writeAudit( 'main-node-update', array( 'Content object ID' => $objectID,
'New Main Node ID' => $mainNodeID,
'New Parent Node ID' => $parentMainNodeID,
'Old Main Node ID' => '',
'Old Main Parent Node ID' => '',
'Content object name' => '',
'Comment' => 'Updated the main location of the current object: eZContentObjectTreeNode::updateMainNodeID()' ) );

$db->query( "UPDATE ezcontentobject_tree SET main_node_id=$mainNodeID WHERE contentobject_id=$objectID" );
if ( !$version )
{
Expand All @@ -2906,7 +2915,6 @@ static function updateMainNodeID( $mainNodeID, $objectID, $version = false, $par
}

$db->commit();

}

function fetchByCRC( $pathStr )
Expand Down
22 changes: 20 additions & 2 deletions kernel/content/ezcontentoperationcollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,11 @@ static public function addAssignment( $nodeID, $objectID, $selectedNodeIDArray )
}
if ( $locationAdded )
{

eZAudit::writeAudit( 'location-assign', array( 'Main Node ID' => $object->attribute( 'main_node_id' ),
'Content object ID' => $object->attribute( 'id' ),
'Content object name' => $object->attribute( 'name' ),
'New Locations Parent Node ID Array' => implode( ', ' , $selectedNodeIDArray ),
'Comment' => 'Assigned new locations to the current node: eZContentOperationCollection::addAssignment()' ) );
//call appropriate method from search engine
eZSearch::addNodeAssignment( $nodeID, $objectID, $selectedNodeIDArray );

Expand Down Expand Up @@ -845,7 +849,7 @@ static public function removeNodes( array $removeNodeIdList )

$db = eZDB::instance();
$db->begin();

$auditInfoArray = array();
foreach ( $removeNodeIdList as $nodeId )
{
$node = eZContentObjectTreeNode::fetch($nodeId);
Expand All @@ -859,6 +863,11 @@ static public function removeNodes( array $removeNodeIdList )
$nodeAssignmentIdList[$nodeAssignment['id']] = 1;
}
}
$auditInfoArray[$nodeId] = array( 'Removed Node ID' => $nodeId,
'Parent Node ID' => $node->attribute( 'parent_node_id' ),
'Content object ID' => $objectId,
'Content object name' => $node->attribute( 'name' ),
'Old Main Node ID' => $node->attribute( 'main_node_id' ) );

if ( $nodeId == $node->attribute( 'main_node_id' ) )
$mainNodeChanged[$objectId] = 1;
Expand All @@ -880,6 +889,15 @@ static public function removeNodes( array $removeNodeIdList )
eZContentObjectTreeNode::updateMainNodeID( $allNodes[0]->attribute( 'node_id' ), $objectId, false, $allNodes[0]->attribute( 'parent_node_id' ) );
}
}
foreach( $auditInfoArray as $auditInfo )
{
if( isset( $mainNodeChanged[$auditInfo['Content object ID']] ) && $mainNodeChanged[$auditInfo['Content object ID']] instanceof eZContentObjectTreeNode )
$auditInfo['New Main Node ID'] = $mainNodeChanged[$auditInfo['Content object ID']]->attribute( 'node_id' );
else
$auditInfo['New Main Node ID'] = $auditInfo['Old Main Node ID'];
$auditInfo['Comment'] = 'Removed a location of the current node: eZContentOperationCollection::removeNodes()';
eZAudit::writeAudit( 'location-remove', $auditInfo );
}

// Give other search engines that the default one a chance to reindex
// when removing locations.
Expand Down
8 changes: 8 additions & 0 deletions settings/audit.ini
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,11 @@ AuditFileNames[section-assign]=section_assign.log
# Who deleted which order in shop (user / order id)
AuditFileNames[order-delete]=order_delete.log

# Who assigned new locations to a node
AuditFileNames[location-assign]=location_assign.log

# Who removed a location of a node
AuditFileNames[location-remove]=location_remove.log

# Who updated the main node
AuditFileNames[main-node-update]=location_main_update.log

0 comments on commit 4560d33

Please sign in to comment.