Skip to content

Commit

Permalink
Fixed PHP 5.6 File Uploads - Added Endpoints
Browse files Browse the repository at this point in the history
Needed some Endpoints that weren’t there, such as MassRelate and Update
Related

Updated documentation on SugarClient

Added a check for PHP 5.5+, and CurlFile usage for File Uploads. Tested
it via Updated UploadFile example
  • Loading branch information
MichaelJ2324 committed Feb 27, 2017
1 parent c245cee commit dd4b8e5
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 18 deletions.
2 changes: 1 addition & 1 deletion examples/UploadFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require_once __DIR__.'/../vendor/autoload.php';

try{
$SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Ent/7700/', array('username' => 'admin', 'password'=>'asdf'));
$SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Ent/7800/', array('username' => 'admin', 'password'=>'asdf'));
$SugarAPI->login();
$EP = $SugarAPI->createRecord('Notes')->execute(array('name' => 'Test Note'));
$response = $EP->getResponse();
Expand Down
31 changes: 16 additions & 15 deletions src/Client/Abstracts/AbstractSugarClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use SugarAPI\SDK\Exception\Authentication\AuthenticationException;
use SugarAPI\SDK\Exception\SDKException;
use SugarAPI\SDK\Helpers\Helpers;
use SugarAPI\SDK\Endpoint\Interfaces\EPInterface;

/**
* The Abstract Client implementation for Sugar
Expand All @@ -17,27 +18,27 @@
* @method EPInterface getAttachment(string $module = '',string $record_id = '')
* @method EPInterface getChangeLog(string $module = '',string $record_id = '')
* @method EPInterface filterRelated(string $module = '')
* @method EPInterface getRelated(string $module = '',
* string $record_id = '',
* string $relationship = '',
* string $related_id = '')
* @method EPInterface getRelated(string $module = '',string $record_id = '',string $relationship = '',string $related_id = '')
* @method EPInterface me()
* @method EPInterface search()
* @method EPInterface oauth2Token()
* @method EPInterface oauth2Refresh()
* @method EPInterface createRecord()
* @method EPInterface filterRecords()
* @method EPInterface attachFile()
* @method EPInterface createRecord(string $module = '')
* @method EPInterface filterRecords(string $module = '')
* @method EPInterface attachFile(string $module = '',string $record_id = '')
* @method EPInterface oauth2Logout()
* @method EPInterface createRelated()
* @method EPInterface linkRecords()
* @method EPInterface createRelated(string $module = '',string $record_id = '',string $relationship = '')
* @method @deprecated EPInterface linkRecords(string $module = '',string $record_id = '',string $relationship = '',string $related_id = '')
* @method EPInterface relateRecord(string $module = '',string $record_id = '',string $relationship = '',string $related_id = '')
* @method EPInterface massRelate(string $module = '',string $record_id = '')
* @method EPInterface bulk()
* @method EPInterface updateRecord()
* @method EPInterface favorite()
* @method EPInterface deleteRecord()
* @method EPInterface unfavorite()
* @method EPInterface deleteFile()
* @method EPInterface unlinkRecords()
* @method EPInterface updateRecord(string $module = '',string $record_id = '')
* @method EPInterface updateRelated(string $module = '',string $record_id = '',string $relationship = '',string $related_id = '')
* @method EPInterface favorite(string $module = '',string $record_id = '')
* @method EPInterface deleteRecord(string $module = '',string $record_id = '')
* @method EPInterface unfavorite(string $module = '',string $record_id = '')
* @method EPInterface deleteFile(string $module = '',string $record_id = '')
* @method EPInterface unlinkRecords(string $module = '',string $record_id = '',string $relationship = '',string $related_id = '')
*/
abstract class AbstractSugarClient extends AbstractClient
{
Expand Down
8 changes: 6 additions & 2 deletions src/Endpoint/POST/ModuleRecordFileField.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ protected function configureData($data)
*/
protected function setFileFieldValue($value)
{
if (strpos($value, '@') === false) {
$value = '@'.$value;
if (version_compare(PHP_VERSION, '5.5.0') >= 0){
$value = new \CURLFile($value);
} else {
if (strpos($value, '@') === false) {
$value = '@'.$value;
}
}
return $value;
}
Expand Down
25 changes: 25 additions & 0 deletions src/Endpoint/POST/ModuleRecordLink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* ©[2016] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
*/

namespace SugarAPI\SDK\Endpoint\POST;

use SugarAPI\SDK\Endpoint\Abstracts\POST\AbstractPostEndpoint;

class ModuleRecordLink extends AbstractPostEndpoint
{
/**
* @inheritdoc
*/
protected $_URL = '$module/$record/link';

/**
* @inheritdoc
*/
protected $_REQUIRED_DATA = array(
'link_name' => NULL,
'ids' => NULL
);

}
16 changes: 16 additions & 0 deletions src/Endpoint/PUT/ModuleRecordLinkRecord.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* ©[2016] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
*/

namespace SugarAPI\SDK\Endpoint\PUT;

use SugarAPI\SDK\Endpoint\Abstracts\PUT\AbstractPutEndpoint;

class ModuleRecordLinkRecord extends AbstractPutEndpoint
{
/**
* @inheritdoc
*/
protected $_URL = '$module/$record/link/$relationship/$record';
}
3 changes: 3 additions & 0 deletions src/Helpers/registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@
'oauth2Logout' => 'POST\\OAuth2Logout',
'createRelated' => 'POST\\ModuleRecordRelationship',
'linkRecords' => 'POST\\ModuleRecordLinkRecord',
'relateRecord' => 'POST\\ModuleRecordLinkRecord',
'massRelate' => 'POST\\ModuleRecordLink',
'bulk' => 'POST\\Bulk',

//PUT API Endpoints
'updateRecord' => 'PUT\\ModuleRecord',
'favorite' => 'PUT\\ModuleRecordFavorite',
'updateMe' => 'PUT\\Me',
'updatePreferences' => 'PUT\\MePreferences',
'updateRelated' => 'PUT\\ModuleRecordLinkRecord',

//DELETE API Endpoints
'deleteRecord' => 'DELETE\\ModuleRecord',
Expand Down

0 comments on commit dd4b8e5

Please sign in to comment.