Plugin or Code to Delete Source Objects When Deleting River Objects?

It occurs to me that I'd like to see behaviour in the river that matches modern social sites - whereby when I delete a river entry, it's underlying object is deleted to. Does a plugin to do this already exist?

thanks

  • You can easily do it on your own.

    In your custom plugin add the action path in your elgg-plugin.php:

    
    return [
       'actions' => [
          'river/delete' => [],
       ],
    ];

    Now create a file actions/river/delete.php with the following content

    
    $id = (int) get_input('id');
    
    $items = elgg_get_river(['id' => $id]);
    if (!$items) {
    	return elgg_error_response(elgg_echo('river:delete:fail'));
    }
    
    $item = $items[0];
    $entity = get_entity($item->object_guid);
    
    if (!$item->canDelete()) {
    	return elgg_error_response(elgg_echo('river:delete:lack_permission'));
    }
    
    if (!$item->delete()) {
    	return elgg_error_response(elgg_echo('river:delete:fail'));
    }
    
    $entity->delete();
    
    return elgg_ok_response('', elgg_echo('river:delete:success'));
    
    
  • remember to flush your cache and run an upgrade before testing it.!

  • BE CAREFUL HERE!!!

    Firstly, the delete option (of river items on the activity page) is only available to admins by default. If it would be intended for normal users also being able to delete river items (AND possibly deleting also the content the items belong to) is something that would have to be changed additionally.

    But the main thing to consider is that not all river entries belong to Elgg entity OBJECTS (blogs, files, comments, etc.). Some entries are connected with USER or GROUP entities (e.g. a user updated his profile, joined a group, etc.). As long as only the river entry gets deleted this might not be too severe. But if you delete the entity (AS ADMIN!) that is the object entity of the river entry you would delete the user or group if you changed the code for not only the river entry getting deleted but the corresponding object entity too. So, you could permanently delete a user or group (together with all the user's / group's content) with one thoughtless click!!!

  • hehe, yes, any code would have to check for these things for safety. i thought that the cross/delete icon was visible for users on their own items in the river, but I see it isn't - so most likely I won't bother to implement this. thanks!