public function BynderService::updateLocalMetadataCron in Bynder 8.2
Same name and namespace in other branches
- 8.3 src/BynderService.php \Drupal\bynder\BynderService::updateLocalMetadataCron()
- 4.0.x src/BynderService.php \Drupal\bynder\BynderService::updateLocalMetadataCron()
Updates the cron metadata information of the local media entities.
Limits the number of processed items to BynderService::MAX_ITEMS.
Overrides BynderServiceInterface::updateLocalMetadataCron
File
- src/
BynderService.php, line 146
Class
- BynderService
- Bynder service.
Namespace
Drupal\bynderCode
public function updateLocalMetadataCron() {
// Get the update frequency value in seconds. In case it is empty or set to
// zero, do not do any updates.
$update_frequency = (int) $this->configFactory
->get('bynder.settings')
->get('update_frequency');
if ($update_frequency === 0) {
return;
}
// Only run updates if the last completed update was more than the
// configured amount of time ago.
$last_update = $this->state
->get(static::METADATA_UPDATE_TIMESTAMP_KEY);
$request_time = $this->time
->getRequestTime();
if ($last_update && $request_time - $last_update < $update_frequency) {
return;
}
$results = $this
->updateMetadataLastMediaEntities($this->state
->get(static::METADATA_UPDATE_ID_KEY));
// There are no Bynder media types, Bynder media entities to update or we
// are processing the latest chunk.
if (empty($results) || $results['total'] < static::MAX_ITEMS) {
$this->state
->set(static::METADATA_UPDATE_TIMESTAMP_KEY, $request_time);
$this->state
->delete(static::METADATA_UPDATE_ID_KEY);
return;
}
// Update the maximum update ID with a new maximum ID.
$this->state
->set(static::METADATA_UPDATE_ID_KEY, $results['max_id']);
}