File: /wordpress/plugins/wp-cloud-client/beta/src/Handler/SyncProfileHandler.php
<?php
declare(strict_types=1);
namespace VPlugins\WPCloudClient\Handler;
use VPlugins\WPCloudClient\Integration\DiviHelper;
use VPlugins\WPCloudClient\Integration\WooCommerceHelper;
final class SyncProfileHandler extends AbstractHandler {
/**
* Return the action name.
*
* @return string Action name.
*/
public function action(): string {
return 'sync_profile';
}
/**
* Sync a profile to active integrations.
*
* @param array<string, mixed> $params Action parameters.
* @return array<string, mixed> Sync results per integration.
*
* @throws \InvalidArgumentException If profile parameter is invalid.
*/
public function execute( array $params ): array {
$this->requireParams( $params, 'profile' );
$profile = $params['profile'];
if ( ! is_array( $profile ) || empty( $profile ) ) {
throw new \InvalidArgumentException( 'profile must be a non-empty object' );
}
$result = [];
$wcResult = WooCommerceHelper::syncProfile( $profile );
if ( null !== $wcResult ) {
$result['woocommerce'] = $wcResult;
}
$diviResult = DiviHelper::syncProfile( $profile );
if ( null !== $diviResult ) {
$result['divi'] = $diviResult;
}
if ( empty( $result ) ) {
$result['message'] = 'No active integrations found (WooCommerce or Divi required)';
}
return $result;
}
}