ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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()
 

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 61 of file class.ilECSConnector.php.

References $GLOBALS, $settings, and settings().

62  {
63  if ($settings) {
64  $this->settings = $settings;
65  } else {
66  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': Using deprecated call');
67  $GLOBALS['DIC']['ilLog']->logStack();
68  }
69  }
settings()
Definition: settings.php:2
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
+ 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 632 of file class.ilECSConnector.php.

References $DIC, and $ilLog.

633  {
634  global $DIC;
635 
636  $ilLog = $DIC['ilLog'];
637 
638  if (!isset($a_header['Location'])) {
639  return false;
640  }
641  $end_path = strrpos($a_header['Location'], "/");
642 
643  if ($end_path === false) {
644  $ilLog->write(__METHOD__ . ': Cannot find path seperator.');
645  return false;
646  }
647  $econtent_id = substr($a_header['Location'], $end_path + 1);
648  $ilLog->write(__METHOD__ . ': Received EContentId ' . $econtent_id);
649  return (int) $econtent_id;
650  }
global $DIC
Definition: saml.php:7

◆ 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 115 of file class.ilECSConnector.php.

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

116  {
117  global $DIC;
118 
119  $ilLog = $DIC['ilLog'];
120 
121  $ilLog->write(__METHOD__ . ': Add new Auth resource...');
122 
123  $this->path_postfix = '/sys/auths';
124 
125  try {
126  $this->prepareConnection();
127 
128  $this->addHeader('Content-Type', 'application/json');
129  $this->addHeader('Accept', 'application/json');
130  $this->addHeader(ilECSConnector::HEADER_MEMBERSHIPS, $a_target_mid);
131  #$this->addHeader(ilECSConnector::HEADER_MEMBERSHIPS, 1);
132 
133  $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
134  $this->curl->setOpt(CURLOPT_POST, true);
135  $this->curl->setOpt(CURLOPT_POSTFIELDS, $a_post);
136  $ret = $this->call();
137 
138  $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
139 
140  $ilLog->write(__METHOD__ . ': Checking HTTP status...');
141  if ($info != self::HTTP_CODE_CREATED) {
142  $ilLog->write(__METHOD__ . ': Cannot create auth resource, did not receive HTTP 201. ');
143  $ilLog->write(__METHOD__ . ': POST was: ' . $a_post);
144  $ilLog->write(__METHOD__ . ': HTTP code: ' . $info);
145  throw new ilECSConnectorException('Received HTTP status code: ' . $info);
146  }
147  $ilLog->write(__METHOD__ . ': ... got HTTP 201 (created)');
148  $ilLog->write(__METHOD__ . ': POST was: ' . $a_post);
149 
150  $result = new ilECSResult($ret);
151  $auth = $result->getResult();
152 
153  $ilLog->write(__METHOD__ . ': ... got hash: ' . $auth->hash);
154 
155  return $auth->hash;
156  } catch (ilCurlConnectionException $exc) {
157  throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
158  }
159  }
$result
global $DIC
Definition: saml.php:7
$auth
Definition: fileserver.php:48
$ret
Definition: parser.php:6
addHeader($a_name, $a_value)
Add Header.
prepareConnection()
prepare connection
$info
Definition: index.php:5
+ 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 395 of file class.ilECSConnector.php.

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

396  {
397  global $DIC;
398 
399  $ilLog = $DIC['ilLog'];
400 
401  $ilLog->write(__METHOD__ . ': Add new EContent...');
402 
403  $this->path_postfix = $a_path;
404 
405  try {
406  $this->prepareConnection();
407 
408  $this->addHeader('Content-Type', 'application/json');
409 
410  $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
411  $this->curl->setOpt(CURLOPT_HEADER, true);
412  $this->curl->setOpt(CURLOPT_POST, true);
413  $this->curl->setOpt(CURLOPT_POSTFIELDS, $a_post);
414  $res = $this->call();
415 
416  $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
417 
418  $ilLog->write(__METHOD__ . ': Checking HTTP status...');
419  if ($info != self::HTTP_CODE_CREATED) {
420  $ilLog->write(__METHOD__ . ': Cannot create econtent, did not receive HTTP 201. ');
421  throw new ilECSConnectorException('Received HTTP status code: ' . $info);
422  }
423  $ilLog->write(__METHOD__ . ': ... got HTTP 201 (created)');
424 
425  $eid = self::_fetchEContentIdFromHeader($this->curl->getResponseHeaderArray());
426  return $eid;
427  } catch (ilCurlConnectionException $exc) {
428  throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
429  }
430  }
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
addHeader($a_name, $a_value)
Add Header.
prepareConnection()
prepare connection
$info
Definition: index.php:5
+ 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 495 of file class.ilECSConnector.php.

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

496  {
497  global $DIC;
498 
499  $ilLog = $DIC['ilLog'];
500 
501  $ilLog->write(__METHOD__ . ': Delete resource with id ' . $a_econtent_id);
502 
503  $this->path_postfix = $a_path;
504 
505  if ($a_econtent_id) {
506  $this->path_postfix .= ('/' . (int) $a_econtent_id);
507  } else {
508  throw new ilECSConnectorException('Error calling deleteResource: No content id given.');
509  }
510 
511  try {
512  $this->prepareConnection();
513  $this->curl->setOpt(CURLOPT_CUSTOMREQUEST, 'DELETE');
514  $res = $this->call();
515  return new ilECSResult($res);
516  } catch (ilCurlConnectionException $exc) {
517  throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
518  }
519  }
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
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 168 of file class.ilECSConnector.php.

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

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

◆ getEventQueues()

ilECSConnector::getEventQueues ( )

get event queue

public

Exceptions
ilECSConnectorException
Deprecated:

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

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

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

◆ getHeader()

◆ getMemberships()

ilECSConnector::getMemberships (   $a_mid = 0)

public

Parameters
intmembership id
Exceptions
ilECSConnectorException

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

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

533  {
534  global $DIC;
535 
536  $ilLog = $DIC['ilLog'];
537 
538  $ilLog->write(__METHOD__ . ': Get existing memberships');
539 
540  $this->path_postfix = '/sys/memberships';
541  if ($a_mid) {
542  $ilLog->write(__METHOD__ . ': Read membership with id: ' . $a_mid);
543  $this->path_postfix .= ('/' . (int) $a_mid);
544  }
545  try {
546  $this->prepareConnection();
547  $res = $this->call();
548 
549  $this->curl->setOpt(CURLOPT_HTTPHEADER, array(0 => 'X-EcsQueryStrings: sender=true'));
550 
551  // Checking status code
552  $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
553  if ($info != self::HTTP_CODE_OK) {
554  $ilLog->write(__METHOD__ . ': Cannot get memberships, did not receive HTTP 200. ');
555  throw new ilECSConnectorException('Received HTTP status code: ' . $info);
556  }
557 
558  return new ilECSResult($res);
559  } catch (ilCurlConnectionException $exc) {
560  throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
561  }
562  }
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
prepareConnection()
prepare connection
$info
Definition: index.php:5
+ 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 342 of file class.ilECSConnector.php.

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

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

◆ getResourceList()

ilECSConnector::getResourceList (   $a_path)

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

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

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

◆ getServer()

ilECSConnector::getServer ( )

Get current server setting.

Returns
ilECSSetting

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

References $settings.

Referenced by prepareConnection().

97  {
98  return $this->settings;
99  }
+ Here is the caller graph for this function:

◆ prepareConnection()

ilECSConnector::prepareConnection ( )
protected

prepare connection

private

Exceptions
ilCurlConnectionException

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

References $path_postfix, ilECSSetting\AUTH_APACHE, ilECSSetting\AUTH_CERTIFICATE, 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().

571  {
572  try {
573  $this->curl = new ilCurlConnection($this->settings->getServerURI() . $this->path_postfix);
574  $this->curl->init();
575  $this->curl->setOpt(CURLOPT_HTTPHEADER, array(0 => 'Accept: application/json'));
576  $this->curl->setOpt(CURLOPT_RETURNTRANSFER, 1);
577  $this->curl->setOpt(CURLOPT_VERBOSE, 1);
578  $this->curl->setOpt(CURLOPT_TIMEOUT_MS, 2000);
579 
580  switch ($this->getServer()->getAuthType()) {
582  $this->curl->setOpt(CURLOPT_SSL_VERIFYPEER, 0);
583  #$this->curl->setOpt(CURLOPT_SSL_VERIFYHOST,0);
584  $this->curl->setOpt(CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
585  $this->curl->setOpt(
586  CURLOPT_USERPWD,
587  $this->getServer()->getAuthUser() . ':' . $this->getServer()->getAuthPass()
588  );
589  break;
590 
592  $this->curl->setOpt(CURLOPT_SSL_VERIFYPEER, 1);
593  // use default 2 for libcurl 7.28.1 support
594  $this->curl->setOpt(CURLOPT_SSL_VERIFYHOST, 2);
595  $this->curl->setOpt(CURLOPT_CAINFO, $this->settings->getCACertPath());
596  $this->curl->setOpt(CURLOPT_SSLCERT, $this->settings->getClientCertPath());
597  $this->curl->setOpt(CURLOPT_SSLKEY, $this->settings->getKeyPath());
598  $this->curl->setOpt(CURLOPT_SSLKEYPASSWD, $this->settings->getKeyPassword());
599  break;
600 
601  }
602  } catch (ilCurlConnectionException $exc) {
603  throw($exc);
604  }
605  }
settings()
Definition: settings.php:2
init()
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 258 of file class.ilECSConnector.php.

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

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

◆ setHeader()

ilECSConnector::setHeader (   $a_header_strings)

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

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

88  {
89  $this->header_strings = $a_header_strings;
90  }
+ 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 441 of file class.ilECSConnector.php.

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

442  {
443  global $DIC;
444 
445  $ilLog = $DIC['ilLog'];
446 
447  $ilLog->write(__METHOD__ . ': Update resource with id ' . $a_econtent_id);
448 
449  $this->path_postfix = $a_path;
450 
451  if ($a_econtent_id) {
452  $this->path_postfix .= ('/' . (int) $a_econtent_id);
453  } else {
454  throw new ilECSConnectorException('Error calling updateResource: No content id given.');
455  }
456  try {
457  $this->prepareConnection();
458  $this->addHeader('Content-Type', 'application/json');
459  $this->addHeader('Accept', 'application/json');
460  $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
461  $this->curl->setOpt(CURLOPT_HEADER, true);
462  $this->curl->setOpt(CURLOPT_PUT, true);
463 
464  $tempfile = ilUtil::ilTempnam();
465  $ilLog->write(__METHOD__ . ': Created new tempfile: ' . $tempfile);
466 
467  $fp = fopen($tempfile, 'w');
468  fwrite($fp, $a_post_string);
469  fclose($fp);
470 
471  $this->curl->setOpt(CURLOPT_UPLOAD, true);
472  $this->curl->setOpt(CURLOPT_INFILESIZE, filesize($tempfile));
473  $fp = fopen($tempfile, 'r');
474  $this->curl->setOpt(CURLOPT_INFILE, $fp);
475 
476  $res = $this->call();
477 
478  fclose($fp);
479  unlink($tempfile);
480 
481  return new ilECSResult($res);
482  } catch (ilCurlConnectionException $exc) {
483  throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
484  }
485  }
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
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().

◆ $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: