Skip to content

Commit eec458a

Browse files
committed
Update Copyright + Update Examples
1 parent 5b96124 commit eec458a

38 files changed

+236
-262
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ To contribute,
44

55
1. Fork this repository.
66
1. Work on your changes within a topic branch.
7-
1. Create a pull request to the corresponding version branch
7+
1. Create a pull request to the corresponding version branch (typically develop branch)
88

9-
Pull requests are accepted under the discretion of the Sugar REST PHP Client maintainer(s). Improve the chances your PR will be merged by following the requirements and guidelines below. For any questions, please e­mail [email protected].
9+
Pull requests are accepted under the discretion of the Sugar PHP Rest Client maintainer(s). Improve the chances your PR will be merged by following the requirements and guidelines below. For any questions, please e­mail [email protected].
1010

1111
**REQUIREMENTS**
1212
- By creating a pull request, you are agreeing to [SugarCRM Open Source Contributor terms](CONTRIBUTOR_TERMS.pdf).
1313

1414
**GUIDELINES**
1515
- Make sure your pull contains quality code. We will certainly provide constructive feedback on works in progress but we will not merge incomplete pull requests.
16+
- Use `composer run quality:fix` to ensure PER 2.0 compliant code
1617
- Make sure your pull is fully documented.
1718
- Make sure all unit tests are updated for relevant code changes, and add any unit tests for new code.
1819
- Reference related Github Issues within commit comments and pull request comment where appropriate.

examples/ArchiveEmail.php

Lines changed: 0 additions & 43 deletions
This file was deleted.

examples/AuditLog.php

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,39 @@
11
<?php
22

33
/**
4-
* ©[2024] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
4+
* ©[2025] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
55
*/
66

77
require_once 'include.php';
88

99
$SugarAPI = new \Sugarcrm\REST\Client\SugarAPI($server, $credentials);
1010
try {
11-
if ($SugarAPI->login()) {
11+
if ($SugarAPI->isAuthenticated()) {
12+
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";
13+
// Due to core Bug on Sugar 11+, Audit Log API has a min version of 11_11, so I'm forcing it here
1214
$SugarAPI->setVersion('11_11');
13-
echo "Logged In: ";
14-
pre($SugarAPI->getAuth()->getToken());
15+
1516
$Account = $SugarAPI->module('Accounts')->set("name", "Audit Log Test");
1617
$Account->save();
17-
pre("Created Account: {$Account['id']}");
18+
echo "Created Account: {$Account['id']}\n";
19+
//Update the account to generate Audits
1820
$Account->set('phone_office', '555-555-5555');
1921
$Account['name'] = 'Audit Log Test - Updated';
2022
$Account['assigned_user_id'] = 'seed_max_id';
2123
$Account->save();
22-
echo "Account Updated:";
23-
pre($Account->toArray());
24+
echo "Account Updated: " . json_encode($Account->toArray(),JSON_PRETTY_PRINT) . "\n";
2425
$Account->audit();
25-
echo "Audit Log: ";
26-
pre($Account->getResponseBody());
26+
echo "Audit Log: " . json_encode($Account->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
2727
} else {
2828
echo "Could not login.";
29-
pre($SugarAPI->getAuth()->getActionEndpoint('authenticate')->getResponse());
29+
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');
30+
$response = $oauthEndpoint->getResponse();
31+
if ($response) {
32+
$statusCode = $oauthEndpoint->getResponse()->getStatusCode();
33+
echo "[$statusCode] - " . $oauthEndpoint->getResponse()->getBody()->getContents();
34+
}
3035
}
3136
} catch (Exception $ex) {
32-
echo "Error Occurred: ";
33-
pre($ex->getMessage());
34-
pre($ex->getTraceAsString());
35-
}
37+
echo "Exception Occurred: " . $ex->getMessage();
38+
echo $ex->getTraceAsString();
39+
}

examples/Bulk.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
<?php
22

33
/**
4-
* ©[2024] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
4+
* ©[2025] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
55
*/
66

77
require_once 'include.php';
88

99
$SugarAPI = new \Sugarcrm\REST\Client\SugarApi($server, $credentials);
10+
1011
try {
1112
if ($SugarAPI->isAuthenticated()) {
13+
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
14+
1215
$lead1 = $SugarAPI->module("Leads");
1316
$lead2 = $SugarAPI->module("Leads");
1417
$lead1['first_name'] = "Test";
@@ -18,23 +21,27 @@
1821
$lead2->set($lead1->toArray());
1922
//Add 2 to second lead last name to differentiate
2023
$lead2['last_name'] .= "2";
21-
//Set
22-
$lead1->setCurrentAction(\MRussell\REST\Endpoint\ModelEndpoint::MODEL_ACTION_CREATE);
23-
$lead2->setCurrentAction(\MRussell\REST\Endpoint\ModelEndpoint::MODEL_ACTION_CREATE);
24+
//By default a SugarBean Endpoint with no action and ID will do a CREATE API Request
25+
//To change the API used for the Model Endpoint, set the Action
26+
//$lead1->setCurrentAction(\MRussell\REST\Endpoint\ModelEndpoint::MODEL_ACTION_CREATE);
2427
$bulk = $SugarAPI->bulk();
2528
$bulk->setData([
2629
$lead1,
2730
$lead2,
2831
]);
29-
echo json_encode($bulk->getData()->toArray(), JSON_PRETTY_PRINT);
32+
echo "Bulk Request Payload: " . json_encode($bulk->getData()->toArray(), JSON_PRETTY_PRINT) . "\n";
3033
$bulk->execute();
31-
echo json_encode($bulk->getResponseContent(), JSON_PRETTY_PRINT);
34+
echo "Bulk Response: " . json_encode($bulk->getResponseBody(), JSON_PRETTY_PRINT) . "\n";
3235
} else {
3336
echo "Could not login.";
34-
pre($SugarAPI->getAuth()->getActionEndpoint('authenticate')->getResponse());
37+
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');
38+
$response = $oauthEndpoint->getResponse();
39+
if ($response) {
40+
$statusCode = $oauthEndpoint->getResponse()->getStatusCode();
41+
echo "[$statusCode] - " . $oauthEndpoint->getResponse()->getBody()->getContents();
42+
}
3543
}
3644
} catch (Exception $ex) {
37-
echo "Error Occurred: ";
38-
pre($ex->getMessage());
39-
pre($ex->getTraceAsString());
40-
}
45+
echo "Exception Occurred: " . $ex->getMessage();
46+
echo $ex->getTraceAsString();
47+
}

examples/CRUD.php

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,48 @@
11
<?php
22

33
/**
4-
* ©[2024] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
4+
* ©[2025] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
55
*/
66

77
require_once 'include.php';
88

99
$SugarAPI = new \Sugarcrm\REST\Client\SugarApi($server, $credentials);
10+
1011
try {
11-
if ($SugarAPI->login()) {
12-
echo "Logged In: ";
13-
pre($SugarAPI->getAuth()->getToken());
14-
$Account = $SugarAPI->module('Accounts')->set("name", "Test")->set("phone_office", "555-555-5555");
15-
echo "Creating Account: ";
16-
pre($Account->toArray());
12+
if ($SugarAPI->isAuthenticated()) {
13+
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
14+
// Create an Account called Test with a phone number
15+
$Account = $SugarAPI->module('Accounts');
16+
// You can set data via Array Access, Object Access, or set methods
17+
$Account->set("name", "Test")
18+
->set("phone_office", "555-555-5555");
19+
$Account['account_type'] = 'Prospect';
20+
$Account->email1 = "[email protected]";
1721
$Account->save();
18-
pre("Saved Account ID: {$Account['id']}");
22+
echo "Saved Account ID: {$Account['id']}\n";
23+
//Update Account
1924
$Account->set('employees', '100');
2025
$Account['shipping_address_city'] = 'Indianapolis';
21-
echo "Changing fields employees and shipping address...<br>";
2226
$Account->save();
23-
echo "Account Updated: ";
24-
pre($Account->toArray());
27+
echo "Account Updated: " . json_encode($Account->toArray(),JSON_PRETTY_PRINT) . "\n";
28+
29+
//Retrieve the Account in a new Object
2530
$Account2 = $SugarAPI->module('Accounts', $Account['id']);
2631
$Account2->retrieve();
27-
echo "Retrieving the Account Again...<br>";
28-
pre($Account2->toArray());
32+
echo "Retrieved Account: " . json_encode($Account2->toArray(),JSON_PRETTY_PRINT) . "\n";
33+
//Delete the Account
2934
$Account2->delete();
30-
echo "Account Deleted. Response: ";
31-
pre($Account2->getResponseBody());
35+
echo "Deleted Response: " . json_encode($Account2->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
3236
} else {
3337
echo "Could not login.";
34-
pre($SugarAPI->getAuth()->getActionEndpoint('authenticate')->getResponse());
38+
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');
39+
$response = $oauthEndpoint->getResponse();
40+
if ($response) {
41+
$statusCode = $oauthEndpoint->getResponse()->getStatusCode();
42+
echo "[$statusCode] - " . $oauthEndpoint->getResponse()->getBody()->getContents();
43+
}
3544
}
3645
} catch (Exception $ex) {
37-
echo "Error Occurred: ";
38-
pre($ex->getMessage());
39-
pre($ex->getTraceAsString());
46+
echo "Exception Occurred: " . $ex->getMessage();
47+
echo $ex->getTraceAsString();
4048
}

examples/DuplicateCheck.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
<?php
22

33
/**
4-
* ©[2024] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
4+
* ©[2025] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
55
*/
66

77
require_once 'include.php';
88

99
$SugarAPI = new \Sugarcrm\REST\Client\SugarApi($server, $credentials);
1010

1111
try {
12-
if ($SugarAPI->login()) {
13-
echo "Logged In: ";
14-
pre($SugarAPI->getAuth()->getToken());
12+
if ($SugarAPI->isAuthenticated()) {
13+
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
14+
//Create a new Account
1515
$Account = $SugarAPI->module('Accounts')->set("name", "DuplicateCheck Test");
1616
$Account->save();
17-
pre("Account Created: {$Account['id']}");
18-
$a = $Account->toArray();
19-
echo "Running duplicateCheck for Account: ";
17+
echo "Account Created: {$Account['id']}\n";
18+
// Run duplicate check
2019
$Account->duplicateCheck();
21-
pre($Account->getResponseBody());
20+
echo "Response: " . json_encode($Account->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
2221
} else {
2322
echo "Could not login.";
24-
pre($SugarAPI->getAuth()->getActionEndpoint('authenticate')->getResponse());
23+
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');
24+
$response = $oauthEndpoint->getResponse();
25+
if ($response) {
26+
$statusCode = $oauthEndpoint->getResponse()->getStatusCode();
27+
echo "[$statusCode] - " . $oauthEndpoint->getResponse()->getBody()->getContents();
28+
}
2529
}
2630
} catch (Exception $ex) {
27-
echo "Error Occurred: ";
28-
pre($ex->getMessage());
31+
echo "Exception Occurred: " . $ex->getMessage();
32+
echo $ex->getTraceAsString();
2933
}

examples/Favorite.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11
<?php
22

33
/**
4-
* ©[2024] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
4+
* ©[2025] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
55
*/
66

77
require_once 'include.php';
88

99
$SugarAPI = new \Sugarcrm\REST\Client\SugarApi($server, $credentials);
1010

1111
try {
12-
if ($SugarAPI->login()) {
13-
echo "Logged In: <pre>";
14-
print_r($SugarAPI->getAuth()->getToken()->access_token);
15-
echo "</pre>";
12+
if ($SugarAPI->isAuthenticated()) {
13+
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
14+
//Create a new Account
1615
$Account = $SugarAPI->module('Accounts')->set("name", "Favorite Test");
1716
$Account->save();
18-
echo "<pre> Account Created: {$Account['id']}</pre><br>";
17+
echo "Account Created: {$Account['id']}\n";
1918
$Account->favorite();
20-
echo "Account added to Favorites: " . ($Account->my_favorite == 1 ? "TRUE" : "FALSE");
19+
echo "Account added to Favorites: " . ($Account->my_favorite ? "TRUE" : "FALSE") . "\n";
2120
} else {
2221
echo "Could not login.";
23-
pre($SugarAPI->getAuth()->getActionEndpoint('authenticate')->getResponse());
22+
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');
23+
$response = $oauthEndpoint->getResponse();
24+
if ($response) {
25+
$statusCode = $oauthEndpoint->getResponse()->getStatusCode();
26+
echo "[$statusCode] - " . $oauthEndpoint->getResponse()->getBody()->getContents();
27+
}
2428
}
2529
} catch (Exception $ex) {
26-
echo "Error Occurred: ";
27-
pre($ex->getMessage());
28-
}
30+
echo "Exception Occurred: " . $ex->getMessage();
31+
echo $ex->getTraceAsString();
32+
}

0 commit comments

Comments
 (0)