Skip to content
Snippets Groups Projects
Commit 47fa660b authored by damjan's avatar damjan
Browse files

[FEATURE] Making service method for PUTing edited data to web resource

parent f8445b62
No related branches found
No related tags found
No related merge requests found
......@@ -60,10 +60,11 @@ class TsrefController extends \TYPO3\Flow\Mvc\Controller\ActionController {
*/
public function submitTypeAction(Attribute $theType, $editForm) {
if ($editForm) {
//TODO: Call edit service method
$result = $this->tsrefRestService->editAttribute($theType);
} else {
$this->tsrefRestService->addNewAttribute($theType);
$result = $this->tsrefRestService->addNewAttribute($theType);
}
// TODO: Return error message.
$this->forward('index', 'tsref', 'SGalinski.TypoScriptReferenceFrontend');
}
......@@ -79,9 +80,6 @@ class TsrefController extends \TYPO3\Flow\Mvc\Controller\ActionController {
$selectedTypeAsStdClass = $this->tsrefRestService->getAttributeById($theTypeId);
$theType->initialiseAttribute($selectedTypeAsStdClass);
$this->view->assign('selectedType', $selectedTypeAsStdClass);
} else {
// Add new type
}
$types = $this->tsrefRestService->getTypes();
......@@ -92,6 +90,6 @@ class TsrefController extends \TYPO3\Flow\Mvc\Controller\ActionController {
$this->view->assign('associativeTypes', $associativeTypes); // TODO: Use this array also for rendering menu.
$this->view->assign('types', $types);
$this->view->assign('theType', $theType);
$this->view->assign('editForm', $theTypeId !== NULL);
$this->view->assign('editForm', ($theTypeId !== NULL));
}
}
\ No newline at end of file
......@@ -50,7 +50,7 @@ class TsrefRestService {
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, TRUE);
// Timeout in seconds
curl_setopt($curlHandle, CURLOPT_TIMEOUT, 10);
curl_setopt($curlHandle, CURLOPT_TIMEOUT, 30);
return $curlHandle;
}
......@@ -177,12 +177,47 @@ class TsrefRestService {
$curlHandle = $this->initialiseCurl();
curl_setopt($curlHandle, CURLOPT_POST, 1);
curl_setopt($curlHandle, CURLOPT_HTTPHEADER, [
curl_setopt(
$curlHandle, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'accesstoken: ' . self::AUTHENTICATION_TOKEN
]);
]
);
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $attributeJson);
// Download the given URL, and return output
$output = curl_exec($curlHandle);
// Close the cURL resource, and free system resources
curl_close($curlHandle);
return $output;
}
/**
* Sends edited attribute to REST API resource by use of PUT method.
*
* @param Attribute $attribute
* @return mixed
*/
public function editAttribute(Attribute $attribute) {
if ($attribute->getId() === NULL) {
throw new \RuntimeException(
'Edited attribute: ' . ($attribute->getName() ? $attribute->getName() : '...') . ' doesnt have ID.'
);
}
$attributeJson = json_encode($attribute->toArray(TRUE));
echo ' Edit atr json: ' . $attributeJson . ' ';
$curlHandle = $this->initialiseCurl('/' . $attribute->getId());
curl_setopt($curlHandle, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt(
$curlHandle, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'accesstoken: ' . self::AUTHENTICATION_TOKEN
]
);
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $attributeJson);
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, TRUE);
// Download the given URL, and return output
$output = curl_exec($curlHandle);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment