Event core.handle_post_delete_conditions apparently ignores delete_reason

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
EVO_VV
Registered User
Posts: 34
Joined: Tue Feb 13, 2018 3:11 pm

Event core.handle_post_delete_conditions apparently ignores delete_reason

Post by EVO_VV » Sat Mar 31, 2018 10:29 am

Following on from the last topic :-
Now I need to be able to set the delete_reason and delete_permanent variables so that the user does not have to fill these in every time the button is used.

However, whilst the variables have been set using :-

Code: Select all

	public function obsolete($event)
	{
	// Same check as in previous topic in here
		$event['delete_reason'] = $delete_reason;
		$event['is_soft'] = false;
		$event['force_delete_allowed'] = true;
		$event['perm_check'] = 'delete';
	}
When the Confirm Box appears the Delete Permanently and Delete Reason are blank.
I can see that I might not be setting the correct thing for the delete_permanent but there is nothing in functions_posting.php to add the delete_reason to the template.
There is only :-

Code: Select all

			$template->assign_vars(array(
				'S_SOFTDELETED'		=> $post_data['post_visibility'] == ITEM_DELETED,
				'S_CHECKED_PERMANENT'	=> $request->is_set_post('delete_permanent') ? ' checked="checked"' : '',
				'S_ALLOWED_DELETE'	=> $can_delete,
				'S_ALLOWED_SOFTDELETE'	=> $can_softdelete,
			));
If I click OK then the post is soft deleted with no reason given in the logs.

How can I achieve getting both of those variables set so that the Confirm Box has those values set ?

Ideally I want a 'pop-up' Confirm Box instead of bringing up a new page but that will take setting ajax-data='true' somewhere.
That, however, is a different question which will probably warrant another topic.
Only mentioned here in case implementing that will actually use those variables I set which would solve the above problem.
Last edited by Mick on Sat Mar 31, 2018 10:53 am, edited 1 time in total.
Reason: Added code tags

User avatar
canonknipser
Registered User
Posts: 1472
Joined: Thu Sep 08, 2011 4:16 am
Location: Germany
Name: Frank Jakobs
Contact:

Re: Event core.handle_post_delete_conditions apparently ignores delete_reason

Post by canonknipser » Sun Apr 01, 2018 11:08 am

Where is your variable $delete_reason filled? From the code you posted, it is a local variable in the first function, but not set anywhere...
Greetings
Frank
phpbb.de support team member
English is not my native language
New arrival - Extensions and scripts for phpBB
no support via PM or mail

EVO_VV
Registered User
Posts: 34
Joined: Tue Feb 13, 2018 3:11 pm

Re: Event core.handle_post_delete_conditions apparently ignores delete_reason

Post by EVO_VV » Sun Apr 01, 2018 1:13 pm

It should be set using the core.handle_post_delete_conditions Event which calls the function obsolete in the listener.
Sorry, had forgotten that I mentioned that in the previous topic.
Also in the previous topic is the '//check' mentioned so the complete code is :-

Code: Select all

	public function obsolete($event)
	{
		$delete_reason = $this->request->variable('delete_reason', '');

		if ($delete_reason != "Obsolete")
		{
			return;
		}
		$event['delete_reason'] = $delete_reason;
		$event['is_soft'] = false;
		$event['force_delete_allowed'] = true;
		$event['perm_check'] = 'delete';
	}
EDIT
I have tried to set an $event['some_variable] = $some_value; or $event['some_string] = "Something"; using various Events in viewtopic.php but still get the same result in that nothing is actually changed.
Therefore I suspect that I am missing something very basic, such as a service that is needed, to be able to do this as I see is done in many extensions that use the same syntax.
My services.yml has :-

Code: Select all

services:
    evovv.obsolete.listener:
        class: evovv\obsolete\event\listener
        arguments:
            - '@request'
            - '%core.root_path%'
            - '%core.php_ext%'
        tags:
            - { name: event.listener }
The listener has the declarations

Code: Select all

/** @var \phpbb\request\request */
	protected $request;
	
	/** @var string phpbb_root_path */
	protected $phpbb_root_path;

	/** @var string phpEx */
	protected $php_ext;
And constructor has

Code: Select all

	public function __construct(\phpbb\request\request $request,  $phpbb_root_path, $php_ext)
	{
		$this->request = $request;
		$this->phpbb_root_path = $phpbb_root_path;
		$this->php_ext	= $php_ext;
	}
Am I missing anything ?
Last edited by kinerity on Sun Apr 01, 2018 9:07 pm, edited 1 time in total.
Reason: [code] tags added

User avatar
RMcGirr83
Recognised Extension Developer
Posts: 20784
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: Event core.handle_post_delete_conditions apparently ignores delete_reason

Post by RMcGirr83 » Sun Apr 01, 2018 4:49 pm

Please use code bbcode when copy pasting. It is very difficult to read as it is now.
Did you assign your function to the core handler?
https://github.com/rmcgirr83/phpBB-nati ... #L107-L110
Do you have this extension on github? That too would make this infinitely easier.
In times of change, learners inherit the earth, while the learned find themselves beautifully equipped to deal with a world that no longer exists - Eric Hoffer
Former Modifications/Extensions Team Member | My extensions
Appreciate the extensions/mods/support then buy me a beer
All requests for support via PM will be ignored

EVO_VV
Registered User
Posts: 34
Joined: Tue Feb 13, 2018 3:11 pm

Re: Event core.handle_post_delete_conditions apparently ignores delete_reason

Post by EVO_VV » Mon Apr 02, 2018 4:33 pm

Apologies for using the incorrect BBCode, I will use the correct one for blocks in the future.
Many Thanks to the gentlemen who corrected my error in that.

Yes the function is assigned in the core handler.
I have now found that I had forgotten an 'echo this and die()' test that I put somewhere else that was stopping me from seeing the results of setting the '$event["variable']'s. This part is now working.

However, even though the variables are set when the 'Confirm Box' appears the 'Delete Permanent' and 'Delete Reason' are blank and if the OK is clicked then that post is soft deleted with no reason logged.

At the very minimum what I want to achieve is that the Delete Permanent box is ticked and the Delete Reason is filled in.
Better still would be to avoid having the 'Return to last Forum' or 'Return to last Topic' appear at all and return to the Topic automatically after deleting the post.
Ideally though what I want is to have a 'Pop-Up' Confirm Box just like the one in the ACP you see when you Purge the Cache leaving the user on the same page and in the same place on that page while still deleting the post and logging the action.

I am unfamiliar with github other than occasionally downloading something from there.
However I can attach a .zip if that helps.
Bear in mind it is a 'work in progress' so not everything is in place yet as I'm slowly getting the pieces working as I go.
.
.
EDIT 4/Apr/2018
Removed attached .zip file as no longer relevant.
Last edited by EVO_VV on Wed Apr 04, 2018 4:20 pm, edited 1 time in total.

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51026
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Event core.handle_post_delete_conditions apparently ignores delete_reason

Post by Brf » Mon Apr 02, 2018 5:08 pm

I am not an expert in this type of coding, but isn't $event being passed by value? In other words it is read-only?
I thought a function parameter had to be received like &$event to be passed back to the caller.

EVO_VV
Registered User
Posts: 34
Joined: Tue Feb 13, 2018 3:11 pm

Re: Event core.handle_post_delete_conditions apparently ignores delete_reason

Post by EVO_VV » Tue Apr 03, 2018 5:15 am

@ Brf Thank you for taking the time to consider my problem, however I don't think that is the issue as the assignments are working fine with the $event in all other places.

In the core.handle_post_delete_conditions Event the $delete_reason is already known so it does not need to be changed, although I would like to be able to alter the Delete Permenant setting.

Directly following the Event (core.handle_post_delete_conditions) in functions_posting there is a check to see if a Confirmation Box should be displayed.
As this condition is satisfied the Confirmation Box is duly displayed.
However, the $delete_reason is ignored even though at this point in the code it is known.

A little further down within the if (confirm_box(true)) condition the $delete_reason is passed to the delete_post function.
BUT at this point $delete_reason is not set whereas just before the if (confirm_box(true)) it is known and set.

So it appears that the Confirm Box is over riding the $delete_reason setting.

It looks like the only way around this is to somehow bypass the core code to handle post deletion and to recreate it within the extension.

Back to the drawing board I think unless anybody can see a way around the issue.

User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 2760
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Event core.handle_post_delete_conditions apparently ignores delete_reason

Post by kasimi » Tue Apr 03, 2018 10:45 pm

Brf, $event is an object (more precise: a reference to an object) that coincidentally act's like an array (it implements the ArrayAccess interface). As it's already a reference, there's no need to explicitly add the &. You only need to specify it on object arguments if you wanted to return an object different from the one passed in.

EVO_VV, prosilver's confirm_delete_body.html doesn't allow setting the reason's value attribute. You would have to use your own template file, or *shudder* use JavaScript.

Checking the perma delete box:

Code: Select all

$this->request->overwrite('delete_permanent', true, \phpbb\request\request_interface::POST);

EVO_VV
Registered User
Posts: 34
Joined: Tue Feb 13, 2018 3:11 pm

Re: Event core.handle_post_delete_conditions apparently ignores delete_reason

Post by EVO_VV » Wed Apr 04, 2018 5:12 am

Many thanks for that kasimi and for taking the time to look into the issue as I know you are very busy.

I have already started to replicate the parts of the core delete post required into the extension and so far it does delete the post but refuses to log the deletion.
Looks like I am not using the correct service and quite probably not implementing it correctly as well.
However, progress is progress and I'll look at some examples to see if I can figure it out starting with mchat as a good working example.

At some stage I will need to 'shudder even more' deal with JavaScript but that will have to wait until the rest of the code is working or I'll run into the problem of echo $this_variable; etc. being sent to Ajax and not letting me debug the code.

Back to the Drawing Board ......
I may be some time ............................

:)

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: No registered users and 6 guests