[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[EP-tech] email notification on a specific metadata field value change



CAUTION: This e-mail originated outside the University of Southampton.
To log something in the history dataset, you need to do something like this:
https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Feprints%2Feprints%2Fblob%2F3.3%2Fperl_lib%2FEPrints%2FDataObj%2FEPrint.pm%23L755-L772&data=05%7C01%7Ceprints-tech%40ecs.soton.ac.uk%7C24917ee7cded4358f27008da78a92567%7C4a5378f929f44d3ebe89669d03ada9d8%7C0%7C0%7C637954965110788748%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=TMaXxKfeta%2FbdstQEKPk14afQtZIyl35zZHqwxiGtt4%3D&reserved=0

I don't think the 'revision' needs to be set.
The 'action' value is defined as a set: https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Feprints%2Feprints%2Fblob%2F3.3%2Fperl_lib%2FEPrints%2FDataObj%2FHistory.pm%23L120-L137&data=05%7C01%7Ceprints-tech%40ecs.soton.ac.uk%7C24917ee7cded4358f27008da78a92567%7C4a5378f929f44d3ebe89669d03ada9d8%7C0%7C0%7C637954965110788748%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=04ypc9EMlGCE5Ri50i8a5iY9oi1H80K1UCDW3gGKotg%3D&reserved=0
You could use the 'note' or 'other' action and include info in the 'details' field.

An alternative approach would be to add a new value to the set of options (pushing a value onto the set), or redefining the history->action field using 'replace_core'. This would be beneficial if you ever needed to search the history dataset for that specific action.

Hope that gets you somewhere close to a working solution!
Cheers,
John

________________________________
From: Tomasz Neugebauer <Tomasz.Neugebauer at concordia.ca>
Sent: 05 August 2022 22:20
To: John Salter <J.Salter at leeds.ac.uk>; eprints-tech at ecs.soton.ac.uk <eprints-tech at ecs.soton.ac.uk>
Subject: RE: [EP-tech] email notification on a specific metadata field value change


Thank you, John!  Yes, that worked for me, the function looks like this:



$c->add_dataset_trigger( 'eprint', EPrints::Const::EP_TRIGGER_BEFORE_COMMIT, sub

{

    my( %args ) = @_;

    my( $session, $eprint, $changed ) = @args{qw( repository dataobj changed )};



   if( exists $changed->{'field_of_interest'} )

    {

        my $old_val = $changed->{'field_of_interest'};

        my $new_val = $eprint->get_value( 'field_of_interest');



                        my $user = $eprint->get_user();

                        my $username = EPrints::Utils::tree_to_utf8( $user->render_description() );



        # generate an email alert

                        if ($old_val eq 'FALSE' && $new_val eq 'TRUE') {

                                    print STDERR "field_of_interest Changed from ".$old_val." ".$new_val." SEND NOTIFICATION EMAIL";



                                    my $message = $session->make_element( "p" );

                                    $message->appendChild( $session->make_text("Hello " . $username.","));

                                    $message->appendChild($session->make_element( "br" ));

                                    $message->appendChild($session->make_element( "br" ));



                                    my $title = $session->make_element( "strong" );

                                    $title->appendChild($session->make_text($eprint->get_value("title")));



                                    $message->appendChild($session->make_text( "This email is to let you know that the following item you deposited: "));

                                    $message->appendChild($title);

                                    $message->appendChild($session->make_text(" (".$eprint->get_url().")"));

                                    $message->appendChild($session->make_text(" has changed in a specific way."));



                                    my $ok = $user->mail("field_change_phrase",$message);

                        }



    }

}, priority => 73);



This works!  The only thing is, I would like the action to register in the history for the item, any idea how would I do that?



Tomasz





From: John Salter <J.Salter at leeds.ac.uk>
Sent: August 3, 2022 5:37 PM
To: eprints-tech at ecs.soton.ac.uk; Tomasz Neugebauer <Tomasz.Neugebauer at concordia.ca>
Subject: RE: [EP-tech] email notification on a specific metadata field value change



Attention This email originates from outside the concordia.ca domain. // Ce courriel provient de l'exterieur du domaine de concordia.ca





This sounds like a job for a commit trigger.
There is a 'changed' hash - which has the old field values in it (the EPrint object already has the newer values in it).



You can check whether the field you are interested in is a key in the changed hash, and use that as a basis for sending an email.

NB The example below may not be syntactically correct. It's lashed together late at night (for me anyway), but I think you'll get the idea. Happy to answer questions about it in (my) morning!



Cheers,

John



$c->add_dataset_trigger( 'eprint', EPrints::Const::EP_TRIGGER_BEFORE_COMMIT, sub

{

    my( %args ) = @_;

    my( $repo, $user, $changed ) = @args{qw( repository dataobj changed )};



   if( exists $changed->{'the_field_youre_interested_in'} )

    {

        my $old_val = $changed->{'the_field_youre_interested_in'};

        my $new_val = $eprint->get_value( 'the_field_youre_interested_in' );



        # generate an email alert

    }

}, priority => 73);













From: eprints-tech-bounces at ecs.soton.ac.uk<mailto:eprints-tech-bounces at ecs.soton.ac.uk> [mailto:eprints-tech-bounces at ecs.soton.ac.uk] On Behalf Of Tomasz Neugebauer via Eprints-tech
Sent: 03 August 2022 22:18
To: eprints-tech at ecs.soton.ac.uk<mailto:eprints-tech at ecs.soton.ac.uk>
Subject: [EP-tech] email notification on a specific metadata field value change



CAUTION: This e-mail originated outside the University of Southampton.

Another question from me, I hope I don?t get blocked for posting too many!

I would like to add an email notification that would be sent out to the depositor when a specific editor-only metadata field changes in a deposit.

What would be the best/easiest way to get that done?

This method is the only way that comes to mind, but it seems complicated.  Would I need to

1.    add an item field with a date value,

2.    use ?automatic fields.pl? to insert a date of when the field changes into it whenver the field that I want monitored changes, and

3.    run a batch script nightly to send the notification email to for all those items that have ?today?s? date in the monitor field

Or could I use a trigger mechanism on this field to send out the email?

Tomasz




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ecs.soton.ac.uk/pipermail/eprints-tech/attachments/20220807/3f3d596a/attachment-0001.html