ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ilECSConnector Class Reference
+ Inheritance diagram for ilECSConnector:
+ Collaboration diagram for ilECSConnector:

Public Member Functions

 __construct (?ilECSSetting $settings=null)
 
 addHeader (string $a_name, string $a_value)
 Add Header. More...
 
 getHeader ()
 
 setHeader (array $a_header_strings)
 
 getServer ()
 Get current server setting. More...
 
 addAuth (string $a_post, int $a_target_mid)
 Add auth resource. More...
 
 getAuth (string $a_hash, bool $a_details_only=false)
 get auth resource More...
 
 readEventFifo (bool $a_delete=false)
 Read event fifo. More...
 
 getResourceList (string $a_path)
 
 getResource (string $a_path, int $a_econtent_id, bool $a_details_only=false)
 Get resources from ECS server. More...
 
 addResource (string $a_path, $a_post)
 Add resource. More...
 
 updateResource (string $a_path, int $a_econtent_id, string $a_post_string)
 update resource More...
 
 deleteResource (string $a_path, int $a_econtent_id)
 Delete resource. More...
 
 getMemberships (int $a_mid=0)
 

Data Fields

const HTTP_CODE_CREATED = 201
 
const HTTP_CODE_OK = 200
 
const HTTP_CODE_NOT_FOUND = 404
 
const HEADER_MEMBERSHIPS = 'X-EcsReceiverMemberships'
 
const HEADER_COMMUNITIES = 'X-EcsReceiverCommunities'
 

Protected Member Functions

 prepareConnection ()
 prepare connection More...
 
 call ()
 call peer More...
 

Protected Attributes

string $path_postfix = ''
 
ilECSSetting $settings = null
 
ilCurlConnection $curl = null
 
array $header_strings = []
 
ilLogger $logger
 

Private Member Functions

 _fetchEContentIdFromHeader (array $a_header)
 fetch new econtent id from location header More...
 

Detailed Description

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 25 of file class.ilECSConnector.php.

Constructor & Destructor Documentation

◆ __construct()

ilECSConnector::__construct ( ?ilECSSetting  $settings = null)

Definition at line 44 of file class.ilECSConnector.php.

References $DIC, $settings, ILIAS\Repository\logger(), ILIAS\Repository\settings(), and ilLogLevel\WARNING.

45  {
46  global $DIC;
47 
48  $this->logger = $DIC->logger()->wsrv();
49  if ($settings) {
50  $this->settings = $settings;
51  } else {
52  $this->logger->warning('Using deprecated call.');
53  $this->logger->logStack(ilLogLevel::WARNING);
54  }
55  }
global $DIC
Definition: shib_login.php:26
ilECSSetting $settings
+ Here is the call graph for this function:

Member Function Documentation

◆ _fetchEContentIdFromHeader()

ilECSConnector::_fetchEContentIdFromHeader ( array  $a_header)
private

fetch new econtent id from location header

Parameters
arrayheader array

Definition at line 534 of file class.ilECSConnector.php.

References ILIAS\Repository\logger().

Referenced by addResource().

534  : int
535  {
536  $location_parts = [];
537  foreach ($a_header as $header => $value) {
538  if (strcasecmp('Location', $header) === 0) {
539  $location_parts = explode('/', $value);
540  break;
541  }
542  }
543  if (!$location_parts) {
544  $this->logger->error(__METHOD__ . ': Cannot find location headers.');
545  throw new ilECSConnectorException("Cannot find location header in response");
546  }
547  if (count($location_parts) === 1) {
548  $this->logger->warning(__METHOD__ . ': Cannot find path seperator.');
549  throw new ilECSConnectorException("Location header has wrong format: " . $location_parts[0]);
550  }
551  $econtent_id = end($location_parts);
552  $this->logger->info(__METHOD__ . ': Received EContentId ' . $econtent_id);
553  return (int) $econtent_id;
554  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addAuth()

ilECSConnector::addAuth ( string  $a_post,
int  $a_target_mid 
)

Add auth resource.

Parameters
string$a_postpost data
int$a_target_midthe membership id of target server
Returns
string the new hash for this authentication
Exceptions
ilECSConnectorException

Definition at line 100 of file class.ilECSConnector.php.

References $info, addHeader(), call(), getHeader(), ILIAS\Repository\logger(), and prepareConnection().

100  : string
101  {
102  $this->logger->info(__METHOD__ . ': Add new Auth resource...');
103 
104  $this->path_postfix = '/sys/auths';
105 
106  try {
107  $this->prepareConnection();
108 
109  $this->addHeader('Content-Type', 'application/json');
110  $this->addHeader('Accept', 'application/json');
111  $this->addHeader(self::HEADER_MEMBERSHIPS, (string) $a_target_mid);
112 
113  $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
114  $this->curl->setOpt(CURLOPT_POST, true);
115  $this->curl->setOpt(CURLOPT_POSTFIELDS, $a_post);
116  $ret = $this->call();
117 
118  $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
119 
120  $this->logger->info(__METHOD__ . ': Checking HTTP status...');
121  if ($info !== self::HTTP_CODE_CREATED) {
122  $this->logger->info(__METHOD__ . ': Cannot create auth resource, did not receive HTTP 201. ');
123  $this->logger->info(__METHOD__ . ': POST was: ' . $a_post);
124  $this->logger->info(__METHOD__ . ': HTTP code: ' . $info);
125  throw new ilECSConnectorException('Received HTTP status code: ' . $info);
126  }
127  $this->logger->info(__METHOD__ . ': ... got HTTP 201 (created)');
128  $this->logger->info(__METHOD__ . ': POST was: ' . $a_post);
129 
130  $result = new ilECSResult($ret);
131  $auth = $result->getResult();
132 
133  $this->logger->info(__METHOD__ . ': ... got hash: ' . $auth->hash);
134 
135  return $auth->hash;
136  } catch (ilCurlConnectionException $exc) {
137  throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
138  }
139  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addHeader(string $a_name, string $a_value)
Add Header.
$info
Definition: entry_point.php:21
prepareConnection()
prepare connection
+ Here is the call graph for this function:

◆ addHeader()

ilECSConnector::addHeader ( string  $a_name,
string  $a_value 
)

◆ addResource()

ilECSConnector::addResource ( string  $a_path,
  $a_post 
)

Add resource.

public

Parameters
string$a_pathresource "path"
array | string$a_postpost data
Returns
int new econtent id
Exceptions
ilECSConnectorException

Definition at line 309 of file class.ilECSConnector.php.

References $info, _fetchEContentIdFromHeader(), addHeader(), call(), getHeader(), ILIAS\Repository\logger(), and prepareConnection().

309  : int
310  {
311  $this->logger->info(__METHOD__ . ': Add new EContent...');
312 
313  $this->path_postfix = $a_path;
314 
315  try {
316  $this->prepareConnection();
317 
318  $this->addHeader('Content-Type', 'application/json');
319 
320  $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
321  $this->curl->setOpt(CURLOPT_HEADER, true);
322  $this->curl->setOpt(CURLOPT_POST, true);
323  $this->curl->setOpt(CURLOPT_POSTFIELDS, $a_post);
324  $this->call();
325 
326  $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
327 
328  $this->logger->debug(__METHOD__ . ': Checking HTTP status...');
329  if ($info !== self::HTTP_CODE_CREATED) {
330  $this->logger->debug(__METHOD__ . ': Cannot create econtent, did not receive HTTP 201. ');
331  throw new ilECSConnectorException('Received HTTP status code: ' . $info);
332  }
333  $this->logger->debug(__METHOD__ . ': ... got HTTP 201 (created)');
334 
335  return $this->_fetchEContentIdFromHeader($this->curl->getResponseHeaderArray());
336  } catch (ilCurlConnectionException $exc) {
337  throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
338  }
339  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addHeader(string $a_name, string $a_value)
Add Header.
_fetchEContentIdFromHeader(array $a_header)
fetch new econtent id from location header
$info
Definition: entry_point.php:21
prepareConnection()
prepare connection
+ Here is the call graph for this function:

◆ call()

ilECSConnector::call ( )
protected

call peer

Returns
string|bool
Exceptions
ilCurlConnectionException

Definition at line 519 of file class.ilECSConnector.php.

References ILIAS\Repository\logger().

Referenced by addAuth(), ilECSEnrolmentStatusConnector\addEnrolmentStatus(), addResource(), ilECSCourseUrlConnector\addUrl(), deleteResource(), getAuth(), ilECSCourseConnector\getCourse(), ilECSCourseMemberConnector\getCourseMember(), ilECSDirectoryTreeConnector\getDirectoryTree(), ilECSDirectoryTreeConnector\getDirectoryTrees(), ilECSEnrolmentStatusConnector\getEnrolmentStatus(), getMemberships(), getResource(), getResourceList(), readEventFifo(), and updateResource().

520  {
521  try {
522  return $this->curl->exec();
523  } catch (ilCurlConnectionException $exc) {
524  $this->logger->error($exc->getMessage());
525  throw($exc);
526  }
527  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deleteResource()

ilECSConnector::deleteResource ( string  $a_path,
int  $a_econtent_id 
)

Delete resource.

Parameters
string$a_pathresource "path"
int$a_econtent_idecontent id
Exceptions
ilECSConnectorException

Definition at line 404 of file class.ilECSConnector.php.

References $info, $res, call(), ILIAS\Repository\logger(), null, and prepareConnection().

404  : ?ilECSResult
405  {
406  $this->logger->debug(__METHOD__ . ': Delete resource with id ' . $a_econtent_id);
407 
408  $this->path_postfix = $a_path;
409 
410  if ($a_econtent_id) {
411  $this->path_postfix .= ('/' . $a_econtent_id);
412  } else {
413  throw new ilECSConnectorException('Error calling deleteResource: No content id given.');
414  }
415 
416  try {
417  $this->prepareConnection();
418  $this->curl->setOpt(CURLOPT_CUSTOMREQUEST, 'DELETE');
419  $res = $this->call();
420  $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
421  if (200 === $info) {
422  return new ilECSResult($res);
423  }
424  return null;
425  } catch (ilCurlConnectionException $exc) {
426  throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
427  }
428  }
$res
Definition: ltiservices.php:66
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$info
Definition: entry_point.php:21
prepareConnection()
prepare connection
+ Here is the call graph for this function:

◆ getAuth()

ilECSConnector::getAuth ( string  $a_hash,
bool  $a_details_only = false 
)

get auth resource

Returns
ilECSResult|ilECSEContentDetails
Exceptions
ilECSConnectorException

Definition at line 147 of file class.ilECSConnector.php.

References $info, $res, call(), ILIAS\Repository\logger(), and prepareConnection().

148  {
149  if ($a_hash === '') {
150  $this->logger->error(__METHOD__ . ': No auth hash given. Aborting.');
151  throw new ilECSConnectorException('No auth hash given.');
152  }
153 
154  $this->path_postfix = '/sys/auths/' . $a_hash;
155 
156  if ($a_details_only) {
157  $this->path_postfix .= ('/details');
158  }
159 
160 
161  try {
162  $this->prepareConnection();
163  $res = $this->call();
164  $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
165 
166  $this->logger->info(__METHOD__ . ': Checking HTTP status...');
167  if ($info !== self::HTTP_CODE_OK) {
168  $this->logger->info(__METHOD__ . ': Cannot get auth resource, did not receive HTTP 200. ');
169  throw new ilECSConnectorException('Received HTTP status code: ' . $info);
170  }
171  $this->logger->info(__METHOD__ . ': ... got HTTP 200 (ok)');
172 
173  $ecs_result = new ilECSResult($res);
174  // Return ECSEContentDetails for details switch
175  if ($a_details_only) {
176  $details = new ilECSEContentDetails();
177  $details->loadFromJson($ecs_result->getResult());
178  return $details;
179  }
180  return $ecs_result;
181  } catch (ilCurlConnectionException $exc) {
182  throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
183  }
184  }
$res
Definition: ltiservices.php:66
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Presentation of ecs content details (http://...campusconnect/courselinks/id/details) ...
$info
Definition: entry_point.php:21
prepareConnection()
prepare connection
+ Here is the call graph for this function:

◆ getHeader()

◆ getMemberships()

ilECSConnector::getMemberships ( int  $a_mid = 0)
Parameters
int$a_midmembership id
Exceptions
ilECSConnectorException

Definition at line 438 of file class.ilECSConnector.php.

References $info, $res, call(), ILIAS\Repository\logger(), and prepareConnection().

438  : ilECSResult
439  {
440  $this->logger->debug(__METHOD__ . ': Get existing memberships');
441 
442  $this->path_postfix = '/sys/memberships';
443  if ($a_mid) {
444  $this->logger->debug(__METHOD__ . ': Read membership with id: ' . $a_mid);
445  $this->path_postfix .= ('/' . $a_mid);
446  }
447  try {
448  $this->prepareConnection();
449  $res = $this->call();
450 
451  $this->curl->setOpt(CURLOPT_HTTPHEADER, array(0 => 'X-EcsQueryStrings: sender=true'));
452 
453  // Checking status code
454  $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
455  if ($info !== self::HTTP_CODE_OK) {
456  $this->logger->debug(__METHOD__ . ': Cannot get memberships, did not receive HTTP 200. ');
457  throw new ilECSConnectorException('Received HTTP status code: ' . $info);
458  }
459 
460  return new ilECSResult($res);
461  } catch (ilCurlConnectionException $exc) {
462  throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage() . $exc->getTraceAsString(), 0, $exc);
463  }
464  }
$res
Definition: ltiservices.php:66
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$info
Definition: entry_point.php:21
prepareConnection()
prepare connection
+ Here is the call graph for this function:

◆ getResource()

ilECSConnector::getResource ( string  $a_path,
int  $a_econtent_id,
bool  $a_details_only = false 
)

Get resources from ECS server.

Exceptions
ilECSConnectorException

Definition at line 259 of file class.ilECSConnector.php.

References $info, $res, call(), ILIAS\Repository\int(), ILIAS\Repository\logger(), and prepareConnection().

259  : ilECSResult
260  {
261  // TODO make handling of a_econtent_id explict like setting it to null
262  if ($a_econtent_id) {
263  $this->logger->debug(__METHOD__ . ': Get resource with ID: ' . $a_econtent_id);
264  } else {
265  $this->logger->debug(__METHOD__ . ': Get all resources ...');
266  }
267 
268  $this->path_postfix = $a_path;
269  if ($a_econtent_id) {
270  $this->path_postfix .= ('/' . $a_econtent_id);
271  }
272  if ($a_details_only) {
273  $this->path_postfix .= ('/details');
274  }
275 
276  try {
277  $this->prepareConnection();
278  $res = $this->call();
279 
280  // Checking status code
281  $info = (int) $this->curl->getInfo(CURLINFO_HTTP_CODE);
282  $this->logger->debug(__METHOD__ . ': Checking HTTP status...');
283  if ($info !== self::HTTP_CODE_OK) {
284  $this->logger->debug(__METHOD__ . ': Cannot get ressource, did not receive HTTP 200. ');
285  throw new ilECSConnectorException('Received HTTP status code: ' . $info);
286  }
287  $this->logger->debug(__METHOD__ . ': ... got HTTP 200 (ok)');
288 
289  $result = new ilECSResult($res);
290  $result->setHeaders($this->curl->getResponseHeaderArray());
291  $result->setHTTPCode($info);
292 
293  return $result;
294  } catch (ilCurlConnectionException $exc) {
295  throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
296  }
297  }
$res
Definition: ltiservices.php:66
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$info
Definition: entry_point.php:21
prepareConnection()
prepare connection
+ Here is the call graph for this function:

◆ getResourceList()

ilECSConnector::getResourceList ( string  $a_path)

Definition at line 229 of file class.ilECSConnector.php.

References $info, $res, call(), getHeader(), ILIAS\Repository\logger(), prepareConnection(), and ilECSResult\RESULT_TYPE_URL_LIST.

229  : ilECSResult
230  {
231  $this->path_postfix = $a_path;
232 
233  try {
234  $this->prepareConnection();
235  $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
236  $res = $this->call();
237 
238  // Checking status code
239  $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
240  $this->logger->debug(__METHOD__ . ': Checking HTTP status...');
241  if ($info !== self::HTTP_CODE_OK) {
242  $this->logger->debug(__METHOD__ . ': Cannot get ressource list, did not receive HTTP 200. ');
243  throw new ilECSConnectorException('Received HTTP status code: ' . $info);
244  }
245  $this->logger->debug(__METHOD__ . ': ... got HTTP 200 (ok)');
246 
248  } catch (ilCurlConnectionException $exc) {
249  throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
250  }
251  }
const RESULT_TYPE_URL_LIST
$res
Definition: ltiservices.php:66
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$info
Definition: entry_point.php:21
prepareConnection()
prepare connection
+ Here is the call graph for this function:

◆ getServer()

ilECSConnector::getServer ( )

Get current server setting.

Definition at line 81 of file class.ilECSConnector.php.

References $settings.

Referenced by prepareConnection().

81  : ilECSSetting
82  {
83  return $this->settings;
84  }
ilECSSetting $settings
+ Here is the caller graph for this function:

◆ prepareConnection()

ilECSConnector::prepareConnection ( )
protected

prepare connection

Exceptions
ilCurlConnectionException

Definition at line 471 of file class.ilECSConnector.php.

References $path_postfix, ilECSSetting\AUTH_APACHE, ilECSSetting\AUTH_CERTIFICATE, ilLogLevel\DEBUG, getServer(), ilCurlConnection\init(), ILIAS\Repository\logger(), and ILIAS\Repository\settings().

Referenced by addAuth(), ilECSEnrolmentStatusConnector\addEnrolmentStatus(), addResource(), ilECSCourseUrlConnector\addUrl(), deleteResource(), getAuth(), ilECSCourseConnector\getCourse(), ilECSCourseMemberConnector\getCourseMember(), ilECSDirectoryTreeConnector\getDirectoryTree(), ilECSDirectoryTreeConnector\getDirectoryTrees(), ilECSEnrolmentStatusConnector\getEnrolmentStatus(), getMemberships(), getResource(), getResourceList(), readEventFifo(), and updateResource().

471  : void
472  {
473  try {
474  $this->curl = new ilCurlConnection($this->settings->getServerURI() . $this->path_postfix);
475  $this->curl->init(true);
476  $this->curl->setOpt(CURLOPT_HTTPHEADER, array(0 => 'Accept: application/json'));
477  $this->curl->setOpt(CURLOPT_RETURNTRANSFER, 1);
478  $this->curl->setOpt(CURLOPT_TIMEOUT_MS, 90000);
479  $this->curl->setOpt(CURLOPT_FORBID_REUSE, true);
480  $this->curl->setOpt(CURLOPT_FRESH_CONNECT, true);
481 
482  if ($this->logger->isHandling(ilLogLevel::DEBUG)) {
483  $this->curl->setOpt(CURLOPT_VERBOSE, 1);
484  }
485 
486  switch ($this->getServer()->getAuthType()) {
488  $this->curl->setOpt(CURLOPT_SSL_VERIFYPEER, 1);
489  #$this->curl->setOpt(CURLOPT_SSL_VERIFYHOST,0);
490  $this->curl->setOpt(CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
491  $this->curl->setOpt(
492  CURLOPT_USERPWD,
493  $this->getServer()->getAuthUser() . ':' . $this->getServer()->getAuthPass()
494  );
495  break;
496 
498  $this->curl->setOpt(CURLOPT_SSL_VERIFYPEER, 1);
499  // use default 2 for libcurl 7.28.1 support
500  $this->curl->setOpt(CURLOPT_SSL_VERIFYHOST, 2);
501  $this->curl->setOpt(CURLOPT_CAINFO, $this->settings->getCACertPath());
502  $this->curl->setOpt(CURLOPT_SSLCERT, $this->settings->getClientCertPath());
503  $this->curl->setOpt(CURLOPT_SSLKEY, $this->settings->getKeyPath());
504  $this->curl->setOpt(CURLOPT_SSLKEYPASSWD, $this->settings->getKeyPassword());
505  break;
506  }
507  } catch (ilCurlConnectionException $exc) {
508  throw($exc);
509  }
510  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
init(bool $set_proxy=true)
getServer()
Get current server setting.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readEventFifo()

ilECSConnector::readEventFifo ( bool  $a_delete = false)

Read event fifo.

Parameters
bool$a_deleteset to true for deleting the current element
Exceptions
ilECSConnectorException

Definition at line 195 of file class.ilECSConnector.php.

References $info, $res, addHeader(), call(), ILIAS\Repository\logger(), and prepareConnection().

195  : ilECSResult
196  {
197  $this->path_postfix = '/sys/events/fifo';
198 
199  try {
200  $this->prepareConnection();
201  $this->addHeader('Content-Type', 'application/json');
202  $this->addHeader('Accept', 'application/json');
203 
204  if ($a_delete) {
205  $this->curl->setOpt(CURLOPT_POST, true);
206  $this->curl->setOpt(CURLOPT_POSTFIELDS, '');
207  }
208  $res = $this->call();
209 
210  // Checking status code
211  $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
212  if ($info !== self::HTTP_CODE_OK) {
213  $this->logger->info(__METHOD__ . ': Cannot read event fifo, did not receive HTTP 200. ');
214  throw new ilECSConnectorException('Received HTTP status code: ' . $info);
215  }
216  //TODO check if this return needs to be moved after the finally
217  return new ilECSResult($res);
218  } catch (ilCurlConnectionException $exc) {
219  throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
220  } finally {
221  $this->curl->close();
222  }
223  }
$res
Definition: ltiservices.php:66
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addHeader(string $a_name, string $a_value)
Add Header.
$info
Definition: entry_point.php:21
prepareConnection()
prepare connection
+ Here is the call graph for this function:

◆ setHeader()

ilECSConnector::setHeader ( array  $a_header_strings)

Definition at line 73 of file class.ilECSConnector.php.

Referenced by ilECSCourseConnector\getCourse(), ilECSCourseMemberConnector\getCourseMember(), ilECSDirectoryTreeConnector\getDirectoryTree(), ilECSDirectoryTreeConnector\getDirectoryTrees(), and ilECSEnrolmentStatusConnector\getEnrolmentStatus().

73  : void
74  {
75  $this->header_strings = $a_header_strings;
76  }
+ Here is the caller graph for this function:

◆ updateResource()

ilECSConnector::updateResource ( string  $a_path,
int  $a_econtent_id,
string  $a_post_string 
)

update resource

Parameters
string$a_pathresource "path"
int$a_econtent_idecontent id
string$a_post_stringpost content
Exceptions
ilECSConnectorException

Definition at line 349 of file class.ilECSConnector.php.

References $info, $res, addHeader(), call(), getHeader(), ilFileUtils\ilTempnam(), ILIAS\Repository\logger(), and prepareConnection().

349  : void
350  {
351  $this->logger->debug(__METHOD__ . ': Update resource with id ' . $a_econtent_id);
352 
353  $this->path_postfix = $a_path;
354 
355  if ($a_econtent_id) {
356  $this->path_postfix .= ('/' . $a_econtent_id);
357  } else {
358  throw new ilECSConnectorException('Error calling updateResource: No content id given.');
359  }
360  try {
361  $this->prepareConnection();
362  $this->addHeader('Content-Type', 'application/json');
363  $this->addHeader('Accept', 'application/json');
364  $this->addHeader('Expect', '');
365  $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
366  $this->curl->setOpt(CURLOPT_HEADER, true);
367  $this->curl->setOpt(CURLOPT_PUT, true);
368  //TODO migrate to filesystem->tempfile
369  $tempfile = ilFileUtils::ilTempnam();
370  $this->logger->info(__METHOD__ . ': Created new tempfile: ' . $tempfile);
371 
372  $fp = fopen($tempfile, 'wb');
373  fwrite($fp, $a_post_string);
374  fclose($fp);
375 
376  $this->curl->setOpt(CURLOPT_UPLOAD, true);
377  $this->curl->setOpt(CURLOPT_INFILESIZE, filesize($tempfile));
378  $fp = fopen($tempfile, 'rb');
379  $this->curl->setOpt(CURLOPT_INFILE, $fp);
380 
381  $res = $this->call();
382 
383  fclose($fp);
384  unlink($tempfile);
385 
386  $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
387  $this->logger->debug(__METHOD__ . ': Checking HTTP status...');
388  if ($info !== self::HTTP_CODE_OK) {
389  $this->logger->debug(__METHOD__ . ': Cannot update resource. ', $a_path, $a_econtent_id);
390  throw new ilECSConnectorException('Received HTTP status code: ' . $info);
391  }
392  } catch (ilCurlConnectionException $exc) {
393  throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
394  }
395  }
$res
Definition: ltiservices.php:66
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addHeader(string $a_name, string $a_value)
Add Header.
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
$info
Definition: entry_point.php:21
prepareConnection()
prepare connection
+ Here is the call graph for this function:

Field Documentation

◆ $curl

ilCurlConnection ilECSConnector::$curl = null
protected

Definition at line 38 of file class.ilECSConnector.php.

◆ $header_strings

array ilECSConnector::$header_strings = []
protected

Definition at line 40 of file class.ilECSConnector.php.

Referenced by getHeader().

◆ $logger

ilLogger ilECSConnector::$logger
protected

Definition at line 42 of file class.ilECSConnector.php.

◆ $path_postfix

string ilECSConnector::$path_postfix = ''
protected

Definition at line 35 of file class.ilECSConnector.php.

Referenced by prepareConnection().

◆ $settings

ilECSSetting ilECSConnector::$settings = null
protected

Definition at line 37 of file class.ilECSConnector.php.

Referenced by __construct(), and getServer().

◆ HEADER_COMMUNITIES

const ilECSConnector::HEADER_COMMUNITIES = 'X-EcsReceiverCommunities'

Definition at line 32 of file class.ilECSConnector.php.

◆ HEADER_MEMBERSHIPS

const ilECSConnector::HEADER_MEMBERSHIPS = 'X-EcsReceiverMemberships'

◆ HTTP_CODE_CREATED

const ilECSConnector::HTTP_CODE_CREATED = 201

Definition at line 27 of file class.ilECSConnector.php.

◆ HTTP_CODE_NOT_FOUND

const ilECSConnector::HTTP_CODE_NOT_FOUND = 404

◆ HTTP_CODE_OK

const ilECSConnector::HTTP_CODE_OK = 200

Definition at line 28 of file class.ilECSConnector.php.


The documentation for this class was generated from the following file: