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

Public Member Functions

 ilDAVLocks ()
 lockRef ($refId, $iliasUserId, $davUser, $token, $expires, $depth, $scope)
 Creates a lock an object, unless there are locks on the object or its parents, which prevent the creation of the lock.
 lockWithoutCheckingDAV (&$objDAV, $iliasUserId, $davUser, $token, $expires, $depth, $scope)
 Creates a write lock.
 lockWithoutCheckingObj ($objId, $nodeId, $iliasUserId, $davUser, $token, $expires, $depth, $scope)
 Creates a write lock.
 updateLockWithoutCheckingDAV (&$objDAV, $token, $expires)
 Updates a write lock.
 updateLockWithoutCheckingObj ($objId, $nodeId, $token, $expires)
 Updates a write lock.
 unlockWithoutCheckingDAV (&$objDAV, $token)
 Discards a write lock.
 getLockDAV (&$objDAV, $token)
 Returns the lock with the specified token on the specified DAV object.
 getLocksOnObjectDAV (&$objDAV)
 Returns all locks on the specified object.
 getLocksOnObjectObj ($objId, $nodeId=0)
 Returns all locks on the specified object id.
 getLocksOnPathDAV (&$pathDAV)
 Returns all locks on the specified object path.
 getLocksOnPathRef ($refId)
 Returns all locks on the specified object, specified by a reference id.
 cleanUp ()
 System maintenance: get rid of locks that have expired over an hour ago.

Protected Member Functions

 writelog ($message)
 Writes a message to the logfile.,.

Private Attributes

 $table = 'dav_lock'
 $isDebug = false
 Set this to true, to get debug output in the ILIAS log.

Detailed Description

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

Member Function Documentation

ilDAVLocks::cleanUp ( )

System maintenance: get rid of locks that have expired over an hour ago.

Since we have no index over the 'expires' column, this causes a (very slow) table space scan.

Definition at line 526 of file class.ilDAVLocks.php.

References $ilDB, $row, ilObject\_getAllReferences(), and DB_FETCHMODE_ASSOC.

Referenced by unlockWithoutCheckingDAV().

{
global $ilDB, $tree;
// 1. Get rid of locks that have expired over an hour ago
$old = time() - 3600;
$q = 'DELETE'
.' FROM '.$this->table
.' WHERE expires < '.$ilDB->quote($old,'integer')
;
$ilDB->manipulate($q);
// 2. Get rid of null resources which are not associated to
// a lock due to step 1, or due to a database inconsistency
// because we are working with non-transactional tables
$q = 'SELECT dat.obj_id '
.' FROM object_data AS dat'
.' LEFT JOIN '.$this->table.' lck'
.' ON dat.obj_id = lck.obj_id'
.' WHERE dat.type = '.$ilDB->quote('null','text')
.' AND lck.obj_id IS NULL'
;
/* TODO: smeyer.' FOR UPDATE' */
$r = $ilDB->query($q);
while ($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
{
$references = ilObject::_getAllReferences($row['obj_id']);
$obj = new ilObjNull($row['obj_id'], false);
if (count($references) == 0)
{
$obj->delete();
} else {
foreach ($references as $refId)
{
$obj->setRefId($refId);
$obj->delete();
$nodeData = $tree->getNodeData($refId);
$tree->deleteTree($nodeData);
}
}
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDAVLocks::getLockDAV ( $objDAV,
  $token 
)

Returns the lock with the specified token on the specified DAV object.

Parameters
$objDAVDAV object to get the lock for.
stringLock token.
Returns
An array of associative arrays for all the locks that were found. Each associative array has the following keys: 'ilias_owner' => user id, 'dav_owner' => user name, 'token' => locktoken 'expires' => expiration timestamp 'depth' => 0 or 'infinity' 'scope' => 'exclusive' or 'shared'

Definition at line 328 of file class.ilDAVLocks.php.

References $ilDB, $result, $row, DB_FETCHMODE_ASSOC, and writelog().

{
global $ilDB;
$this->writelog('getLocks('.$objDAV.')');
$objId = $objDAV->getObjectId();
$nodeId = $objDAV->getNodeId();
$q = 'SELECT ilias_owner, dav_owner, expires, depth, scope'
.' FROM '.$this->table
.' WHERE obj_id = '.$ilDB->quote($objId,'integer')
.' AND node_id = '.$ilDB->quote($nodeId,'integer')
.' AND token = '.$ilDB->quote($token,'text')
;
$this->writelog('getLocks('.$objDAV.') query='.$q);
$r = $ilDB->query($q);
$result = array();
while ($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
{
if ($row['depth'] == -1) $row['depth'] = 'infinity';
$row['scope'] = ($row['scope'] == 'x') ? 'exclusive' : 'shared';
$row['token'] = $token;
}
return $result;
}

+ Here is the call graph for this function:

ilDAVLocks::getLocksOnObjectDAV ( $objDAV)

Returns all locks on the specified object.

This method does not take into account inherited locks from parent objects.

Parameters
$objDAVDAV object to get the locks for.
Returns
An array of associative arrays for all the locks that were found. Each associative array has the following keys: 'ilias_owner' => user id, 'dav_owner' => user name, 'token' => locktoken 'expires' => expiration timestamp 'depth' => 0 or 'infinity' 'scope' => 'exclusive' or 'shared'

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

References getLocksOnObjectObj().

{
$objId = $objDAV->getObjectId();
$nodeId = $objDAV->getNodeId();
return $this->getLocksOnObjectObj($objId, $nodeId);
}

+ Here is the call graph for this function:

ilDAVLocks::getLocksOnObjectObj (   $objId,
  $nodeId = 0 
)

Returns all locks on the specified object id.

This method does not take into account inherited locks from parent objects.

Parameters
$objIdobject ID to get the locks for.
intnode a node of the object. For example the id of a page of a learning module. Specify 0 if the object does not have multiple nodes.
Returns
An array of associative arrays for all the locks that were found. Each associative array has the following keys: 'ilias_owner' => user id, 'dav_owner' => user name, 'token' => locktoken 'expires' => expiration timestamp 'depth' => 0 or 'infinity' 'scope' => 'exclusive' or 'shared'

Definition at line 391 of file class.ilDAVLocks.php.

References $ilDB, $result, $row, DB_FETCHMODE_ASSOC, and writelog().

Referenced by getLocksOnObjectDAV().

{
global $ilDB;
$this->writelog('getLocks('.$objDAV.')');
$nodeId = 0;
$q = 'SELECT ilias_owner, dav_owner, token, expires, depth, scope'
.' FROM '.$this->table
.' WHERE obj_id = '.$ilDB->quote($objId,'integer')
.' AND node_id = '.$ilDB->quote($nodeId,'integer')
.' AND expires > '.$ilDB->quote(time(),'integer')
;
$this->writelog('getLocks('.$objDAV.') query='.$q);
$r = $ilDB->query($q);
$result = array();
while ($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
{
if ($row['depth'] == -1) $row['depth'] = 'infinity';
$row['scope'] = ($row['scope'] == 'x') ? 'exclusive' : 'shared';
}
return $result;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDAVLocks::getLocksOnPathDAV ( $pathDAV)

Returns all locks on the specified object path.

Parameters
$pathDAVArray with DAV objects to get the locks for.
Returns
An array of associative arrays for all the locks that were found. Each associative array has the following keys: 'obj_id' => object id 'node_id' => node id 'ilias_owner' => user id, 'dav_owner' => user name, 'token' => locktoken 'expires' => expiration timestamp 'depth' => 0 or 'infinity' 'scope' => 'exclusive' or 'shared'

Definition at line 429 of file class.ilDAVLocks.php.

References $ilDB, $result, $row, DB_FETCHMODE_ASSOC, and writelog().

{
global $ilDB;
$this->writelog('getLocksOnPathDAV');
$q = 'SELECT obj_id, node_id, ilias_owner, dav_owner, token, expires, depth, scope'
.' FROM '.$this->table
.' WHERE expires > '.$ilDB->quote(time(),'integer')
.' AND ('
;
$isFirst = true;
foreach ($pathDAV as $objDAV)
{
$objId = $objDAV->getObjectId();
$nodeId = $objDAV->getNodeId();
if ($isFirst)
{
$isFirst = false;
} else {
$q .= ' OR ';
}
$q .= '(obj_id = '.$ilDB->quote($objId,'integer').' AND node_id = '.$ilDB->quote($nodeId,'integer').')';
}
$q .= ')';
$this->writelog('getLocksOnPathDAV('.$objDAV.') query='.$q);
$r = $ilDB->query($q);
$result = array();
while ($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
{
if ($row['depth'] == -1) $row['depth'] = 'infinity';
$row['scope'] = ($row['scope'] == 'x') ? 'exclusive' : 'shared';
}
$this->writelog('getLocksOnPathDAV:'.var_export($result,true));
return $result;
}

+ Here is the call graph for this function:

ilDAVLocks::getLocksOnPathRef (   $refId)

Returns all locks on the specified object, specified by a reference id.

Parameters
$refIdThe reference id of the object
Returns
An array of associative arrays for all the locks that were found. Each associative array has the following keys: 'obj_id' => object id 'node_id' => node id 'ilias_owner' => user id, 'dav_owner' => user name, 'token' => locktoken 'expires' => expiration timestamp 'depth' => 0 or 'infinity' 'scope' => 'exclusive' or 'shared'

Definition at line 482 of file class.ilDAVLocks.php.

References $ilDB, $result, $row, DB_FETCHMODE_ASSOC, and writelog().

Referenced by lockRef().

{
global $ilDB, $tree;
$this->writelog('getLocksOnPathRef('.$refId.')');
$pathFull = $tree->getPathFull($refId);
$q = 'SELECT obj_id, node_id, ilias_owner, dav_owner, token, expires, depth, scope'
.' FROM '.$this->table
.' WHERE expires > '.$ilDB->quote(time(),'integer')
.' AND ('
;
$isFirst = true;
foreach ($pathFull as $pathItem)
{
$objId = $pathItem['obj_id'];
$nodeId = 0;
if ($isFirst)
{
$isFirst = false;
} else {
$q .= ' OR ';
}
$q .= '(obj_id = '.$ilDB->quote($objId,'integer').' AND node_id = '.$ilDB->quote($nodeId,'integer').')';
}
$q .= ')';
$this->writelog('getLocksOnPathRef('.$refId.') query='.$q);
$r = $ilDB->query($q);
$result = array();
while ($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
{
if ($row['depth'] == -1) $row['depth'] = 'infinity';
$row['scope'] = ($row['scope'] == 'x') ? 'exclusive' : 'shared';
}
return $result;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDAVLocks::ilDAVLocks ( )

Definition at line 49 of file class.ilDAVLocks.php.

{
}
ilDAVLocks::lockRef (   $refId,
  $iliasUserId,
  $davUser,
  $token,
  $expires,
  $depth,
  $scope 
)

Creates a lock an object, unless there are locks on the object or its parents, which prevent the creation of the lock.

As described in RFC2518, chapter 7.1, a write lock prevents all principals whithout the lock from successfully executing a PUT, POST, PROPPATCH, LOCK, UNLOCK, MOVE, DELETE, or MKCOL on the locked resource. All other current methods, GET in particular, function independently of the lock. For a collection, the lock also affects the ability to add and remove members.

Parameters
intReference id of the object to be locked.
intThe id of a node of the object. For example the id of a page of a learning module. Specify 0 if the object does not have multiple nodes.
intILIAS user id of the lock owner.
stringDAV user of the lock owner.
stringLock token.
intexpiration timestamp for the lock.
boolDepth of the lock. Must be 0 or 'infinity'.
boolScope of the lock. Must be 'exclusive' or 'shared'.
Returns
true, if creation of lock succeeded, returns a string if the creation failed.

Definition at line 76 of file class.ilDAVLocks.php.

References $data, $result, getLocksOnPathRef(), lockWithoutCheckingObj(), updateLockWithoutCheckingObj(), and writelog().

{
$this->writelog('lockRef('.$refId.','.$iliasUserId.','.$davUser.','.$token.','.$expires.','.$depth.','.$scope.')');
global $tree, $txt;
$result = true;
$data = $tree->getNodeData($refId);
// Check whether a lock on the path to the object prevents the creation
// of a new lock
$locksOnPath = $this->getLocksOnPathRef($refId);
if ($scope == 'exclusive' && count($locksOnPath) > 0) {
$result = 'couldnt create exclusive lock due to existing lock on path '.var_export($locksOnPath,true);
}
foreach ($locksOnPath as $lock)
{
if ($lock['token'] == $token &&
$lock['obj_id'] == $data['obj_id'] &&
$lock['ilias_owner'] == $iliasUserId)
{
if ($this->updateLockWithoutCheckingObj($data['obj_id'], 0, $token, $expires))
{
return true;
}
else
{
return 'couldnt update lock';
}
}
}
if ($result === true)
{
foreach ($locksOnPath as $lock)
{
if ($lock['scope'] == 'exclusive' &&
($lock['depth'] == 'infinity' || $lock['obj_id'] == $data['obj_id']) &&
$lock['ilias_owner'] != $iliasUserId)
{
$result = 'couldnt create lock due to exclusive lock on path '.var_export($lock,true);
break;
}
}
}
// Check whether a lock on the children (subtree) of the object prevents
// the creation of a new lock
if ($result === true && $depth == 'infinity')
{
// XXX - if lock has depth infinity, we must check for locks in the subtree
}
if ($result === true)
{
$data['obj_id'], 0,
$iliasUserId, $davUser, $token, $expires, $depth, $scope
);
}
return $result;
}

+ Here is the call graph for this function:

ilDAVLocks::lockWithoutCheckingDAV ( $objDAV,
  $iliasUserId,
  $davUser,
  $token,
  $expires,
  $depth,
  $scope 
)

Creates a write lock.

Important: This is a low-level function, which does not check on existing locks, before creating the lock data.

As described in RFC2518, chapter 7.1, a write lock prevents all principals whithout the lock from successfully executing a PUT, POST, PROPPATCH, LOCK, UNLOCK, MOVE, DELETE, or MKCOL on the locked resource. All other current methods, GET in particular, function independently of the lock. For a collection, the lock also affects the ability to add and remove members.

Parameters
$objDAVDAV object to be locked.
intILIAS user id of the lock owner.
stringDAV user of the lock owner.
stringLock token.
intexpiration timestamp for the lock.
boolDepth of the lock. Must be 0 or 'infinity'.
boolScope of the lock. Must be 'exclusive' or 'shared'.
Returns
true, if creation of lock succeeded.

Definition at line 162 of file class.ilDAVLocks.php.

References lockWithoutCheckingObj().

{
$objId = $objDAV->getObjectId();
$nodeId = $objDAV->getNodeId();
return $this->lockWithoutCheckingObj($objId, $nodeId, $iliasUserId, $davUser, $token, $expires, $depth, $scope);
}

+ Here is the call graph for this function:

ilDAVLocks::lockWithoutCheckingObj (   $objId,
  $nodeId,
  $iliasUserId,
  $davUser,
  $token,
  $expires,
  $depth,
  $scope 
)

Creates a write lock.

       Important: This is a low-level function, which does not check on existing
       locks, before creating the lock data.

       As described in RFC2518, chapter 7.1, a write lock prevents all principals whithout
       the lock from successfully executing a PUT, POST, PROPPATCH, LOCK, UNLOCK, MOVE,
       DELETE, or MKCOL on the locked resource. All other current methods, GET in particular,
       function independently of the lock.
       For a collection, the lock also affects the ability to add and remove members.

       @param int id of the object to be locked.
       @param int node The id of a node of the object. For example the id of a page of a
       learning module. Specify 0 if the object does not have multiple nodes.

. *

Parameters
intILIAS user id of the lock owner.
stringDAV user of the lock owner.
stringLock token.
intexpiration timestamp for the lock.
boolDepth of the lock. Must be 0 or 'infinity'.
boolScope of the lock. Must be 'exclusive' or 'shared'.
Returns
true, if creation of lock succeeded.

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

References $ilDB, $result, PEAR\isError(), and writelog().

Referenced by lockRef(), and lockWithoutCheckingDAV().

{
global $ilDB;
switch ($depth)
{
case 'infinity' : $depth = -1;
break;
case 0 :
$depth = 0;
break;
default :
trigger_error('invalid depth '.$depth,E_ERROR);
return;
}
switch ($scope)
{
case 'exclusive' : $scope = 'x'; break;
case 'shared' : $scope = 's'; break;
default : trigger_error('invalid scope '.$scope,E_ERROR); return;
}
$q = 'INSERT INTO '.$this->table
.' SET obj_id = '.$ilDB->quote($objId,'integer')
.', node_id = '.$ilDB->quote($nodeId,'integer')
.', ilias_owner = '.$ilDB->quote($iliasUserId,'text')
.', dav_owner = '.$ilDB->quote($davUser,'text')
.', token = '.$ilDB->quote($token,'text')
.', expires = '.$ilDB->quote($expires,'integer')
.', depth = '.$ilDB->quote($depth,'integer')
.', type = \'w\''
.', scope = '.$ilDB->quote($scope,'text')
;
$this->writelog('lock query='.$q);
$result = $ilDB->manipulate($q);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDAVLocks::unlockWithoutCheckingDAV ( $objDAV,
  $token 
)

Discards a write lock.

Important: This is a low-level function, which does not check on existing locks, before deleting the lock data.

Parameters
$objDAVDAV object to be locked.
stringLock token.
Returns
true on success.

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

References $ilDB, $success, cleanUp(), and writelog().

{
global $ilDB;
$this->writelog('unlock('.$objDAV.','.$token.')');
$objId = $objDAV->getObjectId();
$nodeId = $objDAV->getNodeId();
// Unlock object
// FIXME - Maybe we should delete all rows with the same token, not
// just the ones with the same token, obj_id and node_id.
$q = 'DELETE FROM '.$this->table
.' WHERE token = '.$ilDB->quote($token,'text')
.' AND obj_id = '.$ilDB->quote($objId,'integer')
.' AND node_id = '.$ilDB->quote($nodeId,'integer')
;
$this->writelog('unlock query='.$q);
$aff = $ilDB->manipulate($q);
$success = $aff > 0;
// clean up expired locks in 1 out of 100 unlock requests
if (rand(1,100) == 1)
{
$this->cleanUp();
}
return $success;
}

+ Here is the call graph for this function:

ilDAVLocks::updateLockWithoutCheckingDAV ( $objDAV,
  $token,
  $expires 
)

Updates a write lock.

Important: This is a low-level function, which does not check on existing locks, before updating the lock data.

Parameters
stringLock token.
intexpiration timestamp for the lock.
Returns
true on success.

Definition at line 242 of file class.ilDAVLocks.php.

References $ilDB, and updateLockWithoutCheckingObj().

{
global $ilDB;
$objId = $objDAV->getObjectId();
$nodeId = $objDAV->getNodeId();
return $this->updateLockWithoutCheckingObj($objId, $nodeId, $token, $expires);
}

+ Here is the call graph for this function:

ilDAVLocks::updateLockWithoutCheckingObj (   $objId,
  $nodeId,
  $token,
  $expires 
)

Updates a write lock.

Important: This is a low-level function, which does not check on existing locks, before updating the lock data.

Parameters
stringLock token.
intexpiration timestamp for the lock.
Returns
true on success.

Definition at line 261 of file class.ilDAVLocks.php.

References $ilDB.

Referenced by lockRef(), and updateLockWithoutCheckingDAV().

{
global $ilDB;
$q = 'UPDATE '.$this->table
.' SET expires = '.$ilDB->quote($expires,'integer')
.' WHERE token = '.$ilDB->quote($token,'text')
.' AND obj_id = '.$ilDB->quote($objId,'integer')
.' AND node_id = '.$ilDB->quote($nodeId,'integer')
;
$aff = $ilDB->manipulate($q);
return $aff > 0;
}

+ Here is the caller graph for this function:

ilDAVLocks::writelog (   $message)
protected

Writes a message to the logfile.,.

Parameters
messageString.
Returns
void.

Definition at line 575 of file class.ilDAVLocks.php.

References $log.

Referenced by getLockDAV(), getLocksOnObjectObj(), getLocksOnPathDAV(), getLocksOnPathRef(), lockRef(), lockWithoutCheckingObj(), and unlockWithoutCheckingDAV().

{
global $log, $ilias;
if ($this->isDebug)
{
$log->write(
$ilias->account->getLogin()
.' DAV ilDAVLocks.'.str_replace("\n",";",$message)
);
}
/*
if ($this->logFile)
{
$fh = fopen($this->logFile, 'a');
fwrite($fh, date('Y-m-d h:i:s '));
fwrite($fh, str_replace("\n",";",$message));
fwrite($fh, "\n\n");
fclose($fh);
}*/
}

+ Here is the caller graph for this function:

Field Documentation

ilDAVLocks::$isDebug = false
private

Set this to true, to get debug output in the ILIAS log.

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

ilDAVLocks::$table = 'dav_lock'
private

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


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