Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
salesforce
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
salesforce
Commits
74a33135
Commit
74a33135
authored
1 year ago
by
Omar Mohamad - El Hassan Lopesino
Committed by
Ricardo Sanz Ante
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3396890
: Allow logging push params and push success
parent
fb96e445
No related branches found
No related tags found
1 merge request
!63
Draft: Resolve #3396890 "Allow logging push"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/salesforce_logger/src/EventSubscriber/SalesforceLoggerSubscriber.php
+63
-0
63 additions, 0 deletions
...logger/src/EventSubscriber/SalesforceLoggerSubscriber.php
modules/salesforce_logger/src/Form/SettingsForm.php
+28
-0
28 additions, 0 deletions
modules/salesforce_logger/src/Form/SettingsForm.php
with
91 additions
and
0 deletions
modules/salesforce_logger/src/EventSubscriber/SalesforceLoggerSubscriber.php
+
63
−
0
View file @
74a33135
...
...
@@ -7,6 +7,7 @@ use Drupal\Core\Logger\RfcLogLevel;
use
Drupal\Core\Utility\Error
;
use
Drupal\salesforce\Event\SalesforceEvents
;
use
Drupal\salesforce\Event\SalesforceExceptionEventInterface
;
use
Drupal\salesforce_mapping
\Event\SalesforcePushParamsEvent
;
use
Psr\Log\LoggerInterface
;
use
Symfony\Component\EventDispatcher\EventSubscriberInterface
;
...
...
@@ -51,6 +52,8 @@ class SalesforceLoggerSubscriber implements EventSubscriberInterface {
*/
public
static
function
getSubscribedEvents
()
{
$events
=
[
SalesforceEvents
::
PUSH_PARAMS
=>
'salesforcePushParams'
,
SalesforceEvents
::
PUSH_SUCCESS
=>
'salesforcePushSuccess'
,
SalesforceEvents
::
ERROR
=>
'salesforceException'
,
SalesforceEvents
::
WARNING
=>
'salesforceException'
,
SalesforceEvents
::
NOTICE
=>
'salesforceException'
,
...
...
@@ -58,6 +61,66 @@ class SalesforceLoggerSubscriber implements EventSubscriberInterface {
return
$events
;
}
/**
* Log params pushed to salesforce.
*
* This functionality can be setup by configuration so that:
* - The sensitive fields are not saved into database.
* - When the data sent is too large, it can be truncated.
*
* @param \Drupal\salesforce_mapping\Event\SalesforcePushParamsEvent $event
* Salesforce push params event.
*/
public
function
salesforcePushParams
(
SalesforcePushParamsEvent
$event
)
{
$log_push_params
=
(
bool
)
$this
->
config
->
get
(
'log_push_params'
);
if
(
$log_push_params
)
{
$fields_to_sanitize
=
$this
->
config
->
get
(
'log_push_params_sanitized_fields'
)
??
[];
$params
=
$event
->
getParams
()
->
getParams
();
foreach
(
$params
as
$key
=>
$value
)
{
if
(
in_array
(
$key
,
$fields_to_sanitize
))
{
$params
[
$key
]
=
'****'
;
}
}
$max_length
=
$this
->
config
->
get
(
'log_push_params_maxlength'
);
$params_json
=
json_encode
(
$params
);
if
(
!
empty
(
$max_length
)
&&
strlen
(
$params_json
)
>
$max_length
)
{
$params_json
=
substr
(
$params_json
,
0
,
$max_length
)
.
'...'
;
}
$this
->
logger
->
debug
(
sprintf
(
'Entity of type "%s" is being pushed to salesforce "%s" entity. Drupal entity ID: %s. Data: %s'
,
$event
->
getEntity
()
->
getEntityTypeId
(),
$event
->
getMapping
()
->
getSalesforceObjectType
(),
$event
->
getEntity
()
->
id
(),
$params_json
)
);
}
}
/**
* Logs when a entity is mapped successfully to salesforce.
*
* @param \Drupal\salesforce_mapping\Event\SalesforcePushParamsEvent $event
* Push params event with salesforce ID.
*/
public
function
salesforcePushSuccess
(
SalesforcePushParamsEvent
$event
)
{
$log_push_params
=
(
bool
)
$this
->
config
->
get
(
'log_push_success'
);
if
(
$log_push_params
)
{
$this
->
logger
->
info
(
sprintf
(
'Entity of type "%s" has been succesfully sent to salesforce as a "%s" entity. Drupal entity ID: %s. Salesforce entity ID: %s.'
,
$event
->
getEntity
()
->
getEntityTypeId
(),
$event
->
getMapping
()
->
getSalesforceObjectType
(),
$event
->
getEntity
()
->
id
(),
$event
->
getMappedObject
()
->
sfid
()
)
);
}
}
/**
* SalesforceException event callback.
*
...
...
This diff is collapsed.
Click to expand it.
modules/salesforce_logger/src/Form/SettingsForm.php
+
28
−
0
View file @
74a33135
...
...
@@ -44,6 +44,30 @@ class SettingsForm extends ConfigFormBase {
'#default_value'
=>
$config
->
get
(
'log_level'
),
];
$form
[
'log_push_params'
]
=
[
'#title'
=>
$this
->
t
(
'Log push params sent to salesforce'
),
'#type'
=>
'checkbox'
,
'#default_value'
=>
$config
->
get
(
'log_push_params'
)
??
FALSE
,
];
$form
[
'log_push_params_maxlength'
]
=
[
'#title'
=>
$this
->
t
(
'Log push params max length'
),
'#type'
=>
'number'
,
'#default_value'
=>
$config
->
get
(
'log_push_params_maxlength'
)
??
NULL
,
];
$form
[
'log_push_params_sanitized_fields'
]
=
[
'#title'
=>
$this
->
t
(
'Fields that must not be shown in logs'
),
'#type'
=>
'textarea'
,
'#default_value'
=>
implode
(
"
\r\n
"
,
$config
->
get
(
'log_push_params_sanitized_fields'
)
??
[]),
];
$form
[
'log_push_success'
]
=
[
'#title'
=>
$this
->
t
(
'Log push success when an entity is sent to salesforce'
),
'#type'
=>
'checkbox'
,
'#default_value'
=>
$config
->
get
(
'log_push_success'
)
??
FALSE
,
];
$form
=
parent
::
buildForm
(
$form
,
$form_state
);
return
$form
;
}
...
...
@@ -54,6 +78,10 @@ class SettingsForm extends ConfigFormBase {
public
function
submitForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
$config
=
$this
->
config
(
'salesforce_logger.settings'
);
$config
->
set
(
'log_level'
,
$form_state
->
getValue
(
'log_level'
));
$config
->
set
(
'log_push_params'
,
$form_state
->
getValue
(
'log_push_params'
));
$config
->
set
(
'log_push_params_maxlength'
,
(
int
)
$form_state
->
getValue
(
'log_push_params_maxlength'
));
$config
->
set
(
'log_push_params_sanitized_fields'
,
explode
(
"
\r\n
"
,
$form_state
->
getValue
(
'log_push_params_sanitized_fields'
)
??
''
));
$config
->
set
(
'log_push_success'
,
$form_state
->
getValue
(
'log_push_success'
));
$config
->
save
();
parent
::
submitForm
(
$form
,
$form_state
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment