Skip to content

Conversation

putzwasser
Copy link
Contributor

Q A
Bug fix? (use the a.b branch) 🟢
New feature/enhancement? (use the a.x branch) 🟢
Deprecations? 🔴
BC breaks? (use the c.x branch) 🔴
Automated tests included? 🟢
Related user documentation PR URL mautic/user-documentation#...
Related developer documentation PR URL mautic/developer-documentation-new#...
Issue(s) addressed Fixes #...

Description

Before this PR fixes two related bugs in the custom Point Action extension logic.

  1. A simple Point Action can omit providing a form to set additional properties (e.g., limiting points for downloads only to specific assets). If it does that a redundant form element (Change points (+/-) input element) gets shown.
  2. Mautic lets you set the points change using the Change points (+/-) input element at the top. This field is ignored by the default attribution logic. It uses the second and redundant input element.

What 2 means: If you provide your own action property form, you can't set a point change value that Mautic will use. Your action gets triggered but no points change is applied.

Side-note: Why do the built-in point actions work, then? ⇒ Because they also provide their own callback in their config (I won't go into detail here, but this obfuscated this bug, as their actions and trigger/attribution conditions are more complex).

The form

Before this PR Mautic added the GenericPointSettingsType to the Point Action form, if the custom action doesn't provide its own property form type. This form type renders the Change points (+/-) input element a second time.

Before After
image image

Point attribution

Before this PR the Mautic\PointBundle\Helper\EventHelper::engagePointAction tried to find the point change value in the custom action's attributes.

This made it necessary to use the second (and redundant; marked red above) points delta input element. If you provided your own property form type Mautic always applied a point change value of 0.

So, basically: Mautic ignored what you've entered in the top the Change points (+/-) input element.


📋 Steps to test this PR:

  1. Open this PR on Gitpod or pull down for testing locally (see docs on testing PRs here)
  2. Add the TestPointSubscriber to your Mautic instance (put it in any EventListener folder)
  3. Navigate to Point Actions > New
  4. Select the Hello World - My custom action action in the Action taken by contact form element
  5. See that no additional Change points (+/-) input element gets added
  6. Add points, save
  7. Open an incognito tab
  8. Create a new identified Contact by submitting some form
  9. See that the newly identified Contact got attributed the points you defined

Sample Listener

This listener registers an example custom point action and an event listener to the LeadEvents::LEAD_IDENTIFIED event that triggers the point action.

<?php

declare(strict_types=1);

use Mautic\LeadBundle\Event\LeadEvent;
use Mautic\LeadBundle\LeadEvents;
use Mautic\PointBundle\Event\PointBuilderEvent;
use Mautic\PointBundle\Model\PointModel;
use Mautic\PointBundle\PointEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class TestPointSubscriber implements EventSubscriberInterface
{
	public const ACTION_NAME = 'helloworld.action.custom_action';

	public function __construct(
		private PointModel $pointModel,
	) {
	}

	public static function getSubscribedEvents(): array
	{
		return [
			PointEvents::POINT_ON_BUILD => ['onPointBuild', 0],
			LeadEvents::LEAD_IDENTIFIED => ['onLeadIdentified', 0],
		];
	}

	/**
	 * Register the plugin's custom Point Action.
	 */
	public function onPointBuild(PointBuilderEvent $event): void
	{
		$action = [
			'group' => 'Hello World',
			'label' => 'My custom action',
		];

		$event->addAction(self::ACTION_NAME, $action);
	}

	/**
	 * Sample event listener just to trigger the point action above
	 */
	public function onLeadIdentified(LeadEvent $event): void
	{
		$this->pointModel->triggerAction(self::ACTION_NAME);
	}
}

Copy link

codecov bot commented Jun 20, 2024

Codecov Report

Attention: Patch coverage is 55.55556% with 4 lines in your changes missing coverage. Please review.

Project coverage is 62.26%. Comparing base (1e4d5bf) to head (b479167).

Files with missing lines Patch % Lines
.../bundles/PointBundle/Controller/AjaxController.php 0.00% 2 Missing ⚠️
.../bundles/PointBundle/Form/Type/PointActionType.php 0.00% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##                5.1   #13868   +/-   ##
=========================================
  Coverage     62.25%   62.26%           
- Complexity    34217    34218    +1     
=========================================
  Files          2251     2251           
  Lines        102327   102328    +1     
=========================================
+ Hits          63705    63711    +6     
+ Misses        38622    38617    -5     
Files with missing lines Coverage Δ
...PointBundle/Form/Type/GenericPointSettingsType.php 0.00% <ø> (ø)
app/bundles/PointBundle/Form/Type/PointType.php 88.88% <100.00%> (-0.25%) ⬇️
app/bundles/PointBundle/Helper/EventHelper.php 100.00% <100.00%> (+100.00%) ⬆️
.../bundles/PointBundle/Controller/AjaxController.php 0.00% <0.00%> (ø)
.../bundles/PointBundle/Form/Type/PointActionType.php 0.00% <0.00%> (ø)

... and 1 file with indirect coverage changes

@andersonjeccel andersonjeccel added T2 Medium difficulty to fix (issue) or test (PR) bug Issues or PR's relating to bugs points-scoring Anything related to points labels Jun 21, 2024
@escopecz escopecz added the pending-feedback PR's and issues that are awaiting feedback from the author label Jun 28, 2024
Copy link
Member

@escopecz escopecz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good 👍

@escopecz escopecz added pending-test-confirmation PR's that require one test before they can be merged code-review-passed PRs which have passed code review and removed pending-feedback PR's and issues that are awaiting feedback from the author labels Jun 28, 2024
@andersonjeccel andersonjeccel added T3 Hard difficulty to fix (issue) or test (PR) and removed T2 Medium difficulty to fix (issue) or test (PR) labels Aug 20, 2024
@escopecz
Copy link
Member

@putzwasser can you please rebase or cherrypick the commits on top of the 5.x branch? There will be no more releases for 5.1

@escopecz escopecz added the needs-rebase PR's that need to be rebased label Oct 22, 2024
@putzwasser
Copy link
Contributor Author

#14218

@escopecz
Copy link
Member

@putzwasser thanks! Could you copy the PR description from this PR to #14218 and close this one?

@putzwasser putzwasser closed this Oct 23, 2024
escopecz pushed a commit that referenced this pull request Nov 5, 2024
* TASK: Removes `GenericPointSettingsType` from ajax call

* TASK: Removes GenericPointSettingsType

* FIX: Makes PointBundle `EventHelper` use the right array item to access points

* FIX: Sets initiated state

* TASK: Adds test

* FIX: phpstan

* TASK: Re-creates `GenericPointSettingsType.php` for semver and adds depreciation notice
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues or PR's relating to bugs code-review-passed PRs which have passed code review needs-rebase PR's that need to be rebased pending-test-confirmation PR's that require one test before they can be merged points-scoring Anything related to points T3 Hard difficulty to fix (issue) or test (PR)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants