Notification on record delete

jo-ka

Member
Hello,

I need to send an mail even when user delete some record. On new and on edit notification is ok, but when someone delete a record, I dcan't get a notification.

Is there some possibility to get some?
 
This is a list plugin, so I assume you can't.

Are you deleting multiple rows in list view or using the delete button in form view?

I have one form php onDeleteRowsForm running with

foreach ($data[0][0] as $row)
{
$xy = $row->my_element;
...

As far as I can remember it's the same hook as in list php events, the form "onDelete" code is also run on delete in list view (and vice versa, therefor you need this loop also in the form code)

Ah, found it:
http://fabrikar.com/forums/index.ph...-deletion-ondeleterowsform.37696/#post-205377
 
The idea is to use the list view, and yes, probably use the multiple delete, and on body mail message use something like;

Code:
$body   = "The user [fab_table___user] has deleted his record with ID [fab_table___id]";

There's where I want to use placeholders. But I'll look at both examples and If I have to use form view, I have to adapt.

Other possibility is to disable select multiple rows and allow only 1 by 1 deletion... Don't know if it makes sense.

Thanks in advance.
 
Try with
var_dump($data[0][0]);exit;
what you get if you are deleting multiple rows.
 

It'd be easier to use the Fabrik sendMail helper, which also does a number of other "things" to help with spam scoring.

Code:
FabrikWorker::sendMail($this->config->get('mailfrom'), $this->config->get('fromname'), $to, $title, $message);

You can usually use $this->config, we inject it into all models when they are instantiated.

For the onDeleteRows in the list php_events plugin, you can get the rows being deleted with getData ... so if you wanted to send an individual message for each row being deleted, with some data from that row (like the email) ...

Code:
$data = $model->getData();
foreach ($data as $group) {
   foreach ($group as $row) {
      FabrikWorker::sendMail(
         $this->config->get('mailfrom'),
         $this->config->get('fromname'),
         $row->yourtable___email_raw,
         "A row has been deleted!",
         "Some message text, perhaps using some form data like this: {$row->yourtable___some_field}"
      );
   }
}

-- hugh
 
Hello.

I've been playing around and I think the best way is to use this:

Code:
$data = $model->getData();
foreach ($data as $group) {
   foreach ($group as $row) {
      FabrikWorker::sendMail(
         $this->config->get('mailfrom'),
         $this->config->get('fromname'),
         $row->yourtable___email_raw,
         "A row has been deleted!",
         "Some message text, perhaps using some form data like this: {$row->yourtable___some_field}"
      );
   }
}

I just couldn't find where in the code I should put the $to variable and also I can't have {$row->yourtable___some_field} populated.

My $to should be something like: yourtable___email1, yourtable___email2, as I need to notify 2 email addresses that are on the row.

Can you please help?

Thanks n advance.
 
You can pass an array of recipient addresses, like this ...

Code:
$data = $model->getData();
foreach ($data as $group) {
   foreach ($group as $row) {
      FabrikWorker::sendMail(
         $this->config->get('mailfrom'),
         $this->config->get('fromname'),
         array(
            $row->yourtable___email1_raw,
            $row->yourtable___email2_raw
         ),
         "A row has been deleted!",
         "Some message text, perhaps using some form data like this: {$row->yourtable___some_field}"
      );
   }
}

Note the _raw suffix to the email, which you may or may not need. For example, if those elements are joins to another table, _raw would probably get you the FK id, not the email (label), so you'd need to remove it. But if they are simple fields, then using _raw would ensure that you get just the address, without any formatting that might be applied (if, say, you are using those fields as details links).

-- hugh
 
OK, I tried first with just one recipient on
Code:
$row->yourtable___email_raw,
, but after the form post, the record is deleted and I can't get any email. There's a warning message saying that at least one destination email (recipient) is needed.

So after it, I've first set $to variable to
Code:
$to="xxx@xxx.com"
and I was able to get the email, but no
Code:
{$row->yourtable___some_field}
is displayed on the message, is just ignored.

Am I missing something?
 
I'm not sure what you mean by a $to variable. The code I gave you doesn't use one, it just sets the recipients directly in the argument list for the sendMail function.

Also ... I presume you are replacing yourtable___email_raw with your actual email element's full name (with _raw appended)?

-- hugh
 
Thanks Hugh.
Maybe I can explain better like this:
This is the code I've set onDeleteRows. So I've used the correct placeholders, as you correctly presumed. You can see the list elements down under.

upload_2018-10-12_19-35-52.png

upload_2018-10-12_19-20-53.png
upload_2018-10-12_19-22-48.png

When I delete the record from the list, I get this error:

upload_2018-10-12_19-25-7.png

If I set the code onDeleteRows like this, the email is sent correctly.

Code:
$to = "xpto@xpto-xpto.pt";
$data = $model->getData();
foreach ($data as $group) {
   foreach ($group as $row) {
      FabrikWorker::sendMail(
         $this->config->get('mailfrom'),
         $this->config->get('fromname'),
         $to,
         "A row has been deleted!",
         "Some message text, perhaps using some form data like this: {$row->fab_dispensas_ca___inicial_raw}"
      );
   }
}

So, what am I doing wrong? Thanks in advance.
 
Does the body of the "correct" email include the expected email adress, i.e. is {$row->fab_dispensas_ca___inicial_raw} replaced?

You can try to debug with
var_dump($data);exit;
or the jdump extension.
 
Did you try to put the email element into the body?
Which element type is email_juiz?
It's working fine on my site.
Make sure there's no typo.
 
Hello. Yes, I've tried and the email is not displayed.
Which lead me to another thinking:
The email field is a calc element, set to AJAX update observing another field.
It's not set to calc on load, as it is observing the other field.

I'm almost sure (never 100%), there's not a typo as I tried this a lot of times copying and pasting the elements name.

So, can this be related with the calc element? Once the value is already stored on the database, does the element type have any kind of influence?

Thanks troester.
 
Pretty sure it's related to the calc element.
Are you sure that the values are stored in the DB?

A calc is only storing if you are saving the record.
So if you add a calc element to a list with existing data the calc field is empty in the existing records (but shown in list view because it's calculating "on the fly").

Check directly in the DB if the values are there.
You may also try without _raw.
 
Yes, I've checked that.
And also I'm sure because I have a form plugin which emails the user when saving the record, using exactly the same field.
I've already tried with and without _raw and with and without { }.
I didn't tried yet with calc on load set to yes on the element.
Do you think it will make any difference?
 
I tried with/without calc on load, with/without show in list, with/without link to details
in all cases the calc element (normal + raw) is included as expected in the mail body.

So no idea, try with
$data = $model->getData();
var_dump($data);exit;

Set list navigation to ajaxfy=no to get the dump on screen (otherwise it will be in the network response).
 
Hello guys, good morning.
I've just found the issue... Damn, you'll not believe.

I' had permission for delete records to SuperUsers for the email element. Although I'm part of the superusers group, when I set the permission to Registered the mail was immediately sent.

Sorry to make you lose time for so stupid issue.

Once more thanks to you.

BR
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top