function acquia_contenthub_subscriber_put_filter in Acquia Content Hub 8.2
Saves a Cloud Filter in Content Hub.
Parameters
array $contenthub_filter: The Cloud Filter ready to be saved.
Return value
array|bool The migrated Cloud Filter or FALSE.
1 call to acquia_contenthub_subscriber_put_filter()
- AcquiaContentHubSubscriberCommands::upgrade in modules/
acquia_contenthub_subscriber/ src/ Commands/ AcquiaContentHubSubscriberCommands.php - Subscriber Upgrade Command.
File
- modules/
acquia_contenthub_subscriber/ acquia_contenthub_subscriber.filters.migrate.inc, line 173 - Defines filter migrations from 1.x to 2.x.
Code
function acquia_contenthub_subscriber_put_filter(array $contenthub_filter) {
$logger = \Drupal::logger('acquia_contenthub_subscriber');
/** @var \Drupal\acquia_contenthub\Client\ClientFactory $factory */
$factory = \Drupal::service("acquia_contenthub.client.factory");
$settings = $factory
->getSettings();
if ($client = $factory
->getClient($settings)) {
try {
$filters = $client
->listFilters();
$plexus_filter = _acquia_contenthub_subscriber_find_cloud_filter($contenthub_filter, $filters);
if (empty($plexus_filter)) {
$plexus_filter = $client
->putFilter($contenthub_filter['data']['query'], $contenthub_filter['name'], NULL, $contenthub_filter['metadata']);
$logger
->info(sprintf('Created cloud filter "%s"', $contenthub_filter['name']));
}
if (empty($plexus_filter['uuid'])) {
$logger
->error(sprintf('Could not migrate Filter "%s".', $contenthub_filter['name']));
return FALSE;
}
// Assign Filter to Webhook.
$webhook = \Drupal::configFactory()
->get('acquia_contenthub.admin_settings')
->get('webhook');
$webhook_uuid = $webhook['uuid'] ?? NULL;
if (Uuid::isValid($webhook_uuid)) {
$response = $client
->addFilterToWebhook($plexus_filter['uuid'], $webhook_uuid);
if (!empty($response['success'])) {
$logger
->info(sprintf('Successfully attached Cloud filter "%s" to this webhook.', $contenthub_filter['name']));
return $plexus_filter;
}
}
} catch (\Exception $ex) {
$logger
->error(sprintf('Could not migrate Filter "%s": Error message: %s.', $contenthub_filter['name'], $ex
->getMessage()));
}
}
return FALSE;
}