From 3c5ea68a0e0b38e885a72e7cd394453f778fd14c Mon Sep 17 00:00:00 2001 From: Mike Russell <3056352+MichaelJ2324@users.noreply.github.com> Date: Mon, 3 Feb 2025 09:48:38 -0500 Subject: [PATCH 1/3] Update CONTRIBUTING.md --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 465b4c5..b753e3d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -23,4 +23,4 @@ Pull requests are accepted under the discretion of the Sugar PHP Rest Client mai File bugs or feature requests using Github Issue Tracker. -https://github.com/sugarcrm-developers/php-rest-client/issues \ No newline at end of file +https://github.com/sugarcrm-developers/php-rest-client/issues From 1a4322cc98d378dc4dd02f408959a6833a36cd20 Mon Sep 17 00:00:00 2001 From: Mike Russell <3056352+MichaelJ2324@users.noreply.github.com> Date: Tue, 4 Feb 2025 13:25:57 -0500 Subject: [PATCH 2/3] Fix up MLP Endpoint for Upload and Install handling --- .../Abstracts/AbstractSugarBeanEndpoint.php | 9 +- src/Endpoint/MLPackage.php | 83 +++++++++++++++++++ 2 files changed, 87 insertions(+), 5 deletions(-) diff --git a/src/Endpoint/Abstracts/AbstractSugarBeanEndpoint.php b/src/Endpoint/Abstracts/AbstractSugarBeanEndpoint.php index 290a64d..6da6c46 100644 --- a/src/Endpoint/Abstracts/AbstractSugarBeanEndpoint.php +++ b/src/Endpoint/Abstracts/AbstractSugarBeanEndpoint.php @@ -543,12 +543,11 @@ protected function configureFileUploadQueryParams(): array ]; if ($this->_deleteFileOnFail) { - $Client = $this->getClient(); - if ($Client) { - $data['platform'] = $Client->getPlatform(); - $token = $Client->getAuth()->getTokenProp('access_token'); + if (!empty($this->_client)) { + $data['platform'] = $this->getClient()->getPlatform(); + $token = $this->getClient()->getAuth()->getTokenProp('access_token'); if ($token) { - $data['oauth_token'] = $Client->getAuth()->getTokenProp('access_token'); + $data['oauth_token'] = $this->getClient()->getAuth()->getTokenProp('access_token'); } } } diff --git a/src/Endpoint/MLPackage.php b/src/Endpoint/MLPackage.php index 016ef8e..e0506c1 100644 --- a/src/Endpoint/MLPackage.php +++ b/src/Endpoint/MLPackage.php @@ -2,6 +2,9 @@ namespace Sugarcrm\REST\Endpoint; +use GuzzleHttp\Psr7\Response; +use MRussell\REST\Endpoint\ModelEndpoint; + class MLPackage extends SugarBean { public const ACTION_INSTALL = 'install'; @@ -14,6 +17,8 @@ class MLPackage extends SugarBean public const ACTION_INSTALL_STATUS = 'installation-status'; + public const MLP_FIELD_PROP = 'upgrade_zip'; + protected static array $_DEFAULT_PROPERTIES = [ self::PROPERTY_URL => 'Administration/packages/$id/$:action', self::PROPERTY_AUTH => true, @@ -25,8 +30,86 @@ class MLPackage extends SugarBean self::ACTION_ENABLE => 'GET', self::ACTION_DISABLE => 'GET', self::ACTION_INSTALL_STATUS => 'GET', + self::BEAN_ACTION_ATTACH_FILE => 'POST' ]; + protected bool $_installing = false; + + protected array $_installOutput = []; + + public function setUrlArgs(array $args): static + { + if (isset($args[0])) { + $this->set($this->getKeyProperty(), $args[0]); + unset($args[0]); + } + return ModelEndpoint::setUrlArgs($args); + } + + public function install(array $options = [], bool $async = false): static + { + $this->_installing = true; + $this->setCurrentAction(self::ACTION_INSTALL); + if ($async) { + return $this->asyncExecute($options); + } else { + return $this->execute($options); + } + } + + public function isInstalling(): bool + { + return $this->_installing; + } + + public function checkInstallStatus(): array + { + $this->setCurrentAction(self::ACTION_INSTALL_STATUS); + $this->execute(); + return $this->_installOutput; + } + + public function upload(string $filePath): static + { + $this->setCurrentAction(self::MODEL_ACTION_CREATE); + $this->_upload = true; + $this->setFile(self::MLP_FIELD_PROP, $filePath); + return $this->execute(); + } + + protected function configurePayload(): mixed + { + $data = $this->getData(); + //If someone set field of ZIP, instead of using upload Method + if (isset($data[self::MLP_FIELD_PROP]) && !$this->_upload && $this->getCurrentAction() !== self::MODEL_ACTION_CREATE) { + $this->setFile(self::MLP_FIELD_PROP, $data[self::MLP_FIELD_PROP]); + $this->_upload = true; + } + return parent::configurePayload(); + } + + protected function parseResponse(Response $response): void + { + parent::parseResponse($response); + if ($response->getStatusCode() == 200) { + $data = $this->getResponseBody(); + switch ($this->getCurrentAction()) { + case self::ACTION_INSTALL: + case self::ACTION_UNINSTALL: + $this->_installing = false; + break; + case self::ACTION_INSTALL_STATUS: + if (!empty($data['message'])){ + $this->_installOutput = $data['message'] ?? []; + } + break; + } + if (($data['status'] ?? "") == 'installed') { + $this->_installing = false; + } + } + } + /** * Setup the query params passed during File Uploads * @codeCoverageIgnore From 0aa813c341251056855e773b55d2b827326bd59f Mon Sep 17 00:00:00 2001 From: Mike Russell <3056352+MichaelJ2324@users.noreply.github.com> Date: Tue, 4 Feb 2025 13:56:14 -0500 Subject: [PATCH 3/3] Code Qaulity Fixes --- examples/AuditLog.php | 6 ++-- examples/Bulk.php | 4 +-- examples/CRUD.php | 8 +++--- examples/DuplicateCheck.php | 4 +-- examples/Favorite.php | 4 +-- examples/FileManipulation.php | 6 ++-- examples/FilterAPI.php | 4 +-- examples/FilterRelated.php | 8 +++--- examples/ModuleEnum.php | 4 +-- examples/NoteAttachments.php | 4 +-- examples/RelateRecords.php | 8 +++--- examples/Sudo.php | 6 ++-- examples/include.php | 6 ++-- src/Auth/SugarOAuthController.php | 2 +- .../Abstracts/AbstractSugarBeanEndpoint.php | 4 +-- src/Endpoint/AuditLog.php | 2 +- src/Endpoint/Collection.php | 4 +-- src/Endpoint/Email.php | 4 +-- src/Endpoint/Generic.php | 4 +-- src/Endpoint/MLPackage.php | 6 ++-- src/Endpoint/ModuleLoader.php | 4 +-- .../Provider/SugarEndpointProvider.php | 4 +-- src/Endpoint/Smart.php | 4 +-- src/Endpoint/SugarBeanCollection.php | 5 +--- tests/Endpoint/Data/BulkRequestTest.php | 2 +- tests/Endpoint/ModuleLoaderTest.php | 28 +++++++++---------- tests/Endpoint/PingTest.php | 2 +- 27 files changed, 69 insertions(+), 78 deletions(-) diff --git a/examples/AuditLog.php b/examples/AuditLog.php index 3ea664a..2241b73 100644 --- a/examples/AuditLog.php +++ b/examples/AuditLog.php @@ -21,9 +21,9 @@ $Account['name'] = 'Audit Log Test - Updated'; $Account['assigned_user_id'] = 'seed_max_id'; $Account->save(); - echo "Account Updated: " . json_encode($Account->toArray(),JSON_PRETTY_PRINT) . "\n"; + echo "Account Updated: " . json_encode($Account->toArray(), JSON_PRETTY_PRINT) . "\n"; $Account->audit(); - echo "Audit Log: " . json_encode($Account->getResponseBody(),JSON_PRETTY_PRINT) . "\n"; + echo "Audit Log: " . json_encode($Account->getResponseBody(), JSON_PRETTY_PRINT) . "\n"; } else { echo "Could not login."; $oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate'); @@ -36,4 +36,4 @@ } catch (Exception $ex) { echo "Exception Occurred: " . $ex->getMessage(); echo $ex->getTraceAsString(); -} \ No newline at end of file +} diff --git a/examples/Bulk.php b/examples/Bulk.php index 616bf52..2a1bd85 100644 --- a/examples/Bulk.php +++ b/examples/Bulk.php @@ -10,7 +10,7 @@ try { if ($SugarAPI->isAuthenticated()) { - echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n"; + echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n"; $lead1 = $SugarAPI->module("Leads"); $lead2 = $SugarAPI->module("Leads"); @@ -44,4 +44,4 @@ } catch (Exception $ex) { echo "Exception Occurred: " . $ex->getMessage(); echo $ex->getTraceAsString(); -} \ No newline at end of file +} diff --git a/examples/CRUD.php b/examples/CRUD.php index 617ccae..c3fca06 100644 --- a/examples/CRUD.php +++ b/examples/CRUD.php @@ -10,7 +10,7 @@ try { if ($SugarAPI->isAuthenticated()) { - echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n"; + echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n"; // Create an Account called Test with a phone number $Account = $SugarAPI->module('Accounts'); // You can set data via Array Access, Object Access, or set methods @@ -24,15 +24,15 @@ $Account->set('employees', '100'); $Account['shipping_address_city'] = 'Indianapolis'; $Account->save(); - echo "Account Updated: " . json_encode($Account->toArray(),JSON_PRETTY_PRINT) . "\n"; + echo "Account Updated: " . json_encode($Account->toArray(), JSON_PRETTY_PRINT) . "\n"; //Retrieve the Account in a new Object $Account2 = $SugarAPI->module('Accounts', $Account['id']); $Account2->retrieve(); - echo "Retrieved Account: " . json_encode($Account2->toArray(),JSON_PRETTY_PRINT) . "\n"; + echo "Retrieved Account: " . json_encode($Account2->toArray(), JSON_PRETTY_PRINT) . "\n"; //Delete the Account $Account2->delete(); - echo "Deleted Response: " . json_encode($Account2->getResponseBody(),JSON_PRETTY_PRINT) . "\n"; + echo "Deleted Response: " . json_encode($Account2->getResponseBody(), JSON_PRETTY_PRINT) . "\n"; } else { echo "Could not login."; $oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate'); diff --git a/examples/DuplicateCheck.php b/examples/DuplicateCheck.php index 91ffb65..ac47054 100644 --- a/examples/DuplicateCheck.php +++ b/examples/DuplicateCheck.php @@ -10,14 +10,14 @@ try { if ($SugarAPI->isAuthenticated()) { - echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n"; + echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n"; //Create a new Account $Account = $SugarAPI->module('Accounts')->set("name", "DuplicateCheck Test"); $Account->save(); echo "Account Created: {$Account['id']}\n"; // Run duplicate check $Account->duplicateCheck(); - echo "Response: " . json_encode($Account->getResponseBody(),JSON_PRETTY_PRINT) . "\n"; + echo "Response: " . json_encode($Account->getResponseBody(), JSON_PRETTY_PRINT) . "\n"; } else { echo "Could not login."; $oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate'); diff --git a/examples/Favorite.php b/examples/Favorite.php index 9aabfa8..295e71a 100644 --- a/examples/Favorite.php +++ b/examples/Favorite.php @@ -10,7 +10,7 @@ try { if ($SugarAPI->isAuthenticated()) { - echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n"; + echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n"; //Create a new Account $Account = $SugarAPI->module('Accounts')->set("name", "Favorite Test"); $Account->save(); @@ -29,4 +29,4 @@ } catch (Exception $ex) { echo "Exception Occurred: " . $ex->getMessage(); echo $ex->getTraceAsString(); -} \ No newline at end of file +} diff --git a/examples/FileManipulation.php b/examples/FileManipulation.php index 1d73f0b..7f34761 100644 --- a/examples/FileManipulation.php +++ b/examples/FileManipulation.php @@ -13,7 +13,7 @@ $SugarAPI = new \Sugarcrm\REST\Client\SugarAPI($server, $credentials); try { if ($SugarAPI->isAuthenticated()) { - echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n"; + echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n"; $Note = $SugarAPI->module('Notes')->set("name", "Test"); //Create a note with subject @@ -21,12 +21,12 @@ echo "Saved Note ID: {$Note['id']}
"; echo "Attempting to attach $file..."; $Note->attachFile('filename', $file, true, 'testtest.txt'); - echo "File uploaded: " . json_encode($Note->getResponseBody(),JSON_PRETTY_PRINT) . "\n"; + echo "File uploaded: " . json_encode($Note->getResponseBody(), JSON_PRETTY_PRINT) . "\n"; $Note = $SugarAPI->module('Notes'); echo "Uploading temp file for new note..."; $Note->tempFile('filename', $file); - echo "Temp File uploaded: " . json_encode($Note->getResponseBody(),JSON_PRETTY_PRINT) . "\n"; + echo "Temp File uploaded: " . json_encode($Note->getResponseBody(), JSON_PRETTY_PRINT) . "\n"; $Note->set('name', 'This is a test'); $Note->save(); echo "Note ID: {$Note['id']}\n"; diff --git a/examples/FilterAPI.php b/examples/FilterAPI.php index 9a6f8a1..c9338c4 100644 --- a/examples/FilterAPI.php +++ b/examples/FilterAPI.php @@ -9,7 +9,7 @@ $SugarAPI = new \Sugarcrm\REST\Client\SugarApi($server, $credentials); try { if ($SugarAPI->isAuthenticated()) { - echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n"; + echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n"; $Accounts = $SugarAPI->list('Accounts'); $Accounts->filter()->and() @@ -40,7 +40,7 @@ ->endDate() ->endOr(); echo "Filtering Accounts that are created between dates, or in the last 7 days: " - . json_encode($Accounts->filter()->compile(),JSON_PRETTY_PRINT) . "\n"; + . json_encode($Accounts->filter()->compile(), JSON_PRETTY_PRINT) . "\n"; $Accounts->fetch(); echo "Accounts: " . json_encode($Accounts->toArray(), JSON_PRETTY_PRINT) . "\n"; } else { diff --git a/examples/FilterRelated.php b/examples/FilterRelated.php index ebfc624..72fc927 100644 --- a/examples/FilterRelated.php +++ b/examples/FilterRelated.php @@ -9,19 +9,19 @@ $SugarAPI = new \Sugarcrm\REST\Client\SugarApi($server, $credentials); try { if ($SugarAPI->isAuthenticated()) { - echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n"; + echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n"; $Accounts = $SugarAPI->list('Accounts'); $Accounts->fetch(); //Get first Account in Collection $Account = $Accounts->at(1); //Execute Related contacts count API call $Account->getRelated('contacts', true); - echo "Related Contacts Count response: " . json_encode($Account->getResponseBody(),JSON_PRETTY_PRINT) . "\n"; + echo "Related Contacts Count response: " . json_encode($Account->getResponseBody(), JSON_PRETTY_PRINT) . "\n"; //Assuming there are >0 related contacts, filter them by first name contain an `s` $Filter = $Account->filterRelated('contacts')->contains('first_name', 's'); - echo "Filter Def for API: " . json_encode($Filter->compile(),JSON_PRETTY_PRINT) . "\n"; + echo "Filter Def for API: " . json_encode($Filter->compile(), JSON_PRETTY_PRINT) . "\n"; $Filter->execute(); - echo "Response:" . json_encode($Account->getResponseBody(),JSON_PRETTY_PRINT) . "\n"; + echo "Response:" . json_encode($Account->getResponseBody(), JSON_PRETTY_PRINT) . "\n"; } else { echo "Could not login."; $oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate'); diff --git a/examples/ModuleEnum.php b/examples/ModuleEnum.php index e2f5e92..52b078a 100644 --- a/examples/ModuleEnum.php +++ b/examples/ModuleEnum.php @@ -9,10 +9,10 @@ try { if ($SugarAPI->isAuthenticated()) { - echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n"; + echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n"; $Enum = $SugarAPI->enum('Accounts', 'account_type')->execute(); - echo "Account Type options: " . json_encode($Enum->getResponseBody(),JSON_PRETTY_PRINT) . "\n"; + echo "Account Type options: " . json_encode($Enum->getResponseBody(), JSON_PRETTY_PRINT) . "\n"; } else { echo "Could not login."; $oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate'); diff --git a/examples/NoteAttachments.php b/examples/NoteAttachments.php index 6f6b031..f798ccc 100644 --- a/examples/NoteAttachments.php +++ b/examples/NoteAttachments.php @@ -13,7 +13,7 @@ $SugarAPI = new \Sugarcrm\REST\Client\SugarAPI($server, $credentials); try { if ($SugarAPI->isAuthenticated()) { - echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n"; + echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n"; $Note = $SugarAPI->note()->set("name", "Test"); echo "Creating Note with multiple attachments: "; @@ -34,7 +34,7 @@ //Add attachment_list field to retrieve request so we can see uploaded files $Note->addField('attachment_list'); $Note->retrieve(); - echo "Attachments: " . json_encode($Note->attachment_list,JSON_PRETTY_PRINT) . "\n"; + echo "Attachments: " . json_encode($Note->attachment_list, JSON_PRETTY_PRINT) . "\n"; } else { echo "Could not login."; $oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate'); diff --git a/examples/RelateRecords.php b/examples/RelateRecords.php index 260bbb2..4425d4d 100644 --- a/examples/RelateRecords.php +++ b/examples/RelateRecords.php @@ -9,20 +9,20 @@ $SugarAPI = new \Sugarcrm\REST\Client\SugarApi($server, $credentials); try { if ($SugarAPI->isAuthenticated()) { - echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n"; + echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n"; $Account = $SugarAPI->module('Accounts')->set("name", "Relate Records Test"); $Account->save(); - echo "Created Account {$Account['id']}: " . json_encode($Account->toArray(),JSON_PRETTY_PRINT) . "\n"; + echo "Created Account {$Account['id']}: " . json_encode($Account->toArray(), JSON_PRETTY_PRINT) . "\n"; $Opportunity = $SugarAPI->module('Opportunities'); $Opportunity['name'] = 'Test Opportunity'; $Opportunity['description'] = 'This opportunity was created via the SugarCRM PHP REST Client v1 to test creating relationships.'; $Opportunity->save(); - echo "Created Opportunity {$Opportunity['id']}: " . json_encode($Opportunity->toArray(),JSON_PRETTY_PRINT) . "\n"; + echo "Created Opportunity {$Opportunity['id']}: " . json_encode($Opportunity->toArray(), JSON_PRETTY_PRINT) . "\n"; echo "Relating Opportunity to Account: "; $Account->relate('opportunities', $Opportunity['id']); - echo "Response: " . json_encode($Account->getResponseBody(),JSON_PRETTY_PRINT) . "\n"; + echo "Response: " . json_encode($Account->getResponseBody(), JSON_PRETTY_PRINT) . "\n"; } else { echo "Could not login."; $oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate'); diff --git a/examples/Sudo.php b/examples/Sudo.php index 42c51e1..e2536bc 100644 --- a/examples/Sudo.php +++ b/examples/Sudo.php @@ -9,12 +9,12 @@ $SugarAPI = new \Sugarcrm\REST\Client\SugarApi($server, $credentials); try { if ($SugarAPI->isAuthenticated()) { - echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n"; + echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n"; if ($SugarAPI->sudo('will')) { - echo "Sudo'd to will. Token: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n"; + echo "Sudo'd to will. Token: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n"; $Me = $SugarAPI->me(); $Me->retrieve(); - echo "User: " . json_encode($Me->toArray(),JSON_PRETTY_PRINT) . "\n"; + echo "User: " . json_encode($Me->toArray(), JSON_PRETTY_PRINT) . "\n"; } } else { echo "Could not login."; diff --git a/examples/include.php b/examples/include.php index 257669c..6f69841 100644 --- a/examples/include.php +++ b/examples/include.php @@ -7,8 +7,8 @@ require_once __DIR__ . '/../vendor/autoload.php'; $server = 'localhost'; -$credentials = array( +$credentials = [ 'username' => 'admin', 'password' => 'asdf', - 'platform' => 'base' -); + 'platform' => 'base', +]; diff --git a/src/Auth/SugarOAuthController.php b/src/Auth/SugarOAuthController.php index e543815..2bf5fd8 100644 --- a/src/Auth/SugarOAuthController.php +++ b/src/Auth/SugarOAuthController.php @@ -81,7 +81,7 @@ protected function generateUniqueCacheString(array $creds): string $key = ''; try { $ep = $this->getActionEndpoint(self::ACTION_AUTH); - $key = preg_replace("/\/rest\/v[^\/]+\//","",$ep->getBaseUrl()); + $key = preg_replace("/\/rest\/v[^\/]+\//", "", $ep->getBaseUrl()); } catch (\Exception) { $this->getLogger()->info("Cannot use server in cache string."); } diff --git a/src/Endpoint/Abstracts/AbstractSugarBeanEndpoint.php b/src/Endpoint/Abstracts/AbstractSugarBeanEndpoint.php index 6da6c46..2b77532 100644 --- a/src/Endpoint/Abstracts/AbstractSugarBeanEndpoint.php +++ b/src/Endpoint/Abstracts/AbstractSugarBeanEndpoint.php @@ -94,7 +94,7 @@ abstract class AbstractSugarBeanEndpoint extends ModelEndpoint implements SugarE protected static array $_DEFAULT_PROPERTIES = [ self::PROPERTY_URL => '$module/$id/$:action/$:actionArg1/$:actionArg2/$:actionArg3', self::PROPERTY_HTTP_METHOD => 'GET', - self::PROPERTY_AUTH => true + self::PROPERTY_AUTH => true, ]; /** @@ -380,7 +380,7 @@ public function relate(string $linkName, string $related_id): static */ public function auditLog(?int $limit = null): AuditLog { - $auditCollection = new AuditLog([],['module' => $this->getModule(), 'id' => $this->get('id')]); + $auditCollection = new AuditLog([], ['module' => $this->getModule(), 'id' => $this->get('id')]); if ($limit !== null) { $auditCollection->setLimit($limit); diff --git a/src/Endpoint/AuditLog.php b/src/Endpoint/AuditLog.php index b151ae2..574e435 100644 --- a/src/Endpoint/AuditLog.php +++ b/src/Endpoint/AuditLog.php @@ -8,4 +8,4 @@ class AuditLog extends SugarBeanCollection self::PROPERTY_URL => '$module/$id/audit', self::PROPERTY_AUTH => true, ]; -} \ No newline at end of file +} diff --git a/src/Endpoint/Collection.php b/src/Endpoint/Collection.php index 1e7b5da..751e28c 100644 --- a/src/Endpoint/Collection.php +++ b/src/Endpoint/Collection.php @@ -4,6 +4,4 @@ use Sugarcrm\REST\Endpoint\Abstracts\AbstractSugarCollectionEndpoint; -class Collection extends AbstractSugarCollectionEndpoint -{ -} \ No newline at end of file +class Collection extends AbstractSugarCollectionEndpoint {} diff --git a/src/Endpoint/Email.php b/src/Endpoint/Email.php index 74e02e6..6a6f6ec 100644 --- a/src/Endpoint/Email.php +++ b/src/Endpoint/Email.php @@ -42,7 +42,7 @@ public function addAttachments(array $files, bool $async = true): self if ($async) { $responses = Utils::unwrap($promises); $Note = new Note(); - foreach($responses as $response){ + foreach ($responses as $response) { $Note->setResponse($response); $this->parseAttachmentUploadResponse($Note->getResponseBody()); } @@ -51,4 +51,4 @@ public function addAttachments(array $files, bool $async = true): self return $this; } -} \ No newline at end of file +} diff --git a/src/Endpoint/Generic.php b/src/Endpoint/Generic.php index 4a54023..66e2766 100644 --- a/src/Endpoint/Generic.php +++ b/src/Endpoint/Generic.php @@ -4,6 +4,4 @@ use Sugarcrm\REST\Endpoint\Abstracts\AbstractSugarEndpoint; -class Generic extends AbstractSugarEndpoint -{ -} \ No newline at end of file +class Generic extends AbstractSugarEndpoint {} diff --git a/src/Endpoint/MLPackage.php b/src/Endpoint/MLPackage.php index e0506c1..f384004 100644 --- a/src/Endpoint/MLPackage.php +++ b/src/Endpoint/MLPackage.php @@ -30,7 +30,7 @@ class MLPackage extends SugarBean self::ACTION_ENABLE => 'GET', self::ACTION_DISABLE => 'GET', self::ACTION_INSTALL_STATUS => 'GET', - self::BEAN_ACTION_ATTACH_FILE => 'POST' + self::BEAN_ACTION_ATTACH_FILE => 'POST', ]; protected bool $_installing = false; @@ -99,7 +99,7 @@ protected function parseResponse(Response $response): void $this->_installing = false; break; case self::ACTION_INSTALL_STATUS: - if (!empty($data['message'])){ + if (!empty($data['message'])) { $this->_installOutput = $data['message'] ?? []; } break; @@ -118,4 +118,4 @@ protected function configureFileUploadQueryParams(): array { return []; } -} \ No newline at end of file +} diff --git a/src/Endpoint/ModuleLoader.php b/src/Endpoint/ModuleLoader.php index 4695810..98d34f6 100644 --- a/src/Endpoint/ModuleLoader.php +++ b/src/Endpoint/ModuleLoader.php @@ -16,7 +16,7 @@ class ModuleLoader extends CollectionEndpoint self::PROPERTY_URL => 'Administration/packages/$:filter', self::PROPERTY_RESPONSE_PROP => 'packages', self::PROPERTY_HTTP_METHOD => 'GET', - self::PROPERTY_AUTH => true + self::PROPERTY_AUTH => true, ]; protected string $_modelInterface = MLPackage::class; @@ -67,4 +67,4 @@ public function newPackage(): MLPackage { return $this->generateEndpoint(MLPackage::class); } -} \ No newline at end of file +} diff --git a/src/Endpoint/Provider/SugarEndpointProvider.php b/src/Endpoint/Provider/SugarEndpointProvider.php index 5edae00..97caa08 100644 --- a/src/Endpoint/Provider/SugarEndpointProvider.php +++ b/src/Endpoint/Provider/SugarEndpointProvider.php @@ -89,7 +89,7 @@ class SugarEndpointProvider extends VersionedEndpointProvider self::ENDPOINT_PROPERTIES => [ Generic::PROPERTY_URL => 'oauth2/logout', Generic::PROPERTY_AUTH => true, - Generic::PROPERTY_HTTP_METHOD => "POST" + Generic::PROPERTY_HTTP_METHOD => "POST", ], ], [ @@ -154,6 +154,6 @@ class SugarEndpointProvider extends VersionedEndpointProvider self::ENDPOINT_NAME => 'mlp', self::ENDPOINT_CLASS => MLPackage::class, self::ENDPOINT_PROPERTIES => [], - ] + ], ]; } diff --git a/src/Endpoint/Smart.php b/src/Endpoint/Smart.php index 07f1cd7..28c823a 100644 --- a/src/Endpoint/Smart.php +++ b/src/Endpoint/Smart.php @@ -4,6 +4,4 @@ use Sugarcrm\REST\Endpoint\Abstracts\AbstractSmartSugarEndpoint; -class Smart extends AbstractSmartSugarEndpoint -{ -} \ No newline at end of file +class Smart extends AbstractSmartSugarEndpoint {} diff --git a/src/Endpoint/SugarBeanCollection.php b/src/Endpoint/SugarBeanCollection.php index f54527f..d74acd3 100644 --- a/src/Endpoint/SugarBeanCollection.php +++ b/src/Endpoint/SugarBeanCollection.php @@ -4,7 +4,4 @@ use Sugarcrm\REST\Endpoint\Abstracts\AbstractSugarBeanCollectionEndpoint; -class SugarBeanCollection extends AbstractSugarBeanCollectionEndpoint -{ - -} \ No newline at end of file +class SugarBeanCollection extends AbstractSugarBeanCollectionEndpoint {} diff --git a/tests/Endpoint/Data/BulkRequestTest.php b/tests/Endpoint/Data/BulkRequestTest.php index 464ddc5..3250c80 100644 --- a/tests/Endpoint/Data/BulkRequestTest.php +++ b/tests/Endpoint/Data/BulkRequestTest.php @@ -69,7 +69,7 @@ public function testAsArray(): void $Request = new Request("POST", 'http://localhost/rest/v11/Accounts', ['Content-Type' => 'application/json'], json_encode(['foo' => 'bar'])); - $Filter = new ModuleFilter([],['Contacts']); + $Filter = new ModuleFilter([], ['Contacts']); $Filter->setBaseUrl('http://localhost/rest/v11'); $Filter->filter()->equals('foo', 'bar'); diff --git a/tests/Endpoint/ModuleLoaderTest.php b/tests/Endpoint/ModuleLoaderTest.php index a55b1c2..a5e7cd3 100644 --- a/tests/Endpoint/ModuleLoaderTest.php +++ b/tests/Endpoint/ModuleLoaderTest.php @@ -53,32 +53,32 @@ public function testSetUrlArgs() */ public function testStaged() { - $this->client->mockResponses->append(new Response(200,[],json_encode([ + $this->client->mockResponses->append(new Response(200, [], json_encode([ 'packages' => [ [ 'id' => '12345', - 'name' => 'test' - ] - ] + 'name' => 'test', + ], + ], ]))); $packages = new ModuleLoader(); $packages->setClient($this->client); $packages->setBaseUrl('http://localhost/rest/v11'); $packages->staged(); - $this->assertEquals('http://localhost/rest/v11/Administration/packages/staged', (string)$this->client->mockResponses->getLastRequest()->getUri()); + $this->assertEquals('http://localhost/rest/v11/Administration/packages/staged', (string) $this->client->mockResponses->getLastRequest()->getUri()); $this->assertEquals('GET', $this->client->mockResponses->getLastRequest()->getMethod()); $package = $packages->get('12345'); $this->assertInstanceOf(MLPackage::class, $package); $this->assertEquals([ 'id' => '12345', - 'name' => 'test' + 'name' => 'test', ], $package->toArray()); - $this->client->mockResponses->append(new Response(200,[],json_encode([ - 'packages' => [] + $this->client->mockResponses->append(new Response(200, [], json_encode([ + 'packages' => [], ]))); $packages->fetch(); - $this->assertEquals('http://localhost/rest/v11/Administration/packages', (string)$this->client->mockResponses->getLastRequest()->getUri()); + $this->assertEquals('http://localhost/rest/v11/Administration/packages', (string) $this->client->mockResponses->getLastRequest()->getUri()); $this->assertEquals('GET', $this->client->mockResponses->getLastRequest()->getMethod()); } @@ -90,13 +90,13 @@ public function testStaged() */ public function testInstalled() { - $this->client->mockResponses->append(new Response(200,[],json_encode([ + $this->client->mockResponses->append(new Response(200, [], json_encode([ 'packages' => [ [ 'id' => '12345', - 'name' => 'test' - ] - ] + 'name' => 'test', + ], + ], ]))); $packages = new ModuleLoader(); $packages->setClient($this->client); @@ -108,7 +108,7 @@ public function testInstalled() $this->assertInstanceOf(MLPackage::class, $package); $this->assertEquals([ 'id' => '12345', - 'name' => 'test' + 'name' => 'test', ], $package->toArray()); } diff --git a/tests/Endpoint/PingTest.php b/tests/Endpoint/PingTest.php index f865234..4204068 100644 --- a/tests/Endpoint/PingTest.php +++ b/tests/Endpoint/PingTest.php @@ -42,6 +42,6 @@ public function testWhattimeisit(): void $Ping->setClient($this->client); $Ping->setBaseUrl('http://localhost/rest/v11'); $Ping->whattimeisit(); - $this->assertEquals('http://localhost/rest/v11/ping/whattimeisit', (string)$this->client->mockResponses->getLastRequest()->getUri()); + $this->assertEquals('http://localhost/rest/v11/ping/whattimeisit', (string) $this->client->mockResponses->getLastRequest()->getUri()); } }