ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilECSTaskScheduler Class Reference
+ Collaboration diagram for ilECSTaskScheduler:

Public Member Functions

 getServer ()
 Get server setting.
 startTaskExecution ()
 Start Tasks.
 checkNextExecution ()
 Start.

Static Public Member Functions

static _getInstanceByServerId ($a_server_id)
 get singleton instance Private access use ilECSTaskScheduler::start() or ilECSTaskScheduler::startTaskExecution
static start ()
 Start task scheduler for each server instance.
static startExecution ()
 Static version iterates over all active instances.

Data Fields

const MAX_TASKS = 30

Protected Member Functions

 initNextExecution ()
 Call next task scheduler run.

Protected Attributes

 $settings = null
 $log = null
 $db

Private Member Functions

 __construct (ilECSSetting $setting)
 Singleton constructor.
 readEvents ()
 Read EContent.
 handleEvents ()
 Handle events.
 handleNewlyCreate ($a_obj_id)
 handleDelete ($econtent_id, $a_mid=0)
 Handle delete private.
 handleUpdate (ilECSEContent $content, ilECSEContentDetails $details)
 Handle update/creation of remote courses.
 handleDeprecatedAccounts ()
 Delete deprecate ECS accounts.
 readMIDs ()
 Read MID's of this installation.

Private Attributes

 $event_reader = null
 $mids = array()
 $content = array()
 $to_create = array()
 $to_update = array()
 $to_delete = array()

Static Private Attributes

static $instances = array()

Detailed Description

Author
Stefan Meyer smeye.nosp@m.r.il.nosp@m.ias@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 32 of file class.ilECSTaskScheduler.php.

Constructor & Destructor Documentation

ilECSTaskScheduler::__construct ( ilECSSetting  $setting)
private

Singleton constructor.

public

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

References $ilDB, and $ilLog.

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

Member Function Documentation

static ilECSTaskScheduler::_getInstanceByServerId (   $a_server_id)
static

get singleton instance Private access use ilECSTaskScheduler::start() or ilECSTaskScheduler::startTaskExecution

private

Returns
ilECSTaskScheduler

Definition at line 79 of file class.ilECSTaskScheduler.php.

References ilECSSetting\getInstanceByServerId().

Referenced by ilSoapUtils\handleECSTasks(), and ilECSSettingsGUI\readAll().

{
if(self::$instances[$a_server_id])
{
return self::$instances[$a_server_id];
}
return self::$instances[$a_server_id] =
);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilECSTaskScheduler::checkNextExecution ( )

Start.

public

Definition at line 460 of file class.ilECSTaskScheduler.php.

References $ilDB, $ilLog, and $query.

{
global $ilLog, $ilDB;
if(!$this->settings->isEnabled())
{
return false;
}
if(!$this->settings->checkImportId())
{
$this->log->write(__METHOD__.': Import ID is deleted or not of type "category". Aborting');
return false;
}
// check next task excecution time:
// If it's greater than time() directly increase this value with the polling time
/* synchronized { */
$query = 'UPDATE settings SET '.
'value = '.$ilDB->quote(time() + $this->settings->getPollingTime(),'text').' '.
'WHERE module = '.$ilDB->quote('ecs','text').' '.
'AND keyword = '.$ilDB->quote('next_execution_'.$this->settings->getServerId(),'text').' '.
'AND value < '.$ilDB->quote(time(),'text');
$affected_rows = $ilDB->manipulate($query);
/* } */
if(!$affected_rows)
{
// Nothing to do
return false;
}
return true;
}
ilECSTaskScheduler::getServer ( )

Get server setting.

Returns
ilECSSetting

Definition at line 127 of file class.ilECSTaskScheduler.php.

References $settings.

Referenced by handleEvents(), handleNewlyCreate(), handleUpdate(), readEvents(), and readMIDs().

{
}

+ Here is the caller graph for this function:

ilECSTaskScheduler::handleDelete (   $econtent_id,
  $a_mid = 0 
)
private

Handle delete private.

Parameters
arrayarray of event data

Definition at line 306 of file class.ilECSTaskScheduler.php.

References $GLOBALS, $ref_id, ilObject\_getAllReferences(), ilECSImport\_lookupObjId(), ilECSImport\_lookupObjIds(), and ilObjectFactory\getInstanceByRefId().

Referenced by handleEvents().

{
global $tree;
include_once('./Services/WebServices/ECS/classes/class.ilECSImport.php');
// if mid is zero delete all obj_ids
if(!$a_mid)
{
$obj_ids = ilECSImport::_lookupObjIds($this->settings->getServerId(),$econtent_id);
}
else
{
$obj_ids = (array) ilECSImport::_lookupObjId($this->settings->getServerId(),$econtent_id,$a_mid);
}
$GLOBALS['ilLog']->write(__METHOD__.': Received obj_ids '.print_r($obj_ids,true));
foreach($obj_ids as $obj_id)
{
$references = ilObject::_getAllReferences($obj_id);
foreach($references as $ref_id)
{
if($tmp_obj = ilObjectFactory::getInstanceByRefId($ref_id,false))
{
$this->log->write(__METHOD__.': Deleting obsolete remote course: '.$tmp_obj->getTitle());
$tmp_obj->delete();
$tree->deleteTree($tree->getNodeData($ref_id));
}
unset($tmp_obj);
}
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilECSTaskScheduler::handleDeprecatedAccounts ( )
private

Delete deprecate ECS accounts.

private

Definition at line 399 of file class.ilECSTaskScheduler.php.

References $ilDB, $query, $res, $row, DB_FETCHMODE_OBJECT, and ilObjectFactory\getInstanceByObjId().

Referenced by startTaskExecution().

{
global $ilDB;
$query = "SELECT usr_id FROM usr_data WHERE auth_mode = 'ecs' ".
"AND time_limit_until < ".time()." ".
"AND time_limit_unlimited = 0 ".
"AND (time_limit_until - time_limit_from) < 7200";
$res = $ilDB->query($query);
while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
{
if($user_obj = ilObjectFactory::getInstanceByObjId($row->usr_id,false))
{
$this->log->write(__METHOD__.': Deleting deprecated ECS user account '.$user_obj->getLogin());
$user_obj->delete();
}
// only one user
break;
}
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilECSTaskScheduler::handleEvents ( )
private

Handle events.

private

Definition at line 185 of file class.ilECSTaskScheduler.php.

References $reader, ilECSEvent\DESTROYED, getServer(), handleDelete(), handleNewlyCreate(), handleUpdate(), MAX_TASKS, and ilECSEvent\NEW_EXPORT.

Referenced by startTaskExecution().

{
include_once './Services/WebServices/ECS/classes/class.ilECSEvent.php';
for($i = 0;$i < self::MAX_TASKS;$i++)
{
if(!$event = $this->event_reader->shift())
{
$this->log->write(__METHOD__.': No more pending events found. DONE');
break;
}
if($event['op'] == ilECSEvent::DESTROYED)
{
$this->handleDelete($event['id']);
$this->log->write(__METHOD__.': Handling delete. DONE');
continue;
}
if($event['op'] == ilECSEvent::NEW_EXPORT)
{
$this->handleNewlyCreate($event['id']);
$this->log->write(__METHOD__.': Handling new creation. DONE');
continue;
}
// Operation is create or update
// get econtent
try
{
include_once('./Services/WebServices/ECS/classes/class.ilECSEContentReader.php');
$reader = new ilECSEContentReader($this->getServer()->getServerId(),$event['id']);
$reader->read();
$reader->read(true);
}
catch(Exception $e)
{
$this->log->write(__METHOD__.': Cannot read Econtent. '.$e->getMessage());
continue;
}
if(!$reader->getEContent() instanceof ilECSEContent)
{
$this->handleDelete($event['id']);
$this->log->write(__METHOD__.': Handling delete of deprecated remote courses. DONE');
}
else
{
$this->handleUpdate($reader->getEContent(),$reader->getEContentDetails());
$this->log->write(__METHOD__.': Handling update. DONE');
}
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilECSTaskScheduler::handleNewlyCreate (   $a_obj_id)
private

Definition at line 236 of file class.ilECSTaskScheduler.php.

References $ilLog, $reader, ilObjectFactory\getInstanceByObjId(), and getServer().

Referenced by handleEvents().

{
global $ilLog;
include_once('./Services/WebServices/ECS/classes/class.ilECSExport.php');
include_once('./Services/WebServices/ECS/classes/class.ilECSConnectorException.php');
include_once('./Services/WebServices/ECS/classes/class.ilECSEContentReader.php');
include_once('./Services/WebServices/ECS/classes/class.ilECSReaderException.php');
include_once('./Services/WebServices/ECS/classes/class.ilECSContentWriter.php');
include_once('./Services/WebServices/ECS/classes/class.ilECSContentWriterException.php');
$export = new ilECSExport($this->getServer()->getServerId(),$a_obj_id);
$econtent_id = $export->getEContentId();
try
{
$reader = new ilECSEContentReader($this->getServer()->getServerId(),$econtent_id);
$reader->read();
$reader->read(true);
$econtent = $reader->getEContent();
$details = $reader->getEContentDetails();
if($econtent instanceof ilECSEContent and $details instanceof ilECSEContentDetails)
{
if(!$obj = ilObjectFactory::getInstanceByObjId($a_obj_id,false))
{
$ilLog->write(__METHOD__.': Cannot create object instance. Aborting...');
return false;
}
// Delete resource
$writer = new ilECSContentWriter($obj,$this->getServer()->getServerId());
$writer->setExportable(false);
$writer->setOwnerId($details->getFirstSender());
$writer->setParticipantIds($details->getReceivers());
$writer->refresh();
// Create resource
$writer->setExportable(true);
$writer->refresh();
return true;
}
return false;
}
{
$ilLog->write(__METHOD__.': Cannot handle create event. Message: '.$e1->getMessage());
return false;
}
{
$ilLog->write(__METHOD__.': Cannot handle create event. Message: '.$e2->getMessage());
return false;
}
{
$ilLog->write(__METHOD__.': Cannot handle create event. Message: '.$e2->getMessage());
return false;
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilECSTaskScheduler::handleUpdate ( ilECSEContent  $content,
ilECSEContentDetails  $details 
)
private

Handle update/creation of remote courses.

private

Parameters
arrayarray of ecscontent

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

References $content, $GLOBALS, $ilLog, ilObjRemoteCourse\_createFromECSEContent(), ilECSImport\_isImported(), ilECSEContent\getEContentId(), ilObjectFactory\getInstanceByObjId(), ilECSParticipantSettings\getInstanceByServerId(), ilECSEContent\getOwner(), ilECSEContentDetails\getReceivers(), and getServer().

Referenced by handleEvents().

{
global $ilLog;
$GLOBALS['ilLog']->write(__METHOD__.': Receivers are '. print_r($details->getReceivers(),true));
include_once('./Services/WebServices/ECS/classes/class.ilECSParticipantSettings.php');
if(!ilECSParticipantSettings::getInstanceByServerId($this->getServer()->getServerId())->isImportAllowed($content->getOwner()))
{
$ilLog->write('Ignoring disabled participant. MID: '.$content->getOwner());
return false;
}
include_once('Services/WebServices/ECS/classes/class.ilECSImport.php');
// new mids
#foreach($this->mids as $mid)
foreach(array_intersect($this->mids,$details->getReceivers()) as $mid)
{
// Update existing
if($obj_id = ilECSImport::_isImported($this->settings->getServerId(),$content->getEContentId(),$mid))
{
$ilLog->write(__METHOD__.': Handling update for existing object');
$remote = ilObjectFactory::getInstanceByObjId($obj_id,false);
if($remote->getType() != 'rcrs')
{
$this->log->write(__METHOD__.': Cannot instantiate remote course. Got object type '.$remote->getType());
continue;
}
$remote->updateFromECSContent($this->getServer()->getServerId(),$content);
}
else
{
$ilLog->write(__METHOD__.': Handling create for non existing object');
include_once('./Modules/RemoteCourse/classes/class.ilObjRemoteCourse.php');
$remote_crs = ilObjRemoteCourse::_createFromECSEContent($this->settings->getServerId(),$content,$mid);
}
/*
// deprecated mids
foreach(array_diff(ilECSImport::_lookupMIDs($this->settings->getServerId(),$content->getEContentId()),$details->getReceivers()) as $deprecated)
{
$this->handleDelete($content->getEContentId(),$deprecated);
}
*/
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilECSTaskScheduler::initNextExecution ( )
protected

Call next task scheduler run.

Definition at line 500 of file class.ilECSTaskScheduler.php.

References $_COOKIE, $client_id, $ilLog, $res, duplicate_session(), and ilSoapFunctions\handleECSTasks().

{
global $ilLog;
// Start task execution as backend process
include_once 'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
$soap_client = new ilSoapClient();
$soap_client->setResponseTimeout(1);
$soap_client->enableWSDL(true);
$ilLog->write(__METHOD__.': Trying to call Soap client...');
$new_session_id = duplicate_session($_COOKIE['PHPSESSID']);
$client_id = $_COOKIE['ilClientId'];
if($soap_client->init() and 0)
{
$ilLog->write(__METHOD__.': Calling soap handleECSTasks method...');
$res = $soap_client->call('handleECSTasks',array($new_session_id.'::'.$client_id,$this->settings->getServerId()));
}
else
{
$ilLog->write(__METHOD__.': SOAP call failed. Calling clone method manually. ');
include_once('./webservice/soap/include/inc.soap_functions.php');
$res = ilSoapFunctions::handleECSTasks($new_session_id.'::'.$client_id,$this->settings->getServerId());
}
}

+ Here is the call graph for this function:

ilECSTaskScheduler::readEvents ( )
private

Read EContent.

private

Definition at line 165 of file class.ilECSTaskScheduler.php.

References getServer().

Referenced by startTaskExecution().

{
try
{
include_once('./Services/WebServices/ECS/classes/class.ilECSEventQueueReader.php');
$this->event_reader = new ilECSEventQueueReader($this->getServer()->getServerId());
$this->event_reader->refresh();
}
catch(ilException $exc)
{
throw $exc;
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilECSTaskScheduler::readMIDs ( )
private

Read MID's of this installation.

private

Definition at line 427 of file class.ilECSTaskScheduler.php.

References $reader, ilECSCommunityReader\getInstanceByServerId(), and getServer().

Referenced by startTaskExecution().

{
try
{
$this->mids = array();
include_once('./Services/WebServices/ECS/classes/class.ilECSCommunityReader.php');
foreach($reader->getCommunities() as $com)
{
foreach($com->getParticipants() as $part)
{
if($part->isSelf())
{
$this->mids[] = $part->getMID();
$this->log->write('Fetch MID: '.$part->getMID());
}
}
}
}
catch(ilException $exc)
{
throw $exc;
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ilECSTaskScheduler::start ( )
static

Start task scheduler for each server instance.

Definition at line 94 of file class.ilECSTaskScheduler.php.

References $server, and ilECSServerSettings\getInstance().

{
include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
foreach($servers->getServers() as $server)
{
$sched = new ilECSTaskScheduler($server);
if($sched->checkNextExecution())
{
$sched->initNextExecution();
}
}
}

+ Here is the call graph for this function:

static ilECSTaskScheduler::startExecution ( )
static

Static version iterates over all active instances.

Definition at line 111 of file class.ilECSTaskScheduler.php.

References $server, and ilECSServerSettings\getInstance().

{
include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
foreach($server->getServers() as $server)
{
$sched = new ilECSTaskScheduler($server);
$sched->startTaskExecution();
}
}

+ Here is the call graph for this function:

ilECSTaskScheduler::startTaskExecution ( )

Start Tasks.

private

Definition at line 139 of file class.ilECSTaskScheduler.php.

References $ilLog, handleDeprecatedAccounts(), handleEvents(), readEvents(), and readMIDs().

{
global $ilLog;
try
{
$this->readMIDs();
$this->readEvents();
$this->handleEvents();
}
catch(ilException $exc)
{
$this->log->write(__METHOD__.': Caught exception: '.$exc->getMessage());
return false;
}
return true;
}

+ Here is the call graph for this function:

Field Documentation

ilECSTaskScheduler::$content = array()
private

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

Referenced by handleUpdate().

ilECSTaskScheduler::$db
protected

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

ilECSTaskScheduler::$event_reader = null
private

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

ilECSTaskScheduler::$instances = array()
staticprivate

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

ilECSTaskScheduler::$log = null
protected

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

ilECSTaskScheduler::$mids = array()
private

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

ilECSTaskScheduler::$settings = null
protected

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

Referenced by getServer().

ilECSTaskScheduler::$to_create = array()
private

Definition at line 46 of file class.ilECSTaskScheduler.php.

ilECSTaskScheduler::$to_delete = array()
private

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

ilECSTaskScheduler::$to_update = array()
private

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

const ilECSTaskScheduler::MAX_TASKS = 30

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

Referenced by handleEvents().


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