-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFileManipulation.php
50 lines (44 loc) · 1.9 KB
/
FileManipulation.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* ©[2025] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
*/
use GuzzleHttp\Middleware;
require_once 'include.php';
$file = __DIR__ . '/test.txt';
if (file_exists($file) && is_readable($file)) {
$SugarAPI = new \Sugarcrm\REST\Client\SugarAPI($server, $credentials);
try {
if ($SugarAPI->isAuthenticated()) {
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";
$Note = $SugarAPI->module('Notes')->set("name", "Test");
//Create a note with subject
$Note->save();
echo "Saved Note ID: {$Note['id']}<br>";
echo "Attempting to attach $file...";
$Note->attachFile('filename', $file, true, 'testtest.txt');
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";
$Note->set('name', 'This is a test');
$Note->save();
echo "Note ID: {$Note['id']}\n";
} else {
echo "Could not login.";
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');
$statusCode = $oauthEndpoint->getResponse()->getStatusCode();
echo "[$statusCode] - " . $oauthEndpoint->getResponse()->getBody()->getContents();
}
} catch (Exception $ex) {
echo "Exception Occurred: " . $ex->getMessage();
echo $ex->getTraceAsString();
}
} else {
if (!file_exists($file)) {
echo "Test file does not exist. Create/upload $file";
}
if (!is_readable($file)) {
echo "Test file is not readable for upload. Fix permissions and try again.";
}
}