/** * Get data from server * * @param int $a_server_id * @param int $a_econtent_id * @param string $a_resource_type * @return ilECSEContentDetails */ public static function getInstance($a_server_id, $a_econtent_id, $a_resource_type) { global $ilLog; try { include_once './Services/WebServices/ECS/classes/class.ilECSSetting.php'; include_once './Services/WebServices/ECS/classes/class.ilECSConnector.php'; $connector = new ilECSConnector(ilECSSetting::getInstanceByServerId($a_server_id)); $res = $connector->getResource($a_resource_type, $a_econtent_id, true); if ($res->getHTTPCode() == ilECSConnector::HTTP_CODE_NOT_FOUND) { return; } if (!is_object($res->getResult())) { $ilLog->write(__METHOD__ . ': Error parsing result. Expected result of type array.'); $ilLog->logStack(); throw new ilECSConnectorException('error parsing json'); } } catch (ilECSConnectorException $exc) { return; } include_once './Services/WebServices/ECS/classes/class.ilECSEContentDetails.php'; $details = new self(); $details->loadFromJSON($res->getResult()); return $details; }
/** * Constructor * @param ilECSSetting $settings */ public function __construct(ilECSSetting $settings = null) { parent::__construct($settings); }
/** * Fetch events from fifo * Using fifo * @access public * @throws ilECSConnectorException */ public function refresh() { try { include_once 'Services/WebServices/ECS/classes/class.ilECSConnector.php'; include_once 'Services/WebServices/ECS/classes/class.ilECSConnectorException.php'; $connector = new ilECSConnector($this->getServer()); while (true) { $res = $connector->readEventFifo(false); if (!count($res->getResult())) { return true; } foreach ($res->getResult() as $result) { include_once './Services/WebServices/ECS/classes/class.ilECSEvent.php'; $event = new ilECSEvent($result); $GLOBALS['ilLog']->write(__METHOD__ . ' ---------------------------- Handling new event '); $GLOBALS['ilLog']->write(__METHOD__ . print_r($event, true)); $GLOBALS['ilLog']->write(__METHOD__ . ' ---------------------------- Done! '); // Fill command queue $this->writeEventToDB($event); } // Delete from fifo $connector->readEventFifo(true); } } catch (ilECSConnectorException $e) { $GLOBALS['ilLog']->write(__METHOD__ . ': Cannot read event fifo. Aborting'); } }
/** * Get all available resources * * @param ilECSSetting $a_server * @param bool $a_sender_only * @return array */ public function getAllResourceIds(ilECSSetting $a_server, $a_sender_only = false) { global $ilLog; try { include_once './Services/WebServices/ECS/classes/class.ilECSConnector.php'; $connector = new ilECSConnector($a_server); $connector->addHeader('X-EcsQueryStrings', $a_sender_only ? 'sender=true' : 'all=true'); // #11301 $list = $connector->getResourceList($this->getECSObjectType()); if ($list instanceof ilECSResult) { return $list->getResult()->getLinkIds(); } } catch (ilECSConnectorException $exc) { $ilLog->write(__METHOD__ . ': Error getting resource list. ' . $exc->getMessage()); } }
/** * Delete ECS resource * * as it is called from self::_handleDelete() it has to be public... * * @param type $a_server_id * @throws ilECSConnectorException */ public function doDelete(ilECSSetting $a_server, ilECSExport $a_export_settings) { global $ilLog; // already exported? if ($a_export_settings->isExported()) { include_once './Services/WebServices/ECS/classes/class.ilECSSetting.php'; include_once './Services/WebServices/ECS/classes/class.ilECSConnector.php'; $econtent_id = $a_export_settings->getEContentId(); if (!$econtent_id) { $ilLog->write(__METHOD__ . ': Missing eid. Aborting.'); throw new ilECSConnectorException('Missing ECS content ID. Aborting.'); } $connector = new ilECSConnector($a_server); $ilLog->write(__METHOD__ . ': Start deleting ECS content...'); $connector->deleteResource($this->getECSObjectType(), $econtent_id); // status changed $a_export_settings->setExported(false); $a_export_settings->save(); } }
/** * Validate ECS hash * * @access public * @param string username * @param string pass * */ public function validateHash() { global $ilLog; // fetch hash if (isset($_GET['ecs_hash']) and strlen($_GET['ecs_hash'])) { $hash = $_GET['ecs_hash']; } if (isset($_GET['ecs_hash_url'])) { $hashurl = urldecode($_GET['ecs_hash_url']); $hash = basename(parse_url($hashurl, PHP_URL_PATH)); //$hash = urldecode($_GET['ecs_hash_url']); } $GLOBALS['ilLog']->write(__METHOD__ . ': Using ecs hash ' . $hash); // Check if hash is valid ... try { include_once './Services/WebServices/ECS/classes/class.ilECSConnector.php'; $connector = new ilECSConnector($this->getCurrentServer()); $res = $connector->getAuth($hash); $auths = $res->getResult(); $this->abreviation = $auths->abbr; $ilLog->write(__METHOD__ . ': Got abr: ' . $this->abreviation); return true; } catch (ilECSConnectorException $e) { $ilLog->write(__METHOD__ . ': Authentication failed with message: ' . $e->getMessage()); return false; } }
/** * Validate ECS hash * * @access public * @param string username * @param string pass * */ public function validateHash() { global $ilLog; // fetch hash if (isset($_GET['ecs_hash']) and strlen($_GET['ecs_hash'])) { $hash = $_GET['ecs_hash']; } if (isset($_GET['ecs_hash_url'])) { $hashurl = urldecode($_GET['ecs_hash_url']); $hash = basename(parse_url($hashurl, PHP_URL_PATH)); //$hash = urldecode($_GET['ecs_hash_url']); } $GLOBALS['ilLog']->write(__METHOD__ . ': Using ecs hash ' . $hash); // Check if hash is valid ... try { include_once './Services/WebServices/ECS/classes/class.ilECSConnector.php'; $connector = new ilECSConnector($this->getCurrentServer()); $res = $connector->getAuth($hash); $auths = $res->getResult(); $GLOBALS['ilLog']->write(__METHOD__ . ': Auths: ' . print_r($auths, TRUE)); if ($auths->pid) { try { include_once './Services/WebServices/ECS/classes/class.ilECSCommunityReader.php'; $reader = ilECSCommunityReader::getInstanceByServerId($this->getCurrentServer()->getServerId()); $part = $reader->getParticipantByMID($auths->pid); if (is_object($part) and is_object($part->getOrganisation())) { $this->abreviation = $part->getOrganisation()->getAbbreviation(); } else { $this->abreviation = $auths->abbr; } } catch (Exception $e) { $ilLog->write(__METHOD__ . ': Authentication failed with message: ' . $e->getMessage()); return false; } } else { $this->abreviation = $auths->abbr; } $ilLog->write(__METHOD__ . ': Got abr: ' . $this->abreviation); } catch (ilECSConnectorException $e) { $ilLog->write(__METHOD__ . ': Authentication failed with message: ' . $e->getMessage()); return false; } // read current mid try { include_once './Services/WebServices/ECS/classes/class.ilECSConnector.php'; $connector = new ilECSConnector($this->getCurrentServer()); $details = $connector->getAuth($hash, TRUE); $GLOBALS['ilLog']->write(__METHOD__ . ': ' . print_r($details, TRUE)); $GLOBALS['ilLog']->write(__METHOD__ . ': Token created for mid ' . $details->getFirstSender()); $this->setMID($details->getFirstSender()); } catch (ilECSConnectorException $e) { $ilLog->write(__METHOD__ . ': Receiving mid failed with message: ' . $e->getMessage()); return false; } return TRUE; }