Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
72.73% |
8 / 11 |
|
50.00% |
3 / 6 |
CRAP | |
0.00% |
0 / 1 |
| Update_Contact | |
72.73% |
8 / 11 |
|
50.00% |
3 / 6 |
7.99 | |
0.00% |
0 / 1 |
| get_slug | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get_title | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get_description | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get_data_type | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get_category | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Jetpack CRM Automation Update_Contact action. |
| 4 | * |
| 5 | * @package automattic/jetpack-crm |
| 6 | * @since 6.2.0 |
| 7 | */ |
| 8 | |
| 9 | namespace Automattic\Jetpack\CRM\Automation\Actions; |
| 10 | |
| 11 | use Automattic\Jetpack\CRM\Automation\Base_Action; |
| 12 | use Automattic\Jetpack\CRM\Automation\Data_Types\Contact_Data; |
| 13 | use Automattic\Jetpack\CRM\Automation\Data_Types\Data_Type; |
| 14 | use Automattic\Jetpack\CRM\Entities\Contact; |
| 15 | use Automattic\Jetpack\CRM\Entities\Factories\Contact_Factory; |
| 16 | |
| 17 | /** |
| 18 | * Adds the Update_Contact class. |
| 19 | * |
| 20 | * @since 6.2.0 |
| 21 | */ |
| 22 | class Update_Contact extends Base_Action { |
| 23 | |
| 24 | /** |
| 25 | * Get the slug name of the step. |
| 26 | * |
| 27 | * @since 6.2.0 |
| 28 | * |
| 29 | * @return string The slug name of the step. |
| 30 | */ |
| 31 | public static function get_slug(): string { |
| 32 | return 'jpcrm/update_contact'; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Get the title of the step. |
| 37 | * |
| 38 | * @since 6.2.0 |
| 39 | * |
| 40 | * @return string|null The title of the step. |
| 41 | */ |
| 42 | public static function get_title(): ?string { |
| 43 | return 'Update Contact Action'; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Get the description of the step. |
| 48 | * |
| 49 | * @since 6.2.0 |
| 50 | * |
| 51 | * @return string|null The description of the step. |
| 52 | */ |
| 53 | public static function get_description(): ?string { |
| 54 | return 'Action to update the contact'; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Get the data type. |
| 59 | * |
| 60 | * @since 6.2.0 |
| 61 | * |
| 62 | * @return string The type of the step. |
| 63 | */ |
| 64 | public static function get_data_type(): string { |
| 65 | return Contact_Data::class; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Get the category of the step. |
| 70 | * |
| 71 | * @since 6.2.0 |
| 72 | * |
| 73 | * @return string|null The category of the step. |
| 74 | */ |
| 75 | public static function get_category(): ?string { |
| 76 | return __( 'Contact', 'zero-bs-crm' ); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Update the DAL with the new contact data. |
| 81 | * |
| 82 | * @since 6.2.0 |
| 83 | * |
| 84 | * @param Data_Type $data Data passed from the trigger. |
| 85 | */ |
| 86 | protected function execute( Data_Type $data ) { |
| 87 | /** @var Contact $contact */ |
| 88 | $contact = $data->get_data(); |
| 89 | |
| 90 | foreach ( $this->attributes as $key => $value ) { |
| 91 | $contact->$key = $value; |
| 92 | } |
| 93 | |
| 94 | global $zbs; |
| 95 | |
| 96 | $zbs->DAL->contacts->addUpdateContact( // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
| 97 | Contact_Factory::data_for_dal( $contact ) |
| 98 | ); |
| 99 | } |
| 100 | } |