Object_Sync_Sf_Salesforce_Pull
Object_Sync_Sf_Salesforce_Pull class.
Table of Contents
- $debug : string
- Whether the plugin is in debug mode
- $file : string
- The main plugin file
- $logging : object
- Object_Sync_Sf_Logging class
- $login_credentials : array<string|int, mixed>
- Login credentials for the Salesforce API; comes from wp-config or from the plugin settings
- $mappings : object
- Object_Sync_Sf_Mapping class
- $mergeable_record_types : array<string|int, mixed>
- Types of Salesforce records that can be merged
- $option_prefix : string
- The plugin's prefix when saving options to the database
- $pull_options : object
- Object_Sync_Sf_Pull_Options class
- $queue : object
- Object_Sync_Sf_Queue class
- $salesforce : array<string|int, mixed>
- Object_Sync_Sf_Salesforce class This contains Salesforce API methods
- $schedulable_classes : array<string|int, mixed>
- Array of what classes in the plugin can be scheduled to occur with `wp_cron` events
- $schedule_name : string
- The name of the ActionScheduler queue
- $slug : string
- The plugin's slug so we can include it when necessary
- $sync_transients : object
- Object_Sync_Sf_Sync_Transients class
- $version : string
- Current version of the plugin
- $wordpress : object
- Object_Sync_Sf_WordPress class
- $wpdb : object
- Global object of `$wpdb`, the WordPress database
- $batch_soql_queries : bool
- Whether to batch SOQL queries
- $max_soql_size : int
- Maximum size of a SOQL batch
- $min_soql_batch_size : int
- Minimum size of a SOQL batch
- __construct() : mixed
- Constructor for pull class
- add_actions() : mixed
- Create the action hooks based on what object maps exist from the admin settings route is http://example.com/wp-json/salesforce-rest-api/pull/ plus params we decide to accept.
- clear_current_type_query() : mixed
- Clear the currently stored query for the specified content type
- deprecated_actions() : mixed
- Deprecated actions
- deprecated_pull_option_names() : mixed
- Modify legacy named individual option records for sync operations
- manual_pull() : array<string|int, mixed>
- Method for ajax hooks to call for pulling manually
- salesforce_pull() : mixed
- Callback for the standard pull process used by webhooks and cron.
- salesforce_pull_process_records() : bool
- Sync WordPress objects and Salesforce objects from the queue using the REST API.
- salesforce_pull_webhook() : array<string|int, mixed>
- REST API callback for salesforce pull. Returns status of 200 for successful attempt or 403 for a failed pull attempt (SF not authorized, threshhold reached, etc.
- batch_soql_queries() : bool
- Whether to use the batchSize parameter on SOQL queries
- check_offset_query() : object|bool
- Get the next offset query. If check is true, only see if that query would have results. Otherwise, return the SOQL object.
- check_throttle() : bool
- Determines if the Salesforce pull should be allowed, or throttled.
- create_called_from_salesforce() : array<string|int, mixed>
- Create records in WordPress from a Salesforce pull
- create_object_map() : int
- Create an object map between a Salesforce object and a WordPress object
- delete_called_from_salesforce() : array<string|int, mixed>
- Delete records in WordPress from a Salesforce pull
- get_deleted_records() : mixed
- Get deleted records from salesforce.
- get_merged_records() : mixed
- Get merged records from Salesforce.
- get_next_record_batch() : mixed
- Pull the next batch of records from the Salesforce API, if applicable Executes a nextRecordsUrl SOQL query based on the previous result, and places each updated SF object into the queue for later processing.
- get_pull_date_value() : timestamp
- Given a SObject type name, determine the datetime value the SOQL object should use to filter results. Often this will be LastModifiedDate.
- get_pull_offset() : mixed
- Determine the offset for the SOQL query to run
- get_pull_query() : Object_Sync_Sf_Salesforce_Select_Query
- Given a SObject type name, build an SOQL query to include all fields for all fieldmaps mapped to that SObject.
- get_synced_object() : array<string|int, mixed>
- Generate the synced_object array
- get_updated_records() : mixed
- Pull updated records from Salesforce and place them in the queue.
- increment_current_type_datetime() : mixed
- Increment the currently running query's datetime
- is_pull_allowed() : bool
- Find out if pull is allowed for this record
- respond_to_salesforce_merge() : mixed
- Respond to Salesforce merge events This means we update the mapping object to contain the new Salesforce Id, and pull its data
- update_called_from_salesforce() : array<string|int, mixed>
- Update records in WordPress from a Salesforce pull
Properties
$debug
Whether the plugin is in debug mode
public
string
$debug
$file
The main plugin file
public
string
$file
$logging
Object_Sync_Sf_Logging class
public
object
$logging
$login_credentials
Login credentials for the Salesforce API; comes from wp-config or from the plugin settings
public
array<string|int, mixed>
$login_credentials
$mappings
Object_Sync_Sf_Mapping class
public
object
$mappings
$mergeable_record_types
Types of Salesforce records that can be merged
public
array<string|int, mixed>
$mergeable_record_types
$option_prefix
The plugin's prefix when saving options to the database
public
string
$option_prefix
$pull_options
Object_Sync_Sf_Pull_Options class
public
object
$pull_options
$queue
Object_Sync_Sf_Queue class
public
object
$queue
$salesforce
Object_Sync_Sf_Salesforce class This contains Salesforce API methods
public
array<string|int, mixed>
$salesforce
$schedulable_classes
Array of what classes in the plugin can be scheduled to occur with `wp_cron` events
public
array<string|int, mixed>
$schedulable_classes
$schedule_name
The name of the ActionScheduler queue
public
string
$schedule_name
$slug
The plugin's slug so we can include it when necessary
public
string
$slug
$sync_transients
Object_Sync_Sf_Sync_Transients class
public
object
$sync_transients
$version
Current version of the plugin
public
string
$version
$wordpress
Object_Sync_Sf_WordPress class
public
object
$wordpress
$wpdb
Global object of `$wpdb`, the WordPress database
public
object
$wpdb
$batch_soql_queries
Whether to batch SOQL queries
private
bool
$batch_soql_queries
$max_soql_size
Maximum size of a SOQL batch
private
int
$max_soql_size
$min_soql_batch_size
Minimum size of a SOQL batch
private
int
$min_soql_batch_size
Methods
__construct()
Constructor for pull class
public
__construct() : mixed
Return values
mixed —add_actions()
Create the action hooks based on what object maps exist from the admin settings route is http://example.com/wp-json/salesforce-rest-api/pull/ plus params we decide to accept.
public
add_actions() : mixed
Return values
mixed —clear_current_type_query()
Clear the currently stored query for the specified content type
public
clear_current_type_query(string $type[, int $fieldmap_id = '' ]) : mixed
Parameters
- $type : string
-
e.g. "Contact", "Account", etc.
- $fieldmap_id : int = ''
-
is the fieldmap ID that goes with this query.
Return values
mixed —deprecated_actions()
Deprecated actions
public
deprecated_actions() : mixed
Return values
mixed —deprecated_pull_option_names()
Modify legacy named individual option records for sync operations
public
deprecated_pull_option_names(string $key, array<string|int, mixed> $params) : mixed
Parameters
- $key : string
-
the plugin's suggested key name.
- $params : array<string|int, mixed>
-
the array of parameters to make the key.
Tags
Return values
mixed —$value the value of the item. False if it's empty.
manual_pull()
Method for ajax hooks to call for pulling manually
public
manual_pull(string $object_type[, string $salesforce_id = '' ]) : array<string|int, mixed>
Parameters
- $object_type : string
-
the Salesforce object type.
- $salesforce_id : string = ''
-
the Salesforce record ID.
Return values
array<string|int, mixed> —$result
salesforce_pull()
Callback for the standard pull process used by webhooks and cron.
public
salesforce_pull() : mixed
Return values
mixed —salesforce_pull_process_records()
Sync WordPress objects and Salesforce objects from the queue using the REST API.
public
salesforce_pull_process_records(string $object_type, array<string|int, mixed>|string $object, int $sf_sync_trigger) : bool
Parameters
- $object_type : string
-
Type of Salesforce object.
- $object : array<string|int, mixed>|string
-
The Salesforce data or its Id value.
- $sf_sync_trigger : int
-
Trigger for this sync.
Tags
Return values
bool —true or exit the method
salesforce_pull_webhook()
REST API callback for salesforce pull. Returns status of 200 for successful attempt or 403 for a failed pull attempt (SF not authorized, threshhold reached, etc.
public
salesforce_pull_webhook(WP_REST_Request $request) : array<string|int, mixed>
Parameters
- $request : WP_REST_Request
-
This is a merged object of all the arguments from the API request.
Return values
array<string|int, mixed> —code: 201 data: success : true
batch_soql_queries()
Whether to use the batchSize parameter on SOQL queries
private
batch_soql_queries(bool $batch_soql_queries) : bool
Parameters
- $batch_soql_queries : bool
-
whether to batch the queries.
Return values
bool —$batch_soql_queries
check_offset_query()
Get the next offset query. If check is true, only see if that query would have results. Otherwise, return the SOQL object.
private
check_offset_query(string $type, array<string|int, mixed> $salesforce_mapping, array<string|int, mixed> $query_options) : object|bool
When batchSize is not in use, run a check with an offset.
Parameters
- $type : string
-
the Salesforce object type.
- $salesforce_mapping : array<string|int, mixed>
-
the map between object types.
- $query_options : array<string|int, mixed>
-
the options for the SOQL query.
Return values
object|bool —$soql|$does_next_offset_have_results
check_throttle()
Determines if the Salesforce pull should be allowed, or throttled.
private
check_throttle() : bool
Prevents too many pull processes from running at once.
Return values
bool —Returns false if the time elapsed between recent pulls is too short.
create_called_from_salesforce()
Create records in WordPress from a Salesforce pull
private
create_called_from_salesforce(string $sf_sync_trigger, array<string|int, mixed> $synced_object, array<string|int, mixed> $params, array<string|int, mixed> $prematch, string $wordpress_id_field_name, int $seconds) : array<string|int, mixed>
Parameters
- $sf_sync_trigger : string
-
The current operation's trigger.
- $synced_object : array<string|int, mixed>
-
Combined data for fieldmap, mapping object, and Salesforce object data.
- $params : array<string|int, mixed>
-
Array of mapped key value pairs between WordPress and Salesforce fields.
- $prematch : array<string|int, mixed>
-
Array of criteria to determine what to do on upsert operations.
- $wordpress_id_field_name : string
-
The name of the ID field for this particular WordPress object type.
- $seconds : int
-
Timeout for the transient value to determine the direction for a sync.
Tags
Return values
array<string|int, mixed> —$results Currently this contains an array of log entries for each attempt.
create_object_map()
Create an object map between a Salesforce object and a WordPress object
private
create_object_map(array<string|int, mixed> $salesforce_object, string $wordpress_id, array<string|int, mixed> $field_mapping) : int
Parameters
- $salesforce_object : array<string|int, mixed>
-
Array of the salesforce object's data.
- $wordpress_id : string
-
Unique identifier for the WordPress object.
- $field_mapping : array<string|int, mixed>
-
The row that maps the object types together, including which fields match which other fields.
Return values
int —$wpdb->insert_id This is the database row for the map object
delete_called_from_salesforce()
Delete records in WordPress from a Salesforce pull
private
delete_called_from_salesforce(string $sf_sync_trigger, array<string|int, mixed> $synced_object, string $wordpress_id_field_name, int $seconds, array<string|int, mixed> $mapping_objects) : array<string|int, mixed>
Parameters
- $sf_sync_trigger : string
-
The current operation's trigger.
- $synced_object : array<string|int, mixed>
-
Combined data for fieldmap, mapping object, and Salesforce object data.
- $wordpress_id_field_name : string
-
The name of the ID field for this particular WordPress object type.
- $seconds : int
-
Timeout for the transient value to determine the direction for a sync.
- $mapping_objects : array<string|int, mixed>
-
The data for the mapping objects between the individual Salesforce and WordPress items. We only pass this because of the need to count before deleting records.
Tags
Return values
array<string|int, mixed> —$results Currently this contains an array of log entries for each attempt.
get_deleted_records()
Get deleted records from salesforce.
private
get_deleted_records() : mixed
Note that deletions can only be queried via REST with an API version >= 29.0.
Return values
mixed —get_merged_records()
Get merged records from Salesforce.
private
get_merged_records() : mixed
Note that merges can currently only work if the Soap API is enabled.
Return values
mixed —get_next_record_batch()
Pull the next batch of records from the Salesforce API, if applicable Executes a nextRecordsUrl SOQL query based on the previous result, and places each updated SF object into the queue for later processing.
private
get_next_record_batch(datetime $last_sync, array<string|int, mixed> $salesforce_mapping, array<string|int, mixed> $map_sync_triggers, string $type, string $version_path, array<string|int, mixed> $query_options, array<string|int, mixed> $response) : mixed
Parameters
- $last_sync : datetime
-
when it was last synced.
- $salesforce_mapping : array<string|int, mixed>
-
the fieldmap.
- $map_sync_triggers : array<string|int, mixed>
-
the sync trigger bit values.
- $type : string
-
the Salesforce object type.
- $version_path : string
-
the API path for the Salesforce version.
- $query_options : array<string|int, mixed>
-
the SOQL query options.
- $response : array<string|int, mixed>
-
the previous response.
Return values
mixed —get_pull_date_value()
Given a SObject type name, determine the datetime value the SOQL object should use to filter results. Often this will be LastModifiedDate.
private
get_pull_date_value(string $type, object $soql[, int $fieldmap_id = '' ]) : timestamp
Parameters
- $type : string
-
e.g. "Contact", "Account", etc.
- $soql : object
-
the SOQL object.
- $fieldmap_id : int = ''
-
is the fieldmap ID that goes with this query.
Return values
timestamp —$pull_trigger_field_value
get_pull_offset()
Determine the offset for the SOQL query to run
private
get_pull_offset(string $type, object $soql[, bool $reset = false ]) : mixed
Parameters
- $type : string
-
e.g. "Contact", "Account", etc.
- $soql : object
-
the SOQL object.
- $reset : bool = false
-
whether to reset the offset.
Return values
mixed —get_pull_query()
Given a SObject type name, build an SOQL query to include all fields for all fieldmaps mapped to that SObject.
private
get_pull_query(string $type[, array<string|int, mixed> $salesforce_mapping = array() ]) : Object_Sync_Sf_Salesforce_Select_Query
Parameters
- $type : string
-
e.g. "Contact", "Account", etc.
- $salesforce_mapping : array<string|int, mixed> = array()
-
the fieldmap that maps the two object types.
Tags
Return values
Object_Sync_Sf_Salesforce_Select_Query —or null if no mappings or no mapped fields were found.
get_synced_object()
Generate the synced_object array
private
get_synced_object(array<string|int, mixed> $object, array<string|int, mixed> $mapping_object, array<string|int, mixed> $salesforce_mapping) : array<string|int, mixed>
Parameters
- $object : array<string|int, mixed>
-
The data for the Salesforce object.
- $mapping_object : array<string|int, mixed>
-
The data for the mapping object between the individual Salesforce and WordPress items.
- $salesforce_mapping : array<string|int, mixed>
-
The data for the fieldmap between the object types.
Return values
array<string|int, mixed> —$synced_object The combined array of these items. It allows for filtering of, at least, the mapping_object.
get_updated_records()
Pull updated records from Salesforce and place them in the queue.
private
get_updated_records() : mixed
Executes a SOQL query based on defined mappings, loops through the results, and places each updated SF object into the queue for later processing. We copy the convention from the Drupal module here, and run a separate SOQL query for each type of object in SF If we return something here, it's because there is an error.
Return values
mixed —increment_current_type_datetime()
Increment the currently running query's datetime
private
increment_current_type_datetime(string $type[, timestamp $next_query_modified_date = '' ][, int $fieldmap_id = '' ]) : mixed
Parameters
- $type : string
-
e.g. "Contact", "Account", etc.
- $next_query_modified_date : timestamp = ''
-
the last record's modified datetime, or the current time if there isn't one.
- $fieldmap_id : int = ''
-
is the fieldmap ID that goes with this query.
Return values
mixed —is_pull_allowed()
Find out if pull is allowed for this record
private
is_pull_allowed(string $object_type, array<string|int, mixed> $object, string $sf_sync_trigger, array<string|int, mixed> $salesforce_mapping, array<string|int, mixed> $map_sync_triggers) : bool
Parameters
- $object_type : string
-
Salesforce object type.
- $object : array<string|int, mixed>
-
Array of the salesforce object's data.
- $sf_sync_trigger : string
-
The current operation's trigger.
- $salesforce_mapping : array<string|int, mixed>
-
the fieldmap that maps the two object types.
- $map_sync_triggers : array<string|int, mixed>
-
the triggers that are enabled.
Return values
bool —$pull_allowed Whether all this stuff allows the $result to be pulled into WordPress
respond_to_salesforce_merge()
Respond to Salesforce merge events This means we update the mapping object to contain the new Salesforce Id, and pull its data
private
respond_to_salesforce_merge(string $object_type, array<string|int, mixed> $merged_record) : mixed
Parameters
- $object_type : string
-
what type of Salesforce object it is.
- $merged_record : array<string|int, mixed>
-
the record that was merged.
Return values
mixed —update_called_from_salesforce()
Update records in WordPress from a Salesforce pull
private
update_called_from_salesforce(string $sf_sync_trigger, array<string|int, mixed> $synced_object, array<string|int, mixed> $params, string $wordpress_id_field_name, int $seconds) : array<string|int, mixed>
Parameters
- $sf_sync_trigger : string
-
The current operation's trigger.
- $synced_object : array<string|int, mixed>
-
Combined data for fieldmap, mapping object, and Salesforce object data.
- $params : array<string|int, mixed>
-
Array of mapped key value pairs between WordPress and Salesforce fields.
- $wordpress_id_field_name : string
-
The name of the ID field for this particular WordPress object type.
- $seconds : int
-
Timeout for the transient value to determine the direction for a sync.
Tags
Return values
array<string|int, mixed> —$results Currently this contains an array of log entries for each attempt.