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
26a76634
Commit
26a76634
authored
8 years ago
by
Aaron Bauman
Browse files
Options
Downloads
Patches
Plain Diff
restore caching on record type id query and return SFID object
parent
6a159943
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Rest/RestClient.php
+26
-20
26 additions, 20 deletions
src/Rest/RestClient.php
with
26 additions
and
20 deletions
src/Rest/RestClient.php
+
26
−
20
View file @
26a76634
...
...
@@ -37,6 +37,8 @@ class RestClient {
private
$configEditable
;
private
$state
;
const
CACHE_LIFETIME
=
300
;
/**
* Constructor which initializes the consumer.
* @param \Drupal\Core\Http\Client $http_client
...
...
@@ -436,7 +438,7 @@ class RestClient {
$cache
=
\Drupal
::
cache
()
->
get
(
'salesforce:objects'
);
// Force the recreation of the cache when it is older than 5 minutes.
if
(
$cache
&&
REQUEST_TIME
<
(
$cache
->
created
+
300
)
&&
!
$reset
)
{
if
(
$cache
&&
REQUEST_TIME
<
(
$cache
->
created
+
self
::
CACHE_LIFETIME
)
&&
!
$reset
)
{
$result
=
$cache
->
data
;
}
else
{
...
...
@@ -492,7 +494,7 @@ class RestClient {
$cache
=
\Drupal
::
cache
()
->
get
(
'salesforce:object:'
.
$name
);
// Force the recreation of the cache when it is older than 5 minutes.
if
(
$cache
&&
REQUEST_TIME
<
(
$cache
->
created
+
300
)
&&
!
$reset
)
{
if
(
$cache
&&
REQUEST_TIME
<
(
$cache
->
created
+
self
::
CACHE_LIFETIME
)
&&
!
$reset
)
{
return
$cache
->
data
;
}
else
{
...
...
@@ -695,29 +697,33 @@ class RestClient {
* @param string $devname
* RecordType DeveloperName, e.g. Donation, Membership, etc.
*
* @return
string
SFID
* @return SFID
* The Salesforce ID of the given Record Type, or null.
*
* @throws Exception if record type not found
*/
public
function
getRecordTypeIdByDeveloperName
(
$name
,
$devname
,
$reset
=
FALSE
)
{
// @TODO: r
es
t
or
e caching
// $cache = cache_get('salesforce_record_types');
$cache
=
\Drupal
::
cache
()
->
get
(
'sal
es
f
or
ce:record_types'
);
// Force the recreation of the cache when it is older than 5 minutes.
// if ($cache && REQUEST_TIME < ($cache->created + 300) && !$reset) {
// return !empty($cache->data[$name][$devname])
// ? $cache->data[$name][$devname]['Id']
// : NULL;
// }
$query
=
new
SalesforceSelectQuery
(
'RecordType'
);
$query
->
fields
=
array
(
'Id'
,
'Name'
,
'DeveloperName'
,
'SobjectType'
);
$result
=
$this
->
query
(
$query
);
$record_types
=
array
();
foreach
(
$result
[
'records'
]
as
$rt
)
{
$record_types
[
$rt
[
'SobjectType'
]][
$rt
[
'DeveloperName'
]]
=
$rt
;
if
(
$cache
&&
REQUEST_TIME
<
(
$cache
->
created
+
self
::
CACHE_LIFETIME
)
&&
!
$reset
)
{
$record_types
=
$cache
->
data
;
}
else
{
$query
=
new
SalesforceSelectQuery
(
'RecordType'
);
$query
->
fields
=
array
(
'Id'
,
'Name'
,
'DeveloperName'
,
'SobjectType'
);
$result
=
$this
->
query
(
$query
);
$record_types
=
array
();
foreach
(
$result
[
'records'
]
as
$rt
)
{
$record_types
[
$rt
[
'SobjectType'
]][
$rt
[
'DeveloperName'
]]
=
$rt
;
}
\Drupal
::
cache
()
->
set
(
'salesforce:record_types'
,
$record_types
,
0
,
[
'salesforce'
]);
}
if
(
empty
(
$record_types
[
$name
][
$devname
][
'Id'
]))
{
throw
new
Exception
(
"No record type
$devname
for
$name
"
);
}
// cache_set('salesforce_record_types', $record_types, 'cache', CACHE_TEMPORARY);
return
!
empty
(
$record_types
[
$name
][
$devname
])
?
$record_types
[
$name
][
$devname
][
'Id'
]
:
NULL
;
return
new
SFID
(
$record_types
[
$name
][
$devname
][
'Id'
]);
}
/**
...
...
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