public function SalesforceMappingCommands::pruneRevisions in Salesforce Suite 8.4
Same name and namespace in other branches
- 8.3 modules/salesforce_mapping/src/Commands/SalesforceMappingCommands.php \Drupal\salesforce_mapping\Commands\SalesforceMappingCommands::pruneRevisions()
- 5.0.x modules/salesforce_mapping/src/Commands/SalesforceMappingCommands.php \Drupal\salesforce_mapping\Commands\SalesforceMappingCommands::pruneRevisions()
Delete old revisions of Mapped Objects, based on revision limit settings.
Useful if you have recently changed settings, or if you have just updated to a version with prune support.
@command salesforce_mapping:prune-revisions @aliases sfprune,sf-prune-revisions
Parameters
int $limit: If $limit is not specified, salesforce.settings.limit_mapped_object_revisions is used.
Throws
\Drupal\Component\Plugin\Exception\PluginNotFoundException
File
- modules/
salesforce_mapping/ src/ Commands/ SalesforceMappingCommands.php, line 108
Class
- SalesforceMappingCommands
- A Drush commandfile.
Namespace
Drupal\salesforce_mapping\CommandsCode
public function pruneRevisions($limit) {
$revision_table = $this->etm
->getDefinition('salesforce_mapped_object')
->getRevisionTable();
$ids = $this->database
->select($revision_table, 'r')
->fields('r', [
'id',
])
->having('COUNT(r.id) > ' . $limit)
->groupBy('r.id')
->execute()
->fetchCol();
if (empty($ids)) {
$this
->logger()
->warning(dt("No Mapped Objects with more than !limit revision(s). No action taken.", [
'!limit' => $limit,
]));
return;
}
$this
->logger()
->info(dt('Found !count mapped objects with excessive revisions. Will prune to revision(s) each. This may take a while.', [
'!count' => count($ids),
'!limit' => $limit,
]));
$total = count($ids);
$i = 0;
$buckets = ceil($total / 20);
if ($buckets == 0) {
$buckets = 1;
}
foreach ($ids as $id) {
if ($i++ % $buckets == 0) {
$this
->logger()
->info(dt("Pruned !i of !total records.", [
'!i' => $i,
'!total' => $total,
]));
}
/** @var \Drupal\salesforce_mapping\Entity\MappedObject $mapped_object */
if ($mapped_object = $this->mappedObjectStorage
->load($id)) {
$mapped_object
->pruneRevisions($this->mappedObjectStorage);
}
}
}