ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilECSEventQueueReader Class Reference

Reads ECS events and stores them in the database. More...

+ Collaboration diagram for ilECSEventQueueReader:

Public Member Functions

 __construct ($a_server_id)
 Constructor.
 getServer ()
 get server setting
 getEvents ()
 get all events
 deleteAll ()
 Delete all events.
 deleteAllEContentEvents (array $a_types)
 Delete all econtents.
 refresh ()
 Fetch events from fifo Using fifo public.
 shift ()
 get and delete the first event entry
 add ($a_type, $a_id, $a_op)
 add
 delete ($a_event_id)
 delete private
 read ()
 Read public.

Static Public Member Functions

static handleImportReset (ilECSSetting $server)
 Reread all imported econtent.
static handleExportReset (ilECSSetting $server)
 Handle export reset.
static deleteServer ($a_server_id)
 Delete by server id ilDB $ilDB.
static deleteByServerId ($a_server_id)

Data Fields

const TYPE_EXPORTED = 'exported'
const TYPE_DIRECTORY_TREES = 'directory_trees'
const TYPE_CMS_COURSES = 'courses'
const TYPE_CMS_COURSE_MEMBERS = 'course_members'
const TYPE_REMOTE_COURSE = 'rcrs'
const TYPE_REMOTE_CATEGORY = 'rcat'
const TYPE_REMOTE_FILE = 'rfil'
const TYPE_REMOTE_GLOSSARY = 'rglo'
const TYPE_REMOTE_GROUP = 'rgrp'
const TYPE_REMOTE_LEARNING_MODULE = 'rlm'
const TYPE_REMOTE_WIKI = 'rwik'
const TYPE_REMOTE_TEST = 'rtst'
const TYPE_COURSE_URLS = 'course_urls'

Protected Member Functions

 deleteAllExportedEvents ()
 Delete all exported events.

Static Protected Member Functions

static getEventTypeFromObjectType ($a_obj_type)
 Convert object type to event type.
static getAllEContentTypes ()
 All available content types.
static getAllResourceIds (ilECSSetting $server, array $a_types, $a_sender_only=false)
 Get all resource ids by resource type.

Protected Attributes

 $log
 $db
 $events = array()
 $econtent_ids = array()

Private Member Functions

 writeEventToDB (ilECSEvent $ev)
 Write event to db.
 update ($a_type, $a_id, $a_operation)
 update one entry

Detailed Description

Reads ECS events and stores them in the database.

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

Definition at line 36 of file class.ilECSEventQueueReader.php.

Constructor & Destructor Documentation

ilECSEventQueueReader::__construct (   $a_server_id)

Constructor.

public

Definition at line 63 of file class.ilECSEventQueueReader.php.

References $ilLog, ilECSSetting\getInstanceByServerId(), and read().

{
global $ilLog,$ilDB;
include_once('Services/WebServices/ECS/classes/class.ilECSSetting.php');
$this->settings = ilECSSetting::getInstanceByServerId($a_server_id);
$this->log = $ilLog;
$this->db = $ilDB;
$this->read();
}

+ Here is the call graph for this function:

Member Function Documentation

ilECSEventQueueReader::add (   $a_type,
  $a_id,
  $a_op 
)

add

public

Definition at line 542 of file class.ilECSEventQueueReader.php.

References $query, $res, and getServer().

{
global $ilDB;
$next_id = $ilDB->nextId('ecs_events');
$query = "INSERT INTO ecs_events (event_id,type,id,op,server_id) ".
"VALUES (".
$ilDB->quote($next_id,'integer').", ".
$this->db->quote($a_type,'text').", ".
$this->db->quote($a_id,'integer').", ".
$this->db->quote($a_op,'text').", ".
$ilDB->quote($this->getServer()->getServerId(),'integer').' '.
")";
$res = $ilDB->manipulate($query);
$new_event['event_id'] = $next_id;
$new_event['type'] = $a_type;
$new_event['id'] = $a_id;
$new_event['op'] = $a_op;
$this->events[] = $new_event;
$this->econtent_ids[$a_id] = $a_id;
return true;
}

+ Here is the call graph for this function:

ilECSEventQueueReader::delete (   $a_event_id)

delete private

Parameters
intevent id

Definition at line 591 of file class.ilECSEventQueueReader.php.

References $query, $res, and getServer().

{
global $ilDB;
$query = "DELETE FROM ecs_events ".
"WHERE event_id = ".$this->db->quote($a_event_id,'integer')." ".
'AND server_id = '.$ilDB->quote($this->getServer()->getServerId(),'integer');
$res = $ilDB->manipulate($query);
unset($this->econtent_ids[$a_event_id]);
return true;
}

+ Here is the call graph for this function:

ilECSEventQueueReader::deleteAll ( )

Delete all events.

public

Definition at line 295 of file class.ilECSEventQueueReader.php.

References $query, $res, and getServer().

{
global $ilDB;
$query = "DELETE FROM ecs_events ".
'WHERE server_id = '.$ilDB->quote($this->getServer()->getServerId(),'integer');
$res = $ilDB->manipulate($query);
return true;
}

+ Here is the call graph for this function:

ilECSEventQueueReader::deleteAllEContentEvents ( array  $a_types)

Delete all econtents.

public

Parameters
array$a_types

Definition at line 311 of file class.ilECSEventQueueReader.php.

References $query, $res, and getServer().

Referenced by handleImportReset().

{
global $ilDB;
$query = "DELETE FROM ecs_events ".
"WHERE ".$this->db->in("type", $a_types, "", "text").' '.
'AND server_id = '.$ilDB->quote($this->getServer()->getServerId(),'integer');
$res = $ilDB->manipulate($query);
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilECSEventQueueReader::deleteAllExportedEvents ( )
protected

Delete all exported events.

public

Definition at line 327 of file class.ilECSEventQueueReader.php.

References $query, $res, and getServer().

Referenced by handleExportReset().

{
global $ilDB;
$query = "DELETE FROM ecs_events ".
"WHERE type = ".$this->db->quote(self::TYPE_EXPORTED,'text').' '.
'AND server_id = '.$ilDB->quote($this->getServer()->getServerId(),'integer');
$res = $ilDB->manipulate($query);
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ilECSEventQueueReader::deleteByServerId (   $a_server_id)
static

Definition at line 630 of file class.ilECSEventQueueReader.php.

References $query.

Referenced by ilECSSetting\delete().

{
global $ilDB;
$query = 'DELETE FROM ecs_events'.
' WHERE server_id = '.$ilDB->quote($a_server_id,'integer');
$ilDB->manipulate($query);
return true;
}

+ Here is the caller graph for this function:

static ilECSEventQueueReader::deleteServer (   $a_server_id)
static

Delete by server id ilDB $ilDB.

Parameters
int$a_server_id

Definition at line 388 of file class.ilECSEventQueueReader.php.

References $query.

Referenced by ilECSSettingsGUI\doDelete().

{
global $ilDB;
$query = 'DELETE FROM ecs_events '.
'WHERE server_id = '.$ilDB->quote($a_server_id,'integer');
$ilDB->manipulate($query);
}

+ Here is the caller graph for this function:

static ilECSEventQueueReader::getAllEContentTypes ( )
staticprotected

All available content types.

Returns
array

Definition at line 93 of file class.ilECSEventQueueReader.php.

Referenced by handleExportReset(), and handleImportReset().

{
return array(self::TYPE_REMOTE_COURSE, self::TYPE_REMOTE_CATEGORY,
self::TYPE_REMOTE_FILE, self::TYPE_REMOTE_GLOSSARY, self::TYPE_REMOTE_GROUP,
self::TYPE_REMOTE_LEARNING_MODULE, self::TYPE_REMOTE_WIKI, self::TYPE_REMOTE_TEST);
}

+ Here is the caller graph for this function:

static ilECSEventQueueReader::getAllResourceIds ( ilECSSetting  $server,
array  $a_types,
  $a_sender_only = false 
)
staticprotected

Get all resource ids by resource type.

Parameters
ilECSSetting$server
array$a_types
bool$a_sender_only
Returns
array type => ids

Definition at line 108 of file class.ilECSEventQueueReader.php.

References ilRemoteObjectBase\getInstanceByEventType().

Referenced by handleExportReset(), and handleImportReset().

{
include_once 'Services/WebServices/ECS/classes/class.ilRemoteObjectBase.php';
$list = array();
foreach($a_types as $type)
{
if($robj)
{
$list[$type] = $robj->getAllResourceIds($server, $a_sender_only);
}
}
return $list;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilECSEventQueueReader::getEvents ( )

get all events

public

Definition at line 285 of file class.ilECSEventQueueReader.php.

{
return $this->events ? $this->events : array();
}
static ilECSEventQueueReader::getEventTypeFromObjectType (   $a_obj_type)
staticprotected

Convert object type to event type.

Parameters
string$a_obj_type
Returns
string

Definition at line 82 of file class.ilECSEventQueueReader.php.

Referenced by handleImportReset().

{
// currently they are the same for all resource types
return $a_obj_type;
}

+ Here is the caller graph for this function:

ilECSEventQueueReader::getServer ( )

get server setting

Returns
ilECSSetting

Definition at line 273 of file class.ilECSEventQueueReader.php.

Referenced by add(), delete(), deleteAll(), deleteAllEContentEvents(), deleteAllExportedEvents(), read(), refresh(), update(), and writeEventToDB().

{
return $this->settings;
}

+ Here is the caller graph for this function:

static ilECSEventQueueReader::handleExportReset ( ilECSSetting  $server)
static

Handle export reset.

Delete exported econtent and create it again

Returns
bool throws ilException, ilECSConnectorException

Definition at line 230 of file class.ilECSEventQueueReader.php.

References $GLOBALS, ilECSExport\_deleteEContentIds(), ilECSExport\_getAllEContentIds(), deleteAllExportedEvents(), getAllEContentTypes(), getAllResourceIds(), and ilECSSetting\getServerId().

Referenced by ilECSSettingsGUI\readAll().

{
include_once('./Services/WebServices/ECS/classes/class.ilECSExport.php');
// Delete all export events
$queue = new ilECSEventQueueReader($server->getServerId());
// Read all local export info
$local_econtent_ids = ilECSExport::_getAllEContentIds($server->getServerId());
$list = self::getAllResourceIds($server, $types, true);
// merge in one array
$all_remote_ids = array();
foreach($list as $resource_type => $remote_ids)
{
$all_remote_ids = array_merge($all_remote_ids,(array) $remote_ids);
}
$all_remote_ids = array_unique($all_remote_ids);
$GLOBALS['ilLog']->write(__METHOD__.': Resources = ' . print_r($all_remote_ids,true));
$GLOBALS['ilLog']->write(__METHOD__.': Local = ' . print_r($local_econtent_ids,true));
foreach($local_econtent_ids as $local_econtent_id => $local_obj_id)
{
if(!in_array($local_econtent_id, $all_remote_ids))
{
// Delete this deprecated info
$GLOBALS['ilLog']->write(__METHOD__.': Deleting deprecated econtent id '. $local_econtent_id);
ilECSExport::_deleteEContentIds($server->getServerId(),array($local_econtent_id));
}
}
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ilECSEventQueueReader::handleImportReset ( ilECSSetting  $server)
static

Reread all imported econtent.

Returns
bool throws ilException, ilECSConnectorException

Definition at line 131 of file class.ilECSEventQueueReader.php.

References $GLOBALS, $ilLog, ilObject\_lookupType(), ilECSEvent\CREATED, deleteAllEContentEvents(), ilECSEvent\DESTROYED, getAllEContentTypes(), ilECSImport\getAllImportedRemoteObjects(), getAllResourceIds(), getEventTypeFromObjectType(), ilECSUtils\getPossibleRemoteTypes(), ilECSSetting\getServerId(), and ilECSEvent\UPDATED.

Referenced by ilECSSettingsGUI\readAll().

{
global $ilLog;
include_once('Services/WebServices/ECS/classes/class.ilECSConnector.php');
include_once('Services/WebServices/ECS/classes/class.ilECSConnectorException.php');
try
{
include_once('./Services/WebServices/ECS/classes/class.ilECSEventQueueReader.php');
include_once('./Services/WebServices/ECS/classes/class.ilECSImport.php');
include_once('./Services/WebServices/ECS/classes/class.ilECSExport.php');
$event_queue = new ilECSEventQueueReader($server->getServerId());
$event_queue->deleteAllEContentEvents($types);
$list = self::getAllResourceIds($server, $types);
$GLOBALS['ilLog']->write(__METHOD__.': Imported = '.print_r($imported,true));
$GLOBALS['ilLog']->write(__METHOD__.': List = '.print_r($list,true));
foreach($list as $resource_type => $link_ids)
{
if(!in_array($resource_type, ilECSUtils::getPossibleRemoteTypes()))
{
$GLOBALS['ilLog']->write(__METHOD__.': Ignoring resource type '. $resource_type);
continue;
}
foreach((array) $link_ids as $link_id)
{
if(!isset($imported[$link_id]))
{
// Add create event for not imported econtent
$event_queue->add(
$resource_type,
$link_id,
);
}
else
{
// Add update event for already existing events
$event_queue->add(
$resource_type,
$link_id,
);
}
if(isset($imported[$link_id]))
{
unset($imported[$link_id]);
}
}
}
if(is_array($imported))
{
// Delete event for deprecated econtent
include_once 'Services/WebServices/ECS/classes/class.ilECSObjectSettings.php';
foreach($imported as $econtent_id => $obj_id)
{
if($type)
{
$event_queue->add($type,
$econtent_id,
);
}
}
}
}
{
$ilLog->write('Cannot connect to ECS server: '.$e1->getMessage());
throw $e1;
}
catch(ilException $e2)
{
$ilLog->write('Update failed: '.$e2->getMessage());
throw $e2;
}
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilECSEventQueueReader::read ( )

Read public.

Definition at line 607 of file class.ilECSEventQueueReader.php.

References $query, $res, $row, DB_FETCHMODE_OBJECT, and getServer().

Referenced by __construct().

{
global $ilDB;
$query = "SELECT * FROM ecs_events ".
'WHERE server_id = '.$ilDB->quote($this->getServer()->getServerId(),'integer').' '.
'ORDER BY event_id';
$res = $this->db->query($query);
$counter = 0;
while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
{
$this->events[$counter]['event_id'] = $row->event_id;
$this->events[$counter]['type'] = $row->type;
$this->events[$counter]['id'] = $row->id;
$this->events[$counter]['op'] = $row->op;
$this->econtent_ids[$row->event_id] = $row->event_id;
++$counter;
}
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilECSEventQueueReader::refresh ( )

Fetch events from fifo Using fifo public.

Exceptions
ilECSConnectorException

Definition at line 344 of file class.ilECSEventQueueReader.php.

References $GLOBALS, $res, $result, getServer(), and writeEventToDB().

{
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);
}
}
{
$GLOBALS['ilLog']->write(__METHOD__.': Cannot read event fifo. Aborting');
}
}

+ Here is the call graph for this function:

ilECSEventQueueReader::shift ( )

get and delete the first event entry

public

Returns
array event data or an empty array if the queue is empty

Definition at line 521 of file class.ilECSEventQueueReader.php.

{
$event = array_shift($this->events);
if($event == null)
{
return array();
}
else
{
#$this->delete($event['event_id']);
return $event;
}
}
ilECSEventQueueReader::update (   $a_type,
  $a_id,
  $a_operation 
)
private

update one entry

private

Definition at line 573 of file class.ilECSEventQueueReader.php.

References $query, $res, and getServer().

{
global $ilDB;
$query = "UPDATE ecs_events ".
"SET op = ".$this->db->quote($a_operation,'text')." ".
"WHERE type = ".$this->db->quote($a_type,'text')." ".
"AND id = ".$this->db->quote($a_id,'integer')." ".
'AND server_id = '.$ilDB->quote($this->getServer()->getServerId(),'integer');
$res = $ilDB->manipulate($query);
}

+ Here is the call graph for this function:

ilECSEventQueueReader::writeEventToDB ( ilECSEvent  $ev)
private

Write event to db.

Definition at line 400 of file class.ilECSEventQueueReader.php.

References $GLOBALS, $query, $res, $row, ilECSEvent\CREATED, DB_FETCHMODE_OBJECT, ilECSEvent\DESTROYED, ilECSEvent\getRessourceId(), ilECSEvent\getRessourceType(), getServer(), ilECSEvent\getStatus(), TYPE_CMS_COURSE_MEMBERS, TYPE_CMS_COURSES, TYPE_COURSE_URLS, TYPE_DIRECTORY_TREES, TYPE_REMOTE_CATEGORY, TYPE_REMOTE_COURSE, TYPE_REMOTE_FILE, TYPE_REMOTE_GLOSSARY, TYPE_REMOTE_GROUP, TYPE_REMOTE_LEARNING_MODULE, TYPE_REMOTE_TEST, TYPE_REMOTE_WIKI, and ilECSEvent\UPDATED.

Referenced by refresh().

{
global $ilDB;
$GLOBALS['ilLog']->write('--------------------------- Writing new event for '. $ev->getRessourceType());
// this should probably be moved elsewhere
switch($ev->getRessourceType())
{
case 'directory_trees':
break;
case 'course_members':
break;
case 'courses':
break;
case 'courselinks':
break;
case 'categories':
break;
case 'files':
break;
case 'glossaries':
break;
case 'groups':
break;
case 'learningmodules':
break;
case 'wikis':
break;
case 'tests':
break;
case 'course_urls':
break;
}
$query = "SELECT * FROM ecs_events ".
"WHERE type = ".$ilDB->quote($type,'integer')." ".
"AND id = ".$ilDB->quote($ev->getRessourceId(),'integer')." ".
'AND server_id = '.$ilDB->quote($this->getServer()->getServerId(),'integer');
$res = $ilDB->query($query);
$event_id = 0;
while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
{
$event_id = $row->event_id;
}
if(!$event_id)
{
// No previous entry exists => perform insert
$query = "INSERT ecs_events (event_id,type,id,op,server_id) ".
"VALUES( ".
$ilDB->quote($ilDB->nextId('ecs_events'),'integer').','.
$ilDB->quote($type,'text').', '.
$ilDB->quote($ev->getRessourceId(),'integer').', '.
$ilDB->quote($ev->getStatus(),'text').', '.
$ilDB->quote($this->getServer()->getServerId(),'integer').' '.
')';
$ilDB->manipulate($query);
return true;
}
// Do update
$do_update = false;
switch($ev->getStatus())
{
// Do update, although impossible
$do_update = true;
break;
$do_update = true;
break;
// Do nothing. Old status is ok.
break;
}
if(!$do_update)
{
return true;
}
$query = "UPDATE ecs_events ".
"SET op = ".$ilDB->quote($ev->getStatus(),'text')." ".
"WHERE event_id = ".$ilDB->quote($event_id,'integer').' '.
'AND type = '.$ilDB->quote($type).' '.
'AND server_id = '.$ilDB->quote($this->getServer()->getServerId(),'integer');
$ilDB->manipulate($query);
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

ilECSEventQueueReader::$db
protected

Definition at line 53 of file class.ilECSEventQueueReader.php.

ilECSEventQueueReader::$econtent_ids = array()
protected

Definition at line 56 of file class.ilECSEventQueueReader.php.

ilECSEventQueueReader::$events = array()
protected

Definition at line 55 of file class.ilECSEventQueueReader.php.

ilECSEventQueueReader::$log
protected

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

const ilECSEventQueueReader::TYPE_CMS_COURSE_MEMBERS = 'course_members'
const ilECSEventQueueReader::TYPE_CMS_COURSES = 'courses'
const ilECSEventQueueReader::TYPE_COURSE_URLS = 'course_urls'
const ilECSEventQueueReader::TYPE_DIRECTORY_TREES = 'directory_trees'
const ilECSEventQueueReader::TYPE_EXPORTED = 'exported'

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

const ilECSEventQueueReader::TYPE_REMOTE_CATEGORY = 'rcat'
const ilECSEventQueueReader::TYPE_REMOTE_COURSE = 'rcrs'
const ilECSEventQueueReader::TYPE_REMOTE_FILE = 'rfil'
const ilECSEventQueueReader::TYPE_REMOTE_GLOSSARY = 'rglo'
const ilECSEventQueueReader::TYPE_REMOTE_GROUP = 'rgrp'
const ilECSEventQueueReader::TYPE_REMOTE_LEARNING_MODULE = 'rlm'
const ilECSEventQueueReader::TYPE_REMOTE_TEST = 'rtst'
const ilECSEventQueueReader::TYPE_REMOTE_WIKI = 'rwik'

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