Skip to content

Commit

Permalink
Merge pull request #44 from MichaelJ2324/2.0
Browse files Browse the repository at this point in the history
SUPP-1255, SUPP-1256
  • Loading branch information
crazytonyi committed Jul 15, 2019
2 parents 6dbd829 + 873ff5e commit 8ca8bde
Show file tree
Hide file tree
Showing 74 changed files with 766 additions and 230 deletions.
43 changes: 25 additions & 18 deletions examples/AuditLog.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
<?php
/**
* ©[2019] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
*/

require_once 'include.php';

$SugarAPI = new \Sugarcrm\REST\Client\Sugar7API($server,$credentials);
try{
$SugarAPI->login();
echo "Logged In: <pre>";
print_r($SugarAPI->getAuth()->getToken()->access_token);
echo "</pre>";
$Account = $SugarAPI->module('Accounts')->set("name","Audit Log Test");
$Account->save();
echo "<pre>Created Account: {$Account['id']}</pre><br>";
$Account->set('phone_office','555-555-5555');
$Account['name'] = 'Audit Log Test - Updated';
$Account['assigned_user_id'] = 'seed_max_id';
$Account->save();
echo "<pre> Account Updated: <br>".print_r($Account->asArray(),true)."</pre><br>";
$Account->audit();
echo "<pre> Audit Log:".print_r($Account->getResponse()->getBody(),true)."</pre><br>";
if ($SugarAPI->login()){
echo "Logged In: ";
pre($SugarAPI->getAuth()->getToken());
$Account = $SugarAPI->module('Accounts')->set("name","Audit Log Test");
$Account->save();
pre("Created Account: {$Account['id']}");
$Account->set('phone_office','555-555-5555');
$Account['name'] = 'Audit Log Test - Updated';
$Account['assigned_user_id'] = 'seed_max_id';
$Account->save();
echo "Account Updated:";
pre($Account->asArray());
$Account->audit();
echo "Audit Log: ";
pre($Account->getResponse()->getBody());
} else {
echo "Could not login.";
pre($SugarAPI->getAuth()->getActionEndpoint('authenticate')->getResponse());
}
}catch (Exception $ex){
echo "<pre>";
//print_r($SugarAPI);
echo "</pre>";
print $ex->getMessage();
echo "Error Occurred: ";
pre($ex->getMessage());
pre($ex->getTraceAsString());
}
52 changes: 31 additions & 21 deletions examples/CRUD.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
<?php
/**
* ©[2019] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
*/

require_once 'include.php';

$SugarAPI = new \Sugarcrm\REST\Client\Sugar7API($server,$credentials);
try{
$SugarAPI->login();
echo "<pre>";
print_r($SugarAPI->getAuth()->getToken()->access_token);
echo "</pre>";
$Account = $SugarAPI->module('Accounts')->set("name","Test")->set("phone_office","555-555-5555");
echo "<pre> Account:".print_r($Account->asArray(),true)."</pre><br>";
$Account->save();
echo "<pre> Saved Account ID: {$Account['id']}</pre><br>";
$Account->set('employees','100');
$Account['shipping_address_city'] = 'Indianapolis';
$Account->save();
echo "<pre> Account Updated: <br>".print_r($Account->asArray(),true)."</pre>";
$Account2 = $SugarAPI->module('Accounts',$Account['id']);
$Account2->retrieve();
echo "<pre> Account2:".print_r($Account2->asArray(),true)."</pre><br>";
$Account2->delete();
echo "Account Deleted. <br><pre>".print_r($Account2->getResponse(),true)."</pre>";
if ($SugarAPI->login()){
echo "Logged In: ";
pre($SugarAPI->getAuth()->getToken());
$Account = $SugarAPI->module('Accounts')->set("name","Test")->set("phone_office","555-555-5555");
echo "Creating Account: ";
pre($Account->asArray());
$Account->save();
pre("Saved Account ID: {$Account['id']}");
$Account->set('employees','100');
$Account['shipping_address_city'] = 'Indianapolis';
echo "Changing fields employees and shipping address...<br>";
$Account->save();
echo "Account Updated: ";
pre($Account->asArray());
$Account2 = $SugarAPI->module('Accounts',$Account['id']);
$Account2->retrieve();
echo "Retrieving the Account Again...<br>";
pre($Account2->asArray());
$Account2->delete();
echo "Account Deleted. Response: ";
pre($Account2->getResponse());
} else {
echo "Could not login.";
pre($SugarAPI->getAuth()->getActionEndpoint('authenticate')->getResponse());
}
}catch (Exception $ex){
echo "<pre>";
//print_r($SugarAPI);
echo "</pre>";
print $ex->getMessage();
echo "Error Occurred: ";
pre($ex->getMessage());
pre($ex->getTraceAsString());
}
30 changes: 30 additions & 0 deletions examples/DuplicateCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* ©[2019] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
*/

require_once 'include.php';

$SugarAPI = new \Sugarcrm\REST\Client\Sugar7API($server,$credentials);

try{
if ($SugarAPI->login()){
echo "Logged In: ";
pre($SugarAPI->getAuth()->getToken());
$Account = $SugarAPI->module('Accounts')->set("name","DuplicateCheck Test");
$Account->save();
pre("Account Created: {$Account['id']}");
$a = $Account->asArray();
unset($a['id']);
echo "Running duplicateCheck for Account: ";
pre($a);
$Account->duplicateCheck();
pre($Account->getResponse()->getBody());
} else {
echo "Could not login.";
pre($SugarAPI->getAuth()->getActionEndpoint('authenticate')->getResponse());
}
}catch (Exception $ex){
echo "Error Occurred: ";
pre($ex->getMessage());
}
31 changes: 18 additions & 13 deletions examples/Favorite.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
<?php
/**
* ©[2019] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
*/

require_once 'include.php';

$SugarAPI = new \Sugarcrm\REST\Client\Sugar7API($server,$credentials);

try{
$SugarAPI->login();
echo "Logged In: <pre>";
print_r($SugarAPI->getAuth()->getToken()->access_token);
echo "</pre>";
$Account = $SugarAPI->module('Accounts')->set("name","Favorite Test");
$Account->save();
echo "<pre> Account Created: {$Account['id']}</pre><br>";
$Account->favorite();
echo "<pre> Account added to Favorites: <br>".print_r($Account,true)."</pre>";
if ($SugarAPI->login()){
echo "Logged In: <pre>";
print_r($SugarAPI->getAuth()->getToken()->access_token);
echo "</pre>";
$Account = $SugarAPI->module('Accounts')->set("name","Favorite Test");
$Account->save();
echo "<pre> Account Created: {$Account['id']}</pre><br>";
$Account->favorite();
echo "<pre> Account added to Favorites: <br>".print_r($Account,true)."</pre>";
} else {
echo "Could not login.";
pre($SugarAPI->getAuth()->getActionEndpoint('authenticate')->getResponse());
}
}catch (Exception $ex){
echo "<pre>";
//print_r($SugarAPI);
echo "</pre>";
print $ex->getMessage();
echo "Error Occurred: ";
pre($ex->getMessage());
}
57 changes: 31 additions & 26 deletions examples/FileManipulation.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,39 @@
if (file_exists($file) && is_readable($file)) {
$SugarAPI = new \Sugarcrm\REST\Client\Sugar7API($server, $credentials);
try {
$SugarAPI->login();
echo "<pre>";
print_r($SugarAPI->getAuth()->getToken()->access_token);
echo "</pre>";
$Note = $SugarAPI->module('Notes')->set("name", "Test");
echo "<pre> Note:" . print_r($Note->asArray(), true) . "</pre><br>";
$Note->save();
echo "<pre> Saved Note ID: {$Note['id']}</pre><br>";
echo "Attempting to attach $file";
$Note->attachFile('filename', $file,TRUE,'text/plain','testtest.txt');
$response = $Note->getResponse()->getBody();
//echo "<pre>" . print_r($Note->getRequest(), true) . "</pre>";
echo "File uploaded: <pre>" . print_r($response,true) . "</pre>";
if ($SugarAPI->login()){
echo "Logged In: ";
pre($SugarAPI->getAuth()->getToken());
$Note = $SugarAPI->module('Notes')->set("name", "Test");
echo "Creating Note: ";
pre($Note->asArray());
$Note->save();
echo "Saved Note ID: {$Note['id']}<br>";
echo "Attempting to attach $file...";
$Note->attachFile('filename', $file,TRUE,'text/plain','testtest.txt');
$response = $Note->getResponse()->getBody();
//echo "<pre>" . print_r($Note->getRequest(), true) . "</pre>";
echo "File uploaded: ";
pre($response);

$Note = $SugarAPI->module('Notes');
$Note->tempFile('filename',$file);
$response = $Note->getResponse()->getBody();
echo "<pre>" . print_r($Note->getRequest(), true) . "</pre>";
echo "File uploaded: <pre>" . print_r($response,true) . "</pre>";
$Note->set('name','This is a test');
$Note->save();
echo "<pre> Note ID: {$Note['id']}</pre><br>";
echo "<pre>" . print_r($Note->getRequest(), true) . "</pre>";
$Note = $SugarAPI->module('Notes');
echo "Uploading temp file for new note...";
$Note->tempFile('filename',$file);
$response = $Note->getResponse()->getBody();
pre($Note->getRequest());
echo "File uploaded: ";
pre($response);
$Note->set('name','This is a test');
$Note->save();
echo "Note ID: {$Note['id']}<br>";
pre($Note->getRequest());
} else {
echo "Could not login.";
pre($SugarAPI->getAuth()->getActionEndpoint('authenticate')->getResponse());
}
} catch (Exception $ex) {
echo "<pre>";
//print_r($SugarAPI);
echo "</pre>";
print $ex->getMessage();
echo "Error Occurred: ";
pre($ex->getMessage());
}
} else {
if (!file_exists($file)){
Expand Down
64 changes: 45 additions & 19 deletions examples/FilterAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,50 @@

$SugarAPI = new \Sugarcrm\REST\Client\Sugar7API($server,$credentials);
try{
$SugarAPI->login();
echo "<pre>";
print_r($SugarAPI->getAuth()->getToken()->access_token);
echo "</pre>";
$Accounts = $SugarAPI->list('Accounts');
$Accounts->filter()->and()
->or()
->starts('name','s')
->contains('name','test')
->endOr()
->equals('assigned_user_id','seed_max_id')
->endAnd();
echo "<pre> Filter Accounts that are assigned to User Max, and that either start with an S or contain 'test' in the name: ".print_r($Accounts->filter()->compile(),true)."</pre><br>";
$Accounts->filter()->execute();
echo "<pre> Response:".print_r($Accounts->getResponse()->getBody(),true)."</pre><br>";
if ($SugarAPI->login()){
echo "Logged In: ";
pre($SugarAPI->getAuth()->getToken());
$Accounts = $SugarAPI->list('Accounts');
$Accounts->filter()->and()
->or()
->starts('name','s')
->contains('name','test')
->endOr()
->equals('assigned_user_id','seed_max_id')
->endAnd();
echo "Filtering Accounts that are assigned to User Max, and that either start with an S or contain 'test' in the name: ";
pre($Accounts->filter()->compile());
$Accounts->count();
echo "Running Count Request: ";
pre($Accounts->getResponse()->getBody());
echo "Running Filter Request: ";
$Accounts->filter()->execute();
echo "Request: ";
pre($Accounts->getRequest());
echo "Accounts: ";
pre($Accounts->asArray());
$Accounts->clear();
$Accounts->filter(true);
echo "Filtering Accounts that are created between dates, or in the last 7 days: ";
$Accounts->filter()->or()->date('date_entered')
->between(array("2019-01-01","2019-02-01"))
->endDate()
->date('date_entered')
->last7Days()
->endDate()
->endOr();
pre($Accounts->filter()->compile());
$Accounts->filter()->execute();
echo "Request: ";
pre($Accounts->getRequest());
echo "Accounts: ";
pre($Accounts->asArray());
} else {
echo "Could not login.";
pre($SugarAPI->getAuth()->getActionEndpoint('authenticate')->getResponse());
}
}catch (Exception $ex){
echo "<pre>";
//print_r($SugarAPI);
echo "</pre>";
print $ex->getMessage();
echo "Error Occurred: ";
pre($ex->getMessage());
pre($ex->getTraceAsString());
}
40 changes: 21 additions & 19 deletions examples/FilterRelated.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
<?php
/**
* ©[2017] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
* ©[2019] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
*/

require_once 'include.php';

$SugarAPI = new \Sugarcrm\REST\Client\Sugar7API($server,$credentials);
try{
$SugarAPI->login();
echo "<pre>";
print_r($SugarAPI->getAuth()->getToken()->access_token);
echo "</pre>";
$Accounts = $SugarAPI->list('Accounts');
$Accounts->fetch();
$Account = $Accounts->at(1);
$Account->getRelated('contacts',true);
echo $Account->getRequest()->getURL()."<br>";
echo "<pre> Response:".print_r($Account->getResponse()->getBody(),true)."</pre><br>";
$Filter = $Account->filterRelated('contacts')->contains('first_name','s');
echo "<pre> Filter Contacts related to Account {$account['id']} where first_name contains an 's': ".print_r($Filter->compile(),true)."</pre><br>";
$Filter->execute();
echo "<pre> Response:".print_r($Account->getResponse()->getBody(),true)."</pre><br>";
if ($SugarAPI->login()){
echo "<pre>";
print_r($SugarAPI->getAuth()->getToken()->access_token);
echo "</pre>";
$Accounts = $SugarAPI->list('Accounts');
$Accounts->fetch();
$Account = $Accounts->at(1);
$Account->getRelated('contacts',true);
echo $Account->getRequest()->getURL()."<br>";
echo "<pre> Response:".print_r($Account->getResponse()->getBody(),true)."</pre><br>";
$Filter = $Account->filterRelated('contacts')->contains('first_name','s');
echo "<pre> Filter Contacts related to Account {$account['id']} where first_name contains an 's': ".print_r($Filter->compile(),true)."</pre><br>";
$Filter->execute();
echo "<pre> Response:".print_r($Account->getResponse()->getBody(),true)."</pre><br>";
} else {
echo "Could not login.";
pre($SugarAPI->getAuth()->getActionEndpoint('authenticate')->getResponse());
}
}catch (Exception $ex){
echo "<pre>";
//print_r($SugarAPI);
echo "</pre>";
print $ex->getMessage();
echo "Error Occurred: ";
pre($ex->getMessage());
}

0 comments on commit 8ca8bde

Please sign in to comment.