ILIAS  Release_4_0_x_branch Revision 61816
 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 ()
 Constructor.
 getEvents ()
 get all events
 deleteAll ()
 Delete all events.
 deleteAllEContentEvents ()
 Delete all econtents.
 deleteAllExportedEvents ()
 Delete all exported events.
 refresh ()
 Fetch events from ECS server.
 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 ()
 handle admin reset
static handleExportReset ()
 Handle export reset.

Data Fields

const TYPE_ECONTENT = 'econtents'
const TYPE_EXPORTED = 'exported'
const OPERATION_DELETE = 'delete'
const OPERATION_UPDATE = 'update'
const OPERATION_CREATE = 'create'
const OPERATION_NEWLY_CREATED = 'newly-created'
const ADMIN_RESET = 'reset'
const ADMIN_RESET_ALL = 'reset_all'

Protected Attributes

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

Private Member Functions

 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 smeye.nosp@m.r@da.nosp@m.tabay.nosp@m..de
Version
$Id$

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

Constructor & Destructor Documentation

ilECSEventQueueReader::__construct ( )

Constructor.

public

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

References $ilDB, $ilLog, ilECSSettings\_getInstance(), and read().

{
global $ilLog,$ilDB;
include_once('Services/WebServices/ECS/classes/class.ilECSSettings.php');
include_once('Services/WebServices/ECS/classes/class.ilECSReaderException.php');
$this->settings = ilECSSettings::_getInstance();
$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 355 of file class.ilECSEventQueueReader.php.

References $ilDB, $query, and $res.

Referenced by refresh().

{
global $ilDB;
$next_id = $ilDB->nextId('ecs_events');
$query = "INSERT INTO ecs_events (event_id,type,id,op) ".
"VALUES (".
$ilDB->quote($next_id,'integer').", ".
$this->db->quote($a_type,'text').", ".
$this->db->quote($a_id,'integer').", ".
$this->db->quote($a_op,'text')." ".
")";
$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 caller graph for this function:

ilECSEventQueueReader::delete (   $a_event_id)
private

delete private

Parameters
intevent id

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

References $ilDB, $query, and $res.

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

Delete all events.

public

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

References $ilDB, $query, and $res.

{
global $ilDB;
$query = "DELETE FROM ecs_events";
$res = $ilDB->manipulate($query);
return true;
}
ilECSEventQueueReader::deleteAllEContentEvents ( )

Delete all econtents.

public

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

References $ilDB, $query, and $res.

{
global $ilDB;
$query = "DELETE FROM ecs_events ".
"WHERE type = ".$this->db->quote(self::TYPE_ECONTENT,'text');
$res = $ilDB->manipulate($query);
return true;
}
ilECSEventQueueReader::deleteAllExportedEvents ( )

Delete all exported events.

public

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

References $ilDB, $query, and $res.

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

get all events

public

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

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

Handle export reset.

Delete exported econtent and create it again

Returns
bool

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

References ilECSExport\_getExportedIDs().

Referenced by refresh().

{
include_once('./Services/WebServices/ECS/classes/class.ilECSExport.php');
$queue = new ilECSEventQueueReader();
$queue->deleteAllExportedEvents();
foreach(ilECSExport::_getExportedIDs() as $obj_id)
{
$queue->add(self::TYPE_EXPORTED,$obj_id,self::OPERATION_NEWLY_CREATED);
}
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ilECSEventQueueReader::handleImportReset ( )
static

handle admin reset

Returns
bool

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

References $ilLog, $null, $reader, ilECSExport\_deleteEContentIds(), ilECSExport\_getAllEContentIds(), ilECSImport\_getAllImportedLinks(), OPERATION_CREATE, OPERATION_DELETE, OPERATION_UPDATE, and TYPE_ECONTENT.

Referenced by ilECSSettingsGUI\readAll(), and refresh().

{
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();
$event_queue->deleteAllEContentEvents();
$reader->read();
$all_content = $reader->getEContent();
// read update events
foreach($all_content as $content)
{
// Ask if this is desired
if(!isset($imported[$content->getEContentId()]) and 0)
{
$event_queue->add(
$content->getEContentId(),
);
}
else
{
$event_queue->add(
$content->getEContentId(),
);
}
if(isset($imported[$content->getEContentId()]))
{
unset($imported[$content->getEContentId()]);
}
if(isset($exported[$content->getEContentId()]))
{
unset($exported[$content->getEContentId()]);
}
}
// read delete events
if(is_array($imported))
{
foreach($imported as $econtent_id => $null)
{
$econtent_id,
}
}
// delete all deprecated export information
if(is_array($exported))
{
}
}
{
$ilLog->write('Cannot connect to ECS server: '.$e1->getMessage());
return false;
}
catch(ilException $e2)
{
$ilLog->write('Update failed: '.$e1->getMessage());
return false;
}
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 417 of file class.ilECSEventQueueReader.php.

References $ilDB, $query, $res, $row, and DB_FETCHMODE_OBJECT.

Referenced by __construct(), and refresh().

{
global $ilDB;
$query = "SELECT * FROM ecs_events 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 caller graph for this function:

ilECSEventQueueReader::refresh ( )

Fetch events from ECS server.

public

Parameters
@throwsilECSConnectorException, ilECSReaderException

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

References $ilLog, $res, add(), elseif(), handleExportReset(), handleImportReset(), read(), and update().

{
global $ilLog;
try
{
include_once('Services/WebServices/ECS/classes/class.ilECSConnector.php');
include_once('Services/WebServices/ECS/classes/class.ilECSConnectorException.php');
$connector = new ilECSConnector();
$res = $connector->getEventQueues();
if(!is_array($res->getResult()))
{
$ilLog->write(__METHOD__.': No new events found.');
return true;
}
$this->log->write(__METHOD__.': Found '.count($res->getResult()).' new events.');
foreach($res->getResult() as $event)
{
// Handle command queue
if(isset($event->cmd) and is_object($event->cmd))
{
if(!isset($event->cmd->admin) and !is_object($event->cmd->admin))
{
throw new ilECSReaderException('Received invalid command queue structure. Property "admin" is missing');
}
$admin_cmd = $event->cmd->admin;
$this->log->write(__METHOD__.': Received new Commandqueue command: '.$admin_cmd);
switch($admin_cmd)
{
case self::ADMIN_RESET:
break;
case self::ADMIN_RESET_ALL:
break;
}
}
// Handle econtents events
if(isset($event->econtents) and is_object($event->econtents))
{
$operation = $event->econtents->op;
if(!in_array($event->econtents->eid,$this->econtent_ids))
{
// It is not necessary to store multiple entries with the same econtent_id.
// since we always have to receive and parse the econtent from the ecs server.
$this->add('econtents',$event->econtents->eid,$event->econtents->op);
$this->log->write(__METHOD__.': Added new entry for EContentId: '.$event->econtents->eid);
}
elseif($operation == self::OPERATION_DELETE)
{
$this->log->write(__METHOD__.': Updating delete operation for EContentId: '.$event->econtents->eid);
$this->update('econtents',$event->econtents->eid,$event->econtents->op);
}
else
{
// update with last operation
$this->log->write(__METHOD__.': Ignoring multiple operations for EContentId: '.$event->econtents->eid);
}
}
}
$this->read();
}
{
$ilLog->write(__METHOD__.': Error connecting to ECS server. '.$e->getMessage());
throw $e;
}
{
$ilLog->write(__METHOD__.': Error reading EventQueue. '.$e->getMessage());
throw $e;
}
}

+ 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 335 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 385 of file class.ilECSEventQueueReader.php.

References $ilDB, $query, and $res.

Referenced by refresh().

{
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')." ";
$res = $ilDB->manipulate($query);
}

+ Here is the caller graph for this function:

Field Documentation

ilECSEventQueueReader::$db
protected

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

ilECSEventQueueReader::$econtent_ids = array()
protected

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

ilECSEventQueueReader::$events = array()
protected

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

ilECSEventQueueReader::$log
protected

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

const ilECSEventQueueReader::ADMIN_RESET = 'reset'

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

const ilECSEventQueueReader::ADMIN_RESET_ALL = 'reset_all'

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

const ilECSEventQueueReader::OPERATION_CREATE = 'create'

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

Referenced by handleImportReset().

const ilECSEventQueueReader::OPERATION_DELETE = 'delete'
const ilECSEventQueueReader::OPERATION_NEWLY_CREATED = 'newly-created'

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

Referenced by ilECSTaskScheduler\handleEvents().

const ilECSEventQueueReader::OPERATION_UPDATE = 'update'

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

Referenced by handleImportReset().

const ilECSEventQueueReader::TYPE_ECONTENT = 'econtents'

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

Referenced by handleImportReset().

const ilECSEventQueueReader::TYPE_EXPORTED = 'exported'

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


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