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

Public Member Functions

 __construct ()
 Singleton constructor.
 startTaskExecution ()
 Start Tasks.
 start ()
 Start.

Static Public Member Functions

static _getInstance ()
 get singleton instance

Data Fields

const MAX_TASKS = 30

Protected Attributes

 $settings = null
 $log = null
 $db

Private Member Functions

 readEvents ()
 Read EContent.
 handleEvents ()
 Handle events.
 handleNewlyCreate ($a_obj_id)
 handleDelete ($econtent_id, $a_mid=0)
 Handle delete private.
 handleUpdate ($ecscontent)
 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 $instance = null

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 ( )

Singleton constructor.

public

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

References $ilDB, $ilLog, and _getInstance().

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

+ Here is the call graph for this function:

Member Function Documentation

static ilECSTaskScheduler::_getInstance ( )
static

get singleton instance

public

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

References $instance.

Referenced by __construct(), ilSoapUtils\handleECSTasks(), ilInitialisation\initILIAS(), ilECSSettingsGUI\readAll(), and readMIDs().

{
if(self::$instance)
{
}
return self::$instance = new ilECSTaskScheduler();
}

+ 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 251 of file class.ilECSTaskScheduler.php.

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

Referenced by handleEvents(), and handleUpdate().

{
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($econtent_id);
}
else
{
$obj_ids = (array) ilECSImport::_lookupObjId($econtent_id,$a_mid);
}
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 340 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 135 of file class.ilECSTaskScheduler.php.

References $reader, elseif(), handleDelete(), handleNewlyCreate(), handleUpdate(), MAX_TASKS, ilECSEventQueueReader\OPERATION_DELETE, and ilECSEventQueueReader\OPERATION_NEWLY_CREATED.

Referenced by startTaskExecution().

{
#return true;
for($i = 0;$i < self::MAX_TASKS;$i++)
{
if(!$event = $this->event_reader->shift())
{
$this->log->write(__METHOD__.': No more pending events found.');
break;
}
// Delete events
{
$this->handleDelete($event['id']);
continue;
}
{
// That was command queue 'reset_all'
// Stop export and then start export.
$this->handleNewlyCreate($event['id']);
}
// Operation is create or update
// get econtent
try
{
include_once('./Services/WebServices/ECS/classes/class.ilECSEContentReader.php');
$reader = new ilECSEContentReader($event['id']);
}
catch(Exception $e)
{
$this->log->write(__METHOD__.': Cannot read Econtent. '.$e->getMessage());
continue;
}
if(!$reader->read())
{
$this->log->write(__METHOD__.': Deleting deprecated remote course.');
$this->handleDelete($event['id']);
}
else
{
$this->log->write(__METHOD__.': Starting update of remote courses.');
$this->handleUpdate($reader->getEContent());
}
}
}

+ 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 187 of file class.ilECSTaskScheduler.php.

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

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($a_obj_id);
$econtent_id = $export->getEContentId();
try
{
$reader = new ilECSEContentReader($econtent_id);
$reader->read();
foreach($reader->getEContent() as $econtent)
{
if(!$obj = ilObjectFactory::getInstanceByObjId($a_obj_id,false))
{
$ilLog->write(__METHOD__.': Cannot create object instance. Aborting...');
}
// Delete resource
$writer = new ilECSContentWriter($obj);
$writer->setExportable(false);
$writer->setOwnerId($econtent->getOwner());
$writer->setParticipantIds($econtent->getEligibleMembers());
$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 (   $ecscontent)
private

Handle update/creation of remote courses.

private

Parameters
arrayarray of ecscontent

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

References $content, $ilLog, ilObjRemoteCourse\_createFromECSEContent(), ilECSParticipantSettings\_getInstance(), ilECSImport\_isImported(), ilECSImport\_lookupMIDs(), ilObjectFactory\getInstanceByObjId(), and handleDelete().

Referenced by handleEvents().

{
global $ilLog;
foreach($ecscontent as $content)
{
include_once('./Services/WebServices/ECS/classes/class.ilECSParticipantSettings.php');
if(!ilECSParticipantSettings::_getInstance()->isEnabled($content->getOwner()))
{
$ilLog->write('Ignoring disabled participant. MID: '.$content->getOwner());
continue;
}
include_once('Services/WebServices/ECS/classes/class.ilECSImport.php');
// new mids
foreach(array_intersect($this->mids,$content->getEligibleMembers()) as $mid)
{
// Update existing
if($obj_id = ilECSImport::_isImported($content->getEContentId(),$mid))
{
$remote = ilObjectFactory::getInstanceByObjId($obj_id,false);
if($remote->getType() != 'rcrs')
{
$this->log->write(__METHOD__.': Cannot instantiate remote course. Got object type '.$remote->getType());
continue;
}
$ilLog->write(__METHOD__.': ... update called.');
$remote->updateFromECSContent($content);
}
else
{
$ilLog->write(__METHOD__.': ... create called.');
include_once('./Modules/RemoteCourse/classes/class.ilObjRemoteCourse.php');
$remote_crs = ilObjRemoteCourse::_createFromECSEContent($content,$mid);
}
}
// deprecated mids
foreach(array_diff(ilECSImport::_lookupMIDs($content->getEContentId()),$content->getEligibleMembers()) as $deprecated)
{
$this->handleDelete($content->getEContentId(),$deprecated);
}
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilECSTaskScheduler::readEvents ( )
private

Read EContent.

private

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

Referenced by startTaskExecution().

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

+ Here is the caller graph for this function:

ilECSTaskScheduler::readMIDs ( )
private

Read MID's of this installation.

private

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

References $reader, and _getInstance().

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:

ilECSTaskScheduler::start ( )

Start.

public

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

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

{
global $ilLog;
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
// and exceute a new task.
// These operations should be thread-safe
$sett = new ilSetting("ecs");
$time = $sett->get("next_execution");
if(time() < ($time + $this->settings->getPollingTime()))
{
return true;
// Nothing to do
}
// Set new execution time
$sett->set("next_execution", time() + $this->settings->getPollingTime());
$this->log->write(__METHOD__.': Starting ECS tasks.');
// Debug
//$this->startTaskExecution();
//return true;
include_once 'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
$soap_client = new ilSoapClient();
$soap_client->setTimeout(1);
$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())
{
$ilLog->write(__METHOD__.': Calling soap handleECSTasks method...');
$res = $soap_client->call('handleECSTasks',array($new_session_id.'::'.$client_id));
}
else
{
$ilLog->write(__METHOD__.': SOAP call failed. Calling clone method manually. ');
include_once('./webservice/soap/include/inc.soap_functions.php');
}
return true;
}

+ Here is the call graph for this function:

ilECSTaskScheduler::startTaskExecution ( )

Start Tasks.

private

Definition at line 89 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::$instance = null
staticprivate

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

Referenced by _getInstance().

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.

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: