Help: Getting a project's view_state

General discussion about MantisBT Plugins

Moderators: Developer, Contributor

Post Reply
Lakmir
Posts: 2
Joined: 31 Mar 2018, 00:03

Help: Getting a project's view_state

Post by Lakmir »

Hi,

I've downloaded a MantisBT/Discord webhook plugin (https://github.com/TechGuard/MantisBT-Discord) which is heavily based on the Slack plugin (viewtopic.php?f=15&t=25349). I'm hacking it up a little; I've removed the URL embed, but I'd also like to make it so that if a project's view_state is set to private, the webhook skips printing out the change. It already does this if the issue itself has a view_state of VS_PRIVATE, but I'm having problems getting the project's overall view_state. I've been digging through the SOAP API docs and I haven't found an easy way of doing this. Keep in mind that I'm a PHP beginner; I'm also on shared hosting so I don't have access to logs to figure out what's wrong with my code.

Here's one of the functions as it's originally written:

Code: Select all

	function bug_report_update($event, $bug, $bug_id)
	{
		lang_push( plugin_config_get('language') );
		$this->skip = $this->skip || gpc_get_bool('slack_skip') || $bug->view_state == VS_PRIVATE;
		$project  = project_get_name($bug->project_id);
		$url      = string_get_bug_view_url_with_fqdn($bug_id);
		$summary  = $this->format_summary($bug);
		$reporter = $this->get_user_name(auth_get_current_user_id());
		$handler  = $this->format_value($bug, 'handler_id');
		$msg      = sprintf(plugin_lang_get($event === 'EVENT_REPORT_BUG' ? 'bug_created' : 'bug_updated'),
			$project, $reporter, $url, $summary, $handler
		);
		$this->notify($msg, $this->get_webhook($project), $this->get_attachment($bug));
		lang_pop();
	}
Here's how I'm hacking it, ideally:

Code: Select all

		lang_push( plugin_config_get('language') );
		$project  = project_get_name($bug->project_id);
		$p_id     = $bug->project_id;
		$projdata = mci_project_get($p_id, "english", true);
		$p_viewst = $projdata['view_state']
		$this->skip = $this->skip || gpc_get_bool('slack_skip') || $bug->view_state == VS_PRIVATE || $p_viewst == VS_PRIVATE;
It appears to be failing on the mci_project_get line, but as far as I can tell I've used the function correctly. (api source) I've removed everything after that (the p_viewst line and the addition of p_viewst to the this-> skip line) and I still get an error 500 when updating a bug. What am I doing wrong?
atrol
Site Admin
Posts: 8366
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: Help: Getting a project's view_state

Post by atrol »

This line of code should do the job

Code: Select all

$t_view_state = project_get_field( $p_id, 'view_state' );
Please use Search before posting and read the Manual
Lakmir
Posts: 2
Joined: 31 Mar 2018, 00:03

Re: Help: Getting a project's view_state

Post by Lakmir »

That did it. Thank you!
Post Reply