Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Synchronize/update all accounts and products #515

Open
Megabits-es opened this issue Feb 10, 2023 · 1 comment
Open

Synchronize/update all accounts and products #515

Megabits-es opened this issue Feb 10, 2023 · 1 comment
Labels
enhancement New feature or request fix needs review A fix is in and it needs further testing

Comments

@Megabits-es
Copy link

The first thing is that I would like to thank you for the enormous work you are doing, thank you very much.

I've been studying your code and I've developed a few lines of code that allow you to sync or update all accounts and/or products from Salesforce to Wordpress, a Salesforce bulk sync.

@Megabits-es
Copy link
Author

Megabits-es commented Feb 10, 2023

function mgb_salesforce_query($mgb_query) {
	$option_token = get_option('object_sync_for_salesforce_access_token');
	$curl = curl_init();
	curl_setopt_array($curl, array(
	  CURLOPT_URL => $mgb_query,
	  CURLOPT_RETURNTRANSFER => true,
	  CURLOPT_ENCODING => '',
	  CURLOPT_MAXREDIRS => 10,
	  CURLOPT_TIMEOUT => 0,
	  CURLOPT_FOLLOWLOCATION => true,
	  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	  CURLOPT_CUSTOMREQUEST => 'GET',
	  CURLOPT_HTTPHEADER => array('Authorization: Bearer '.$option_token),
	));
	$response = curl_exec($curl);
	curl_close($curl);
	$response = json_decode($response, true);
	return $response;
}
add_options_page( 'Salesforce bulk', 'Salesforce bulk', 'manage_options', 'salesforce_bulk', 'mgb_salesforce_bulk_admin_page' );
function mgb_salesforce_bulk_admin_page() {
	?>
	<div class="wrap">
	<h1><?php echo esc_html( get_admin_page_title() );?></h1>
	<h3>Carga/Actualiza todos los usuarios o productos de Salesforce.</h3></br>
	<form action="" method="post">
		<input type="submit" name="bulk_users" value="Cargar/Actualizar todos los usuarios">
		<input type="submit" name="bulk_products" value="Cargar/Actualizar todos los productos">
	</form>
	</div>
	<?php	
	if ( ($_POST['bulk_users']) || ($_POST['bulk_products']) ) {
		if ($_POST['bulk_users']) $object_type = 'Account';
		if ($_POST['bulk_products']) $object_type = 'Product2';
		$fields_query = "Id,Name";
                $your_salesforce= "your_salesforce";
		$mgb_query = "https://".$your_salesforce.".my.salesforce.com/services/data/v56.0/query?q=SELECT+".$fields_query."+FROM+".$object_type;
		$response = mgb_salesforce_query($mgb_query);

		header("X-Accel-Buffering: no");
		ob_end_flush();
		foreach ($response['records'] as $key => $value) {
			echo esc_html($value['Name']).' - '.esc_html($value['Id']).'<br/>';
			ob_flush();
			flush();
			sleep(2);
			if ( class_exists( 'Object_Sync_Sf_Salesforce_Pull' ) ) {
			$mgb_pull_from_salesforce = new Object_Sync_Sf_Salesforce_Pull;
			$mgb_pull_from_salesforce->manual_pull($object_type, $value['Id']);
			}
		}
		ob_clean();
	}
}

@jonathanstegall jonathanstegall added enhancement New feature or request fix needs review A fix is in and it needs further testing labels Jan 27, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request fix needs review A fix is in and it needs further testing
Projects
None yet
Development

No branches or pull requests

1 participant