*solved* Admin log, add pirep id in log

Hello Guys,

when a comment is deleted from a pirep there is only “Deleted a comment” written in the Log.

Is there a chance that (like when a pirep comment is added) there is also written the pirep number from which the comment was delete?

I tried with “LogData::addLog(Auth::$userinfo->pilotid, ‘Deleted a comment’ . $pirepid);” but without success.

Thanks in advance for your help.

BRGDS Thomas

 

I assume you mean in the admin log…

You may want to find the Add Comment code and see how the pirepid is called there - and then adapt it to the delete comment code.

Yes correct, I mean the admin log. Sorry for not being clear.

Your proposal was also my first try but unfortunately I haven’t been able to implement it.

The comment id is posted but not the PIREPID so you would have to find it like this:

$commentid = DB::escape($this-\>post-\>id); $pirep = "SELECT \* FROM ".TABLE\_PREFIX."pirepcomments WHERE `id` = '$commentid'"; LogData::addLog(Auth::$userinfo-\>pilotid, 'Deleted a comment to PIREP #: '.$pirep-\>pirepid);

I would usually put the query into the PIREP Data class, but for this small example (since there’s no method already available) it should be fine to leave it this way.

Thanks for your answer,

I tried it but it don’t worked:

In the log there stands only: “Deleted a comment to PIREP #:

 

Here the inserted code:

 

 public function deletecomment() { if (!isset($this-\>post)) { return; } PIREPData::deleteComment($this-\>post-\>id); $commentid = DB::escape($this-\>post-\>id); $pirep = "SELECT \* FROM ".TABLE\_PREFIX."pirepcomments WHERE `id` = '$commentid'"; LogData::addLog(Auth::$userinfo-\>pilotid, 'Deleted a comment to PIREP #: '.$pirep-\>pirepid); $this-\>set('message', 'Comment deleted!'); $this-\>render('core\_success.tpl'); }

 

Oops I forgot a line before, try this:

public function deletecomment() { if (!isset($this-\>post)) { return; } PIREPData::deleteComment($this-\>post-\>id); $commentid = DB::escape($this-\>post-\>id); $pirep = DB::get\_row("SELECT \* FROM ".TABLE\_PREFIX."pirepcomments WHERE `id` = '$commentid'"); LogData::addLog(Auth::$userinfo-\>pilotid, 'Deleted a comment to PIREP #: '.$pirep-\>pirepid); $this-\>set('message', 'Comment deleted!'); $this-\>render('core\_success.tpl'); }

 

Thanks for your quick answer.

Tested it but it don’t works. :disappointed_face:

Just for confirmation… with your code i only need to chage the PIREPAdmin.php file?

Yes only the PIREPAdmin.php file, try this

 

public function deletecomment() { if (!isset($this-\>post)) { return; } $commentid = DB::escape($this-\>post-\>id); $comment = DB::get\_row("SELECT \* FROM ".TABLE\_PREFIX."pirepcomments WHERE `id` = '$commentid'"); LogData::addLog(Auth::$userinfo-\>pilotid, 'Deleted a comment to PIREP #: '.$comment-\>pirepid); PIREPData::deleteComment($this-\>post-\>id); $this-\>set('message', 'Comment deleted!'); $this-\>render('core\_success.tpl'); }

The query looks right, I think it might have been deleting the comment and then trying to find it which wouldn’t work.

You could also do it this way I would think (that way it will only log it if it has been deleted, but it should do it 99% of the time anyway)

$commentid = DB::escape($this-\>post-\>id); $comment = DB::get\_row("SELECT \* FROM ".TABLE\_PREFIX."pirepcomments WHERE `id` = '$commentid'"); PIREPData::deleteComment($this-\>post-\>id); LogData::addLog(Auth::$userinfo-\>pilotid, 'Deleted a comment to PIREP #: '.$comment-\>pirepid);

 

1 Like

Yes it was the failure you described :slight_smile:

Deleting and searching afterwards can’t work.

Changed the order and it works perfect.

Thank you so much for your help.

BRGDS Thomas