ILIAS  release_7 Revision v7.30-3-g800a261c036
ilECSConnector Class Reference
+ Inheritance diagram for ilECSConnector:
+ Collaboration diagram for ilECSConnector:

Public Member Functions

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

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...
 

Static Protected Member Functions

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

Protected Attributes

 $path_postfix = ''
 
 $settings
 
 $header_strings = array()
 
 $logger
 

Detailed Description

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

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

Constructor & Destructor Documentation

◆ __construct()

ilECSConnector::__construct ( ilECSSetting  $settings = null)

Constructor.

public

Parameters

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

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

67  {
68  global $DIC;
69 
70  $this->logger = $DIC->logger()->wsrv();
71  if ($settings) {
72  $this->settings = $settings;
73  } else {
74  $this->logger->warning('Using deprecated call.');
75  $this->logger->logStack(ilLogLevel::WARNING);
76  }
77  }
settings()
Definition: settings.php:2
global $DIC
Definition: goto.php:24
+ Here is the call graph for this function:

Member Function Documentation

◆ _fetchEContentIdFromHeader()

static ilECSConnector::_fetchEContentIdFromHeader (   $a_header)
staticprotected

fetch new econtent id from location header

public

Parameters
arrayheader array

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

References $DIC.

644  {
645  global $DIC;
646 
647  $ilLog = $DIC['ilLog'];
648  $location_parts = [];
649  foreach ($a_header as $header => $value) {
650  if (strcasecmp('Location', $header) == 0) {
651  $location_parts = explode('/', $value);
652  break;
653  }
654  }
655  if (!$location_parts) {
656  $ilLog->write(__METHOD__ . ': Cannot find location headers.');
657  return false;
658  }
659  if (count($location_parts) == 1) {
660  $ilLog->write(__METHOD__ . ': Cannot find path seperator.');
661  return false;
662  }
663  $econtent_id = end($location_parts);
664  $ilLog->write(__METHOD__ . ': Received EContentId ' . $econtent_id);
665  return (int) $econtent_id;
666  }
global $DIC
Definition: goto.php:24

◆ addAuth()

ilECSConnector::addAuth (   $a_post,
  $a_target_mid 
)

Add auth resource.

public

Parameters
stringpost data
Returns
int new econtent id
Exceptions
ilECSConnectorException

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

References $auth, $DIC, $result, $ret, addHeader(), call(), getHeader(), HEADER_MEMBERSHIPS, and prepareConnection().

124  {
125  global $DIC;
126 
127  $ilLog = $DIC['ilLog'];
128 
129  $ilLog->write(__METHOD__ . ': Add new Auth resource...');
130 
131  $this->path_postfix = '/sys/auths';
132 
133  try {
134  $this->prepareConnection();
135 
136  $this->addHeader('Content-Type', 'application/json');
137  $this->addHeader('Accept', 'application/json');
138  $this->addHeader(ilECSConnector::HEADER_MEMBERSHIPS, $a_target_mid);
139  #$this->addHeader(ilECSConnector::HEADER_MEMBERSHIPS, 1);
140 
141  $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
142  $this->curl->setOpt(CURLOPT_POST, true);
143  $this->curl->setOpt(CURLOPT_POSTFIELDS, $a_post);
144  $ret = $this->call();
145 
146  $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
147 
148  $ilLog->write(__METHOD__ . ': Checking HTTP status...');
149  if ($info != self::HTTP_CODE_CREATED) {
150  $ilLog->write(__METHOD__ . ': Cannot create auth resource, did not receive HTTP 201. ');
151  $ilLog->write(__METHOD__ . ': POST was: ' . $a_post);
152  $ilLog->write(__METHOD__ . ': HTTP code: ' . $info);
153  throw new ilECSConnectorException('Received HTTP status code: ' . $info);
154  }
155  $ilLog->write(__METHOD__ . ': ... got HTTP 201 (created)');
156  $ilLog->write(__METHOD__ . ': POST was: ' . $a_post);
157 
158  $result = new ilECSResult($ret);
159  $auth = $result->getResult();
160 
161  $ilLog->write(__METHOD__ . ': ... got hash: ' . $auth->hash);
162 
163  return $auth->hash;
164  } catch (ilCurlConnectionException $exc) {
165  throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
166  }
167  }
$result
$auth
Definition: metadata.php:59
global $DIC
Definition: goto.php:24
$ret
Definition: parser.php:6
addHeader($a_name, $a_value)
Add Header.
prepareConnection()
prepare connection
+ Here is the call graph for this function:

◆ addHeader()

ilECSConnector::addHeader (   $a_name,
  $a_value 
)

◆ addResource()

ilECSConnector::addResource (   $a_path,
  $a_post 
)

Add resource.

public

Parameters
stringresource "path"
stringpost data
Returns
int new econtent id
Exceptions
ilECSConnectorException

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

References $DIC, $res, addHeader(), call(), getHeader(), and prepareConnection().

404  {
405  global $DIC;
406 
407  $ilLog = $DIC['ilLog'];
408 
409  $ilLog->write(__METHOD__ . ': Add new EContent...');
410 
411  $this->path_postfix = $a_path;
412 
413  try {
414  $this->prepareConnection();
415 
416  $this->addHeader('Content-Type', 'application/json');
417 
418  $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
419  $this->curl->setOpt(CURLOPT_HEADER, true);
420  $this->curl->setOpt(CURLOPT_POST, true);
421  $this->curl->setOpt(CURLOPT_POSTFIELDS, $a_post);
422  $res = $this->call();
423 
424  $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
425 
426  $ilLog->write(__METHOD__ . ': Checking HTTP status...');
427  if ($info != self::HTTP_CODE_CREATED) {
428  $ilLog->write(__METHOD__ . ': Cannot create econtent, did not receive HTTP 201. ');
429  throw new ilECSConnectorException('Received HTTP status code: ' . $info);
430  }
431  $ilLog->write(__METHOD__ . ': ... got HTTP 201 (created)');
432 
433  $eid = self::_fetchEContentIdFromHeader($this->curl->getResponseHeaderArray());
434  return $eid;
435  } catch (ilCurlConnectionException $exc) {
436  throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
437  }
438  }
foreach($_POST as $key=> $value) $res
global $DIC
Definition: goto.php:24
addHeader($a_name, $a_value)
Add Header.
prepareConnection()
prepare connection
+ Here is the call graph for this function:

◆ call()

◆ deleteResource()

ilECSConnector::deleteResource (   $a_path,
  $a_econtent_id 
)

Delete resource.

public

Parameters
stringresource "path"
stringecontent id
Exceptions
ilECSConnectorException

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

References $DIC, $res, call(), and prepareConnection().

504  {
505  global $DIC;
506 
507  $ilLog = $DIC['ilLog'];
508 
509  $ilLog->write(__METHOD__ . ': Delete resource with id ' . $a_econtent_id);
510 
511  $this->path_postfix = $a_path;
512 
513  if ($a_econtent_id) {
514  $this->path_postfix .= ('/' . (int) $a_econtent_id);
515  } else {
516  throw new ilECSConnectorException('Error calling deleteResource: No content id given.');
517  }
518 
519  try {
520  $this->prepareConnection();
521  $this->curl->setOpt(CURLOPT_CUSTOMREQUEST, 'DELETE');
522  $res = $this->call();
523  return new ilECSResult($res);
524  } catch (ilCurlConnectionException $exc) {
525  throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
526  }
527  }
foreach($_POST as $key=> $value) $res
global $DIC
Definition: goto.php:24
prepareConnection()
prepare connection
+ Here is the call graph for this function:

◆ getAuth()

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

get auth resource

public

Parameters
authhash (transfered via GET)
Exceptions
ilECSConnectorException

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

References $DIC, $res, call(), and prepareConnection().

177  {
178  global $DIC;
179 
180  $ilLog = $DIC['ilLog'];
181 
182  if (!strlen($a_hash)) {
183  $ilLog->write(__METHOD__ . ': No auth hash given. Aborting.');
184  throw new ilECSConnectorException('No auth hash given.');
185  }
186 
187  $this->path_postfix = '/sys/auths/' . $a_hash;
188 
189  if ($a_details_only) {
190  $this->path_postfix .= ('/details');
191  }
192 
193 
194  try {
195  $this->prepareConnection();
196  $res = $this->call();
197  $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
198 
199  $ilLog->write(__METHOD__ . ': Checking HTTP status...');
200  if ($info != self::HTTP_CODE_OK) {
201  $ilLog->write(__METHOD__ . ': Cannot get auth resource, did not receive HTTP 200. ');
202  throw new ilECSConnectorException('Received HTTP status code: ' . $info);
203  }
204  $ilLog->write(__METHOD__ . ': ... got HTTP 200 (ok)');
205 
206  $ecs_result = new ilECSResult($res);
207  // Return ECSEContentDetails for details switch
208  if ($a_details_only) {
209  include_once './Services/WebServices/ECS/classes/class.ilECSEContentDetails.php';
210  $details = new ilECSEContentDetails();
211  $details->loadFromJson($ecs_result->getResult());
212  return $details;
213  }
214  return $ecs_result;
215  } catch (ilCurlConnectionException $exc) {
216  throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
217  }
218  }
Presentation of ecs content details (http://...campusconnect/courselinks/id/details) ...
foreach($_POST as $key=> $value) $res
global $DIC
Definition: goto.php:24
prepareConnection()
prepare connection
+ Here is the call graph for this function:

◆ getEventQueues()

ilECSConnector::getEventQueues ( )

get event queue

public

Exceptions
ilECSConnectorException
Deprecated:

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

References $DIC, $res, call(), and prepareConnection().

232  {
233  global $DIC;
234 
235  $ilLog = $DIC['ilLog'];
236 
237  $this->path_postfix = '/eventqueues';
238 
239  try {
240  $this->prepareConnection();
241 
242  $res = $this->call();
243  $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
244 
245  $ilLog->write(__METHOD__ . ': Checking HTTP status...');
246  if ($info != self::HTTP_CODE_OK) {
247  $ilLog->write(__METHOD__ . ': Cannot get event queue, did not receive HTTP 200. ');
248  throw new ilECSConnectorException('Received HTTP status code: ' . $info);
249  }
250  $ilLog->write(__METHOD__ . ': ... got HTTP 200 (ok)');
251  return new ilECSResult($res);
252  } catch (ilCurlConnectionException $exc) {
253  throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
254  }
255  }
foreach($_POST as $key=> $value) $res
global $DIC
Definition: goto.php:24
prepareConnection()
prepare connection
+ Here is the call graph for this function:

◆ getHeader()

◆ getMemberships()

ilECSConnector::getMemberships (   $a_mid = 0)

public

Parameters
intmembership id
Exceptions
ilECSConnectorException

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

References $DIC, $res, call(), and prepareConnection().

541  {
542  global $DIC;
543 
544  $ilLog = $DIC['ilLog'];
545 
546  $ilLog->write(__METHOD__ . ': Get existing memberships');
547 
548  $this->path_postfix = '/sys/memberships';
549  if ($a_mid) {
550  $ilLog->write(__METHOD__ . ': Read membership with id: ' . $a_mid);
551  $this->path_postfix .= ('/' . (int) $a_mid);
552  }
553  try {
554  $this->prepareConnection();
555  $res = $this->call();
556 
557  $this->curl->setOpt(CURLOPT_HTTPHEADER, array(0 => 'X-EcsQueryStrings: sender=true'));
558 
559  // Checking status code
560  $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
561  if ($info != self::HTTP_CODE_OK) {
562  $ilLog->write(__METHOD__ . ': Cannot get memberships, did not receive HTTP 200. ');
563  throw new ilECSConnectorException('Received HTTP status code: ' . $info);
564  }
565 
566  return new ilECSResult($res);
567  } catch (ilCurlConnectionException $exc) {
568  throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
569  }
570  }
foreach($_POST as $key=> $value) $res
global $DIC
Definition: goto.php:24
prepareConnection()
prepare connection
+ Here is the call graph for this function:

◆ getResource()

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

Get resources from ECS server.

public

Parameters
stringresource "path"
inte-content id
Returns
object ECSResult
Exceptions
ilECSConnectorException

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

References $DIC, $res, $result, call(), and prepareConnection().

351  {
352  global $DIC;
353 
354  $ilLog = $DIC['ilLog'];
355 
356  if ($a_econtent_id) {
357  $ilLog->write(__METHOD__ . ': Get resource with ID: ' . $a_econtent_id);
358  } else {
359  $ilLog->write(__METHOD__ . ': Get all resources ...');
360  }
361 
362  $this->path_postfix = $a_path;
363  if ($a_econtent_id) {
364  $this->path_postfix .= ('/' . (int) $a_econtent_id);
365  }
366  if ($a_details_only) {
367  $this->path_postfix .= ('/details');
368  }
369 
370  try {
371  $this->prepareConnection();
372  $res = $this->call();
373 
374  // Checking status code
375  $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
376  $ilLog->write(__METHOD__ . ': Checking HTTP status...');
377  if ($info != self::HTTP_CODE_OK) {
378  $ilLog->write(__METHOD__ . ': Cannot get ressource, did not receive HTTP 200. ');
379  throw new ilECSConnectorException('Received HTTP status code: ' . $info);
380  }
381  $ilLog->write(__METHOD__ . ': ... got HTTP 200 (ok)');
382 
383  $result = new ilECSResult($res);
384  $result->setHeaders($this->curl->getResponseHeaderArray());
385  $result->setHTTPCode($info);
386 
387  return $result;
388  } catch (ilCurlConnectionException $exc) {
389  throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
390  }
391  }
$result
foreach($_POST as $key=> $value) $res
global $DIC
Definition: goto.php:24
prepareConnection()
prepare connection
+ Here is the call graph for this function:

◆ getResourceList()

ilECSConnector::getResourceList (   $a_path)

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

References $DIC, $res, call(), getHeader(), prepareConnection(), and ilECSResult\RESULT_TYPE_URL_LIST.

311  {
312  global $DIC;
313 
314  $ilLog = $DIC['ilLog'];
315 
316  $this->path_postfix = $a_path;
317 
318  try {
319  $this->prepareConnection();
320  $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
321  $res = $this->call();
322 
323  // Checking status code
324  $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
325  $ilLog->write(__METHOD__ . ': Checking HTTP status...');
326  if ($info != self::HTTP_CODE_OK) {
327  $ilLog->write(__METHOD__ . ': Cannot get ressource list, did not receive HTTP 200. ');
328  throw new ilECSConnectorException('Received HTTP status code: ' . $info);
329  }
330  $ilLog->write(__METHOD__ . ': ... got HTTP 200 (ok)');
331 
333  } catch (ilCurlConnectionException $exc) {
334  throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
335  }
336  }
const RESULT_TYPE_URL_LIST
foreach($_POST as $key=> $value) $res
global $DIC
Definition: goto.php:24
prepareConnection()
prepare connection
+ Here is the call graph for this function:

◆ getServer()

ilECSConnector::getServer ( )

Get current server setting.

Returns
ilECSSetting

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

References $settings.

Referenced by prepareConnection().

105  {
106  return $this->settings;
107  }
+ Here is the caller graph for this function:

◆ prepareConnection()

ilECSConnector::prepareConnection ( )
protected

prepare connection

private

Exceptions
ilCurlConnectionException

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

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

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

579  {
580  try {
581  $this->curl = new ilCurlConnection($this->settings->getServerURI() . $this->path_postfix);
582  $this->curl->init(true);
583  $this->curl->setOpt(CURLOPT_HTTPHEADER, array(0 => 'Accept: application/json'));
584  $this->curl->setOpt(CURLOPT_RETURNTRANSFER, 1);
585  $this->curl->setOpt(CURLOPT_TIMEOUT_MS, 2000);
586 
587  if ($this->logger->isHandling(ilLogLevel::DEBUG)) {
588  $this->curl->setOpt(CURLOPT_VERBOSE, 1);
589  }
590 
591  switch ($this->getServer()->getAuthType()) {
593  $this->curl->setOpt(CURLOPT_SSL_VERIFYPEER, 0);
594  #$this->curl->setOpt(CURLOPT_SSL_VERIFYHOST,0);
595  $this->curl->setOpt(CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
596  $this->curl->setOpt(
597  CURLOPT_USERPWD,
598  $this->getServer()->getAuthUser() . ':' . $this->getServer()->getAuthPass()
599  );
600  break;
601 
603  $this->curl->setOpt(CURLOPT_SSL_VERIFYPEER, 1);
604  // use default 2 for libcurl 7.28.1 support
605  $this->curl->setOpt(CURLOPT_SSL_VERIFYHOST, 2);
606  $this->curl->setOpt(CURLOPT_CAINFO, $this->settings->getCACertPath());
607  $this->curl->setOpt(CURLOPT_SSLCERT, $this->settings->getClientCertPath());
608  $this->curl->setOpt(CURLOPT_SSLKEY, $this->settings->getKeyPath());
609  $this->curl->setOpt(CURLOPT_SSLKEYPASSWD, $this->settings->getKeyPassword());
610  break;
611 
612  }
613  } catch (ilCurlConnectionException $exc) {
614  throw($exc);
615  }
616  }
settings()
Definition: settings.php:2
init(bool $set_proxy=true)
Init curl connection.
getServer()
Get current server setting.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readEventFifo()

ilECSConnector::readEventFifo (   $a_delete = false)

Read event fifo.

Parameters
boolset to true for deleting the current element
Exceptions
ilECSConnectorException

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

References $DIC, $res, $result, addHeader(), call(), and prepareConnection().

267  {
268  global $DIC;
269 
270  $ilLog = $DIC['ilLog'];
271 
272  $this->path_postfix = '/sys/events/fifo';
273 
274  try {
275  $this->prepareConnection();
276  $this->addHeader('Content-Type', 'application/json');
277  $this->addHeader('Accept', 'application/json');
278 
279  if ($a_delete) {
280  $this->curl->setOpt(CURLOPT_POST, true);
281  $this->curl->setOpt(CURLOPT_POSTFIELDS, '');
282  }
283  $res = $this->call();
284 
285  // Checking status code
286  $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
287  #$ilLog->write(__METHOD__.': Checking HTTP status...');
288  if ($info != self::HTTP_CODE_OK) {
289  $ilLog->write(__METHOD__ . ': Cannot read event fifo, did not receive HTTP 200. ');
290  throw new ilECSConnectorException('Received HTTP status code: ' . $info);
291  }
292  #$ilLog->write(__METHOD__.': ... got HTTP 200 (ok)');
293 
294  $result = new ilECSResult($res);
295 
296  #$GLOBALS['DIC']['ilLog']->write(__METHOD__.':------------------------------------- FIFO content'. print_r($result,true));
297 
298  return $result;
299  } catch (ilCurlConnectionException $exc) {
300  throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
301  } finally {
302  $this->curl->close();
303  }
304  }
$result
foreach($_POST as $key=> $value) $res
global $DIC
Definition: goto.php:24
addHeader($a_name, $a_value)
Add Header.
prepareConnection()
prepare connection
+ Here is the call graph for this function:

◆ setHeader()

ilECSConnector::setHeader (   $a_header_strings)

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

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

96  {
97  $this->header_strings = $a_header_strings;
98  }
+ Here is the caller graph for this function:

◆ updateResource()

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

update resource

public

Parameters
stringresource "path"
intecontent id
stringpost content
Exceptions
ilECSConnectorException

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

References $DIC, $res, addHeader(), call(), getHeader(), ilUtil\ilTempnam(), and prepareConnection().

450  {
451  global $DIC;
452 
453  $ilLog = $DIC['ilLog'];
454 
455  $ilLog->write(__METHOD__ . ': Update resource with id ' . $a_econtent_id);
456 
457  $this->path_postfix = $a_path;
458 
459  if ($a_econtent_id) {
460  $this->path_postfix .= ('/' . (int) $a_econtent_id);
461  } else {
462  throw new ilECSConnectorException('Error calling updateResource: No content id given.');
463  }
464  try {
465  $this->prepareConnection();
466  $this->addHeader('Content-Type', 'application/json');
467  $this->addHeader('Accept', 'application/json');
468  $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
469  $this->curl->setOpt(CURLOPT_HEADER, true);
470  $this->curl->setOpt(CURLOPT_PUT, true);
471 
472  $tempfile = ilUtil::ilTempnam();
473  $ilLog->write(__METHOD__ . ': Created new tempfile: ' . $tempfile);
474 
475  $fp = fopen($tempfile, 'w');
476  fwrite($fp, $a_post_string);
477  fclose($fp);
478 
479  $this->curl->setOpt(CURLOPT_UPLOAD, true);
480  $this->curl->setOpt(CURLOPT_INFILESIZE, filesize($tempfile));
481  $fp = fopen($tempfile, 'r');
482  $this->curl->setOpt(CURLOPT_INFILE, $fp);
483 
484  $res = $this->call();
485 
486  fclose($fp);
487  unlink($tempfile);
488 
489  return new ilECSResult($res);
490  } catch (ilCurlConnectionException $exc) {
491  throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
492  }
493  }
foreach($_POST as $key=> $value) $res
global $DIC
Definition: goto.php:24
static ilTempnam($a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
addHeader($a_name, $a_value)
Add Header.
prepareConnection()
prepare connection
+ Here is the call graph for this function:

Field Documentation

◆ $header_strings

ilECSConnector::$header_strings = array()
protected

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

Referenced by getHeader().

◆ $logger

ilECSConnector::$logger
protected

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

◆ $path_postfix

ilECSConnector::$path_postfix = ''
protected

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

Referenced by prepareConnection().

◆ $settings

◆ HEADER_COMMUNITIES

const ilECSConnector::HEADER_COMMUNITIES = 'X-EcsReceiverCommunities'

Definition at line 45 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 40 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 41 of file class.ilECSConnector.php.


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