salesforce_pull.install in Salesforce Suite 8.4
Same filename and directory in other branches
Install/uninstall tasks for the Salesforce Pull module.
File
modules/salesforce_pull/salesforce_pull.installView source
<?php
/**
* @file
* Install/uninstall tasks for the Salesforce Pull module.
*/
/**
* Implements hook_uninstall().
*/
function salesforce_pull_uninstall() {
$delete = [
'salesforce.mapping_pull_info',
];
\Drupal::state()
->deleteMultiple($delete);
}
/**
* Convert per-object pull timestamp key-values into one big array.
*/
function salesforce_pull_update_8002() {
$pull_info = [];
$delete = [];
$objects = \Drupal::service('salesforce.client')
->objects();
foreach ($objects as $type) {
$last_del = \Drupal::state()
->get('salesforce_pull_last_delete_' . $type);
$last_pull = \Drupal::state()
->get('salesforce_pull_last_sync_' . $type);
$delete[] = 'salesforce_pull_last_delete_' . $type;
$delete[] = 'salesforce_pull_last_sync_' . $type;
if (!empty($last_del)) {
$pull_info[$type]['last_delete_timestamp'] = $last_del;
}
if (!empty($last_pull)) {
$pull_info[$type]['last_pull_timestamp'] = $last_pull;
}
}
\Drupal::state()
->set('salesforce.sobject_pull_info', $pull_info);
\Drupal::state()
->deleteMultiple($delete);
}
/**
* Convert salesforce_pull_last* timestamps key-values into arrays.
*/
function salesforce_pull_update_8001() {
$kv = \Drupal::service('database')
->query("SELECT name, value FROM key_value WHERE name like 'salesforce_pull_last%'")
->fetchAllKeyed();
$sync = [];
$delete = [];
foreach ($kv as $key => $value) {
$value = unserialize($value);
if (strpos($key, 'delete')) {
$salesforce_type = str_replace('salesforce_pull_last_delete_', '', $key);
$delete[$salesforce_type] = $value;
}
elseif (strpos($key, 'sync')) {
$salesforce_type = str_replace('salesforce_pull_last_sync_', '', $key);
$sync[$salesforce_type] = $value;
}
}
\Drupal::state()
->set('salesforce_pull_last_delete', $delete);
\Drupal::state()
->set('salesforce_pull_last_sync', $sync);
\Drupal::state()
->deleteMultiple(array_keys($kv));
}
/**
* Moves global pull limit out of state into config.
*/
function salesforce_pull_update_8003() {
$config = \Drupal::configFactory()
->getEditable('salesforce.settings');
$config
->set('pull_max_queue_size', \Drupal::state()
->get('salesforce.pull_max_queue_size'))
->save();
\Drupal::state()
->delete('salesforce.pull_max_queue_size');
}
/**
* Refactor pull timestamps, again, into per-mapping timestamps.
*/
function salesforce_pull_update_8004() {
$mapping_pull_info = [];
$pull_info = \Drupal::state()
->get('salesforce.sobject_pull_info', []);
$mappings = \Drupal::entityTypeManager()
->getStorage('salesforce_mapping')
->loadMultiple();
$new_pull_info = [];
foreach ($mappings as $mapping) {
$sobject_type = $mapping
->getSalesforceObjectType();
if (empty($pull_info[$sobject_type])) {
continue;
}
$mapping_pull_info = $pull_info[$sobject_type];
$new_pull_info[$mapping
->id()] = $mapping_pull_info;
}
\Drupal::state()
->set('salesforce.mapping_pull_info', $mapping_pull_info);
\Drupal::state()
->delete('salesforce.sobject_pull_info');
}
/**
* Update mappings with "pull standalone" property.
*/
function salesforce_pull_update_8005() {
$mappings = \Drupal::entityTypeManager()
->getStorage('salesforce_mapping')
->loadPullMappings();
foreach ($mappings as $mapping) {
if (empty($mapping
->get('pull_standalone'))) {
$mapping
->set('pull_standalone', FALSE)
->save();
}
}
}
Functions
Name | Description |
---|---|
salesforce_pull_uninstall | Implements hook_uninstall(). |
salesforce_pull_update_8001 | Convert salesforce_pull_last* timestamps key-values into arrays. |
salesforce_pull_update_8002 | Convert per-object pull timestamp key-values into one big array. |
salesforce_pull_update_8003 | Moves global pull limit out of state into config. |
salesforce_pull_update_8004 | Refactor pull timestamps, again, into per-mapping timestamps. |
salesforce_pull_update_8005 | Update mappings with "pull standalone" property. |