ILIAS  Release_4_2_x_branch Revision 61807
 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 ()
 Delete all econtents.
 deleteAllExportedEvents ()
 Delete all exported events.
 refresh ()
 Fetch events from fifo Using fifo public.
 shift ()
 get and delete the first event entry
 add ($a_type, $a_id, $a_op)
 add
 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.

Data Fields

const TYPE_ECONTENT = 'econtents'
const TYPE_EXPORTED = 'exported'
const ADMIN_RESET = 'reset'
const ADMIN_RESET_ALL = 'reset_all'

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
 delete ($a_event_id)
 delete private

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 55 of file class.ilECSEventQueueReader.php.

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

{
global $ilLog,$ilDB;
include_once('Services/WebServices/ECS/classes/class.ilECSSetting.php');
include_once('Services/WebServices/ECS/classes/class.ilECSReaderException.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 434 of file class.ilECSEventQueueReader.php.

References $ilDB, $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)
private

delete private

Parameters
intevent id

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

References $ilDB, $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 243 of file class.ilECSEventQueueReader.php.

References $ilDB, $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 ( )

Delete all econtents.

public

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

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

Referenced by handleImportReset().

{
global $ilDB;
$query = "DELETE FROM ecs_events ".
"WHERE type = ".$this->db->quote(self::TYPE_ECONTENT,'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 ( )

Delete all exported events.

public

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

References $ilDB, $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::deleteServer (   $a_server_id)
static

Delete by server id ilDB $ilDB.

Parameters
int$a_server_id

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

References $ilDB, and $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:

ilECSEventQueueReader::getEvents ( )

get all events

public

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

{
return $this->events ? $this->events : array();
}
ilECSEventQueueReader::getServer ( )

get server setting

Returns
ilECSSetting

Definition at line 221 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 161 of file class.ilECSEventQueueReader.php.

References $GLOBALS, $reader, ilECSExport\_deleteEContentIds(), ilECSExport\_getAllEContentIds(), deleteAllExportedEvents(), ilECSSetting\getServerId(), and ilECSEContentReader\SENDER_ONLY.

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());
// Read remote list
try
{
include_once './Services/WebServices/ECS/classes/class.ilECSEContentReader.php';
$list = $reader->readResourceList(ilECSEContentReader::SENDER_ONLY);
}
{
$GLOBALS['ilLog']->write(__METHOD__.': Connect failed '.$e->getMessage());
throw $e;
}
{
$GLOBALS['ilLog']->write(__METHOD__.': Connect failed '.$e->getMessage());
throw $e;
}
$remote_econtent_ids = array();
if(count($list))
{
$remote_econtent_ids = $list->getLinkIds();
}
// Delete all deprecated local export info
foreach($local_econtent_ids as $econtent_id => $obj_id)
{
if(!in_array($econtent_id, $remote_econtent_ids))
{
ilECSExport::_deleteEContentIds($server->getServerId(),array($econtent_id));
}
}
// Delete all with deprecated remote info
foreach($remote_econtent_ids as $econtent_id)
{
if(!isset($local_econtent_ids[$econtent_id]))
{
ilECSExport::_deleteEContentIds($server->getServerId(),array($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 76 of file class.ilECSEventQueueReader.php.

References $ilLog, $reader, ilECSImport\_getAllImportedLinks(), ilECSEvent\CREATED, deleteAllEContentEvents(), ilECSEvent\DESTROYED, ilECSSetting\getServerId(), TYPE_ECONTENT, 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.ilECSEContentReader.php');
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();
$list = $reader->readResourceList();
//$all_content = $reader->getEContent();
if(count($list))
{
foreach($list->getLinkIds() as $link_id)
{
if(!isset($imported[$link_id]))
{
// Add create event for not imported econtent
$event_queue->add(
$link_id,
);
}
else
{
// Add update event for already existing events
$event_queue->add(
$link_id,
);
}
if(isset($imported[$link_id]))
{
unset($imported[$link_id]);
}
}
}
if(is_array($imported))
{
// Delete event for deprecated econtent
foreach($imported as $econtent_id => $null)
{
$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 499 of file class.ilECSEventQueueReader.php.

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

Referenced by __construct().

{
global $ilDB;
$query = "SELECT * FROM ecs_events ORDER BY event_id ".
'AND server_id = '.$ilDB->quote($this->getServer()->getServerId(),'integer');
$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,ilECSReaderException

Definition at line 291 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 414 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 465 of file class.ilECSEventQueueReader.php.

References $ilDB, $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 346 of file class.ilECSEventQueueReader.php.

References $GLOBALS, $ilDB, $query, $res, $row, ilECSEvent\CREATED, DB_FETCHMODE_OBJECT, ilECSEvent\DESTROYED, ilECSEvent\getRessourceId(), getServer(), ilECSEvent\getStatus(), and ilECSEvent\UPDATED.

Referenced by refresh().

{
global $ilDB;
$query = "SELECT * FROM ecs_events ".
"WHERE type = ".$ilDB->quote(self::TYPE_ECONTENT,'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;
}
$GLOBALS['ilLog']->write(__METHOD__.': Handling new event '.$ev->getStatus().' for econtent '.$ev->getRessourceId());
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(self::TYPE_ECONTENT,'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 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 45 of file class.ilECSEventQueueReader.php.

ilECSEventQueueReader::$econtent_ids = array()
protected

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

ilECSEventQueueReader::$events = array()
protected

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

ilECSEventQueueReader::$log
protected

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

const ilECSEventQueueReader::ADMIN_RESET = 'reset'

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

const ilECSEventQueueReader::ADMIN_RESET_ALL = 'reset_all'

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

const ilECSEventQueueReader::TYPE_ECONTENT = 'econtents'

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

Referenced by handleImportReset().

const ilECSEventQueueReader::TYPE_EXPORTED = 'exported'

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


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