Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
salesforce-3257058
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
Issue forks
salesforce-3257058
Commits
c8049009
Commit
c8049009
authored
8 years ago
by
Alexander Rhodes
Browse files
Options
Downloads
Patches
Plain Diff
Makes linter pass on CronPull and DeleteHandler
parent
c57fa447
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/salesforce_pull/src/DeleteHandler.php
+57
-36
57 additions, 36 deletions
modules/salesforce_pull/src/DeleteHandler.php
modules/salesforce_pull/src/Plugin/QueueWorker/CronPull.php
+1
-0
1 addition, 0 deletions
modules/salesforce_pull/src/Plugin/QueueWorker/CronPull.php
with
58 additions
and
36 deletions
modules/salesforce_pull/src/DeleteHandler.php
+
57
−
36
View file @
c8049009
...
...
@@ -5,14 +5,10 @@ namespace Drupal\salesforce_pull;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
use
Drupal\Core\State\StateInterface
;
use
Drupal\Core\Utility\Error
;
use
Drupal\salesforce\Exception
;
use
Drupal\salesforce\Rest\RestClient
;
use
Drupal\salesforce\SFID
;
use
Drupal\salesforce\SelectQuery
;
use
Drupal\salesforce_mapping
\Entity\SalesforceMapping
;
use
Drupal\salesforce_mapping
\MappedObjectStorage
;
use
Drupal\salesforce_mapping
\MappingConstants
;
use
Drupal\salesforce_mapping
\SalesforceMappingStorage
;
use
Psr\Log\LogLevel
;
use
Psr\Log\LoggerInterface
;
use
Symfony\Component\HttpFoundation\Request
;
...
...
@@ -25,71 +21,87 @@ use Symfony\Component\HttpFoundation\Request;
class
DeleteHandler
{
/**
* Rest client service.
*
* @var \Drupal\salesforce\Rest\RestClient
*/
protected
$sfapi
;
/**
* Salesforce mapping storage service.
*
* @var \Drupal\salesforce_mapping\SalesforceMappingStorage
*/
protected
$mapping
_s
torage
;
protected
$mapping
S
torage
;
/**
* Mapped Object storage service.
*
* @var \Drupal\salesforce_mapping\MappedObjectStorage
*/
protected
$mapped
_o
bject
_s
torage
;
protected
$mapped
O
bject
S
torage
;
/**
* Entity tpye manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected
$etm
;
/**
* State service.
*
* @var \Drupal\Core\State\StateInterface
*/
protected
$state
;
/**
* Logging service.
*
* @var \Psr\Log\LoggerInterface
*/
protected
$logger
;
/**
* Request service.
*
* @var \Symfony\Component\HttpFoundation\Request
*/
protected
$request
;
/**
* Constructor.
*
* @param \Drupal\salesforce\Rest\RestClient $sfapi
* RestClient object
* @param \Drupal\Core\Entity\EntityTyp
r
ManagerInterface
$
$entity_type_manager
* Entity Manager service
* @param \Drupal\Core\State\StatInterface $state
* State service
*
RestClient object
.
* @param \Drupal\Core\Entity\EntityTyp
e
ManagerInterface $entity_type_manager
*
Entity Manager service
.
* @param \Drupal\Core\State\Stat
e
Interface $state
*
State service
.
* @param Psr\Log\LoggerInterface $logger
* Logging service
*
Logging service
.
*/
private
function
__construct
(
RestClient
$sfapi
,
EntityTypeManagerInterface
$entity_type_manager
,
StateInterface
$state
,
LoggerInterface
$logger
,
Request
$request
)
{
$this
->
sfapi
=
$sfapi
;
$this
->
etm
=
$entity_type_manager
;
$this
->
mapping
_s
torage
=
$this
->
etm
->
getStorage
(
'salesforce_mapping'
);
$this
->
mapped
_o
bject
_s
torage
=
$this
->
etm
->
getStorage
(
'salesforce_mapped_object'
);
$this
->
mapping
S
torage
=
$this
->
etm
->
getStorage
(
'salesforce_mapping'
);
$this
->
mapped
O
bject
S
torage
=
$this
->
etm
->
getStorage
(
'salesforce_mapped_object'
);
$this
->
state
=
$state
;
$this
->
logger
=
$logger
;
$this
->
request
=
$request
;
}
/**
* Chainable instantiation method for class
* Chainable instantiation method for class
.
*
* @param \Drupal\salesforce\Rest\RestClient $sfapi
* RestClient object
* @param \Drupal\Core\Entity\EntityTyp
r
ManagerInterface
$
$entity_type_manager
* Entity Manager service
* @param \Drupal\Core\State\StatInterface $state
* State service
*
RestClient object
.
* @param \Drupal\Core\Entity\EntityTyp
e
ManagerInterface $entity_type_manager
*
Entity Manager service
.
* @param \Drupal\Core\State\Stat
e
Interface $state
*
State service
.
* @param Psr\Log\LoggerInterface $logger
* Logging service
*
Logging service
.
*/
public
static
function
create
(
RestClient
$sfapi
,
EntityTypeManagerInterface
$entity_type_manager
,
StateInterface
$state
,
LoggerInterface
$logger
,
Request
$request
)
{
return
new
DeleteHandler
(
$sfapi
,
$entity_type_manager
,
$state
,
$logger
,
$request
);
...
...
@@ -98,11 +110,12 @@ class DeleteHandler {
/**
* Process deleted records from salesforce.
*
* @return boolean
* @return bool
* TRUE.
*/
public
function
processDeletedRecords
()
{
// @TODO Add back in SOAP, and use autoloading techniques
foreach
(
array_reverse
(
$this
->
mapping
_s
torage
->
getMappedSobjectTypes
())
as
$type
)
{
foreach
(
array_reverse
(
$this
->
mapping
S
torage
->
getMappedSobjectTypes
())
as
$type
)
{
$last_delete_sync
=
$this
->
state
->
get
(
'salesforce_pull_last_delete_'
.
$type
,
strtotime
(
'-29 days'
));
$now
=
time
();
// getDeleted() restraint: startDate must be at least one minute
...
...
@@ -114,20 +127,23 @@ class DeleteHandler {
$this
->
handleDeletedRecords
(
$deleted
,
$type
);
$this
->
state
->
set
(
'salesforce_pull_last_delete_'
.
$type
,
$now
);
}
return
true
;
return
TRUE
;
}
/**
* [handleDeletedRecords description]
* @param array $deleted
* @param string $type
* Delete records.
*
* @param array $deleted
* Array of deleted records.
* @param string $type
* Salesforce object type.
*/
protected
function
handleDeletedRecords
(
array
$deleted
,
$type
)
{
if
(
empty
(
$deleted
[
'deletedRecords'
]))
{
return
;
}
$sf_mappings
=
$this
->
mapping
_s
torage
->
loadByProperties
(
$sf_mappings
=
$this
->
mapping
S
torage
->
loadByProperties
(
[
'salesforce_object_type'
=>
$type
]
);
if
(
empty
(
$sf_mappings
))
{
...
...
@@ -140,13 +156,15 @@ class DeleteHandler {
}
/**
* [handleDeletedRecord description]
* @param [type] $record [description]
* @param [type] $type [description]
* @return [type] [description]
* Delete single mapped object.
*
* @param array $record
* Record array.
* @param string $type
* Salesforce object type.
*/
protected
function
handleDeletedRecord
(
$record
,
$type
)
{
$mapped_objects
=
$this
->
mapped
_o
bject
_s
torage
->
loadBySfid
(
new
SFID
(
$record
[
'id'
]));
protected
function
handleDeletedRecord
(
array
$record
,
$type
)
{
$mapped_objects
=
$this
->
mapped
O
bject
S
torage
->
loadBySfid
(
new
SFID
(
$record
[
'id'
]));
if
(
empty
(
$mapped_objects
))
{
return
;
}
...
...
@@ -167,7 +185,8 @@ class DeleteHandler {
}
}
// The mapping entity is an Entity reference field on mapped object, so we need to get the id value this way.
// The mapping entity is an Entity reference field on mapped object, so we
// need to get the id value this way.
$sf_mapping
=
$mapped_object
->
getMapping
();
if
(
!
$sf_mapping
)
{
$this
->
logger
->
log
(
...
...
@@ -208,10 +227,12 @@ class DeleteHandler {
'%type: @message in %function (line %line of %file).'
,
Error
::
decodeException
(
$e
)
);
// If mapped entity couldn't be deleted, do not delete the mapped object either.
// If mapped entity couldn't be deleted, do not delete the mapped object
// either.
return
;
}
$mapped_object
->
delete
();
}
}
This diff is collapsed.
Click to expand it.
modules/salesforce_pull/src/Plugin/QueueWorker/CronPull.php
+
1
−
0
View file @
c8049009
...
...
@@ -4,6 +4,7 @@ namespace Drupal\salesforce_pull\Plugin\QueueWorker;
/**
* A Salesforce record puller that pulls on CRON run.
*
* @TODO how to make cron time configurable to admin, or at least via settings?
*
* @QueueWorker(
...
...
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