25 require_once
"classes/class.ilObject.php";
26 require_once
"Services/WebDAV/classes/class.ilObjNull.php";
76 public function lockRef($refId, $iliasUserId, $davUser, $token, $expires, $depth, $scope)
78 $this->
writelog(
'lockRef('.$refId.
','.$iliasUserId.
','.$davUser.
','.$token.
','.$expires.
','.$depth.
','.$scope.
')');
82 $data = $tree->getNodeData($refId);
88 if ($scope ==
'exclusive' && count($locksOnPath) > 0) {
89 $result =
'couldnt create exclusive lock due to existing lock on path '.var_export($locksOnPath,
true);
92 foreach ($locksOnPath as $lock)
94 if ($lock[
'token'] == $token &&
95 $lock[
'obj_id'] ==
$data[
'obj_id'] &&
96 $lock[
'ilias_owner'] == $iliasUserId)
104 return 'couldnt update lock';
111 foreach ($locksOnPath as $lock)
113 if ($lock[
'scope'] ==
'exclusive' &&
114 ($lock[
'depth'] ==
'infinity' || $lock[
'obj_id'] ==
$data[
'obj_id']) &&
115 $lock[
'ilias_owner'] != $iliasUserId)
117 $result =
'couldnt create lock due to exclusive lock on path '.var_export($lock,
true);
125 if (
$result ===
true && $depth ==
'infinity')
134 $iliasUserId, $davUser, $token, $expires, $depth, $scope
164 $objId = $objDAV->getObjectId();
165 $nodeId = $objDAV->getNodeId();
167 return $this->
lockWithoutCheckingObj($objId, $nodeId, $iliasUserId, $davUser, $token, $expires, $depth, $scope);
199 case 'infinity' : $depth = -1;
205 trigger_error(
'invalid depth '.$depth,E_ERROR);
211 case 'exclusive' : $scope =
'x';
break;
212 case 'shared' : $scope =
's';
break;
213 default : trigger_error(
'invalid scope '.$scope,E_ERROR);
return;
216 $q =
'INSERT INTO '.$this->table
217 .
' SET obj_id = '.$ilDB->quote($objId)
218 .
', node_id = '.$ilDB->quote($nodeId)
219 .
', ilias_owner = '.$ilDB->quote($iliasUserId)
220 .
', dav_owner = '.$ilDB->quote($davUser)
221 .
', token = '.$ilDB->quote($token)
222 .
', expires = '.$ilDB->quote($expires)
223 .
', depth = '.$ilDB->quote($depth)
225 .
', scope = '.$ilDB->quote($scope)
229 return ! PEAR::isError(
$result);
245 $objId = $objDAV->getObjectId();
246 $nodeId = $objDAV->getNodeId();
265 $q =
'UPDATE '.$this->table
266 .
' SET expires = '.$ilDB->quote($expires)
267 .
' WHERE token = '.$ilDB->quote($token)
268 .
' AND obj_id = '.$ilDB->quote($objId)
269 .
' AND node_id = '.$ilDB->quote($nodeId)
272 return mysql_affected_rows() > 0;
288 $this->
writelog(
'unlock('.$objDAV.
','.$token.
')');
290 $objId = $objDAV->getObjectId();
291 $nodeId = $objDAV->getNodeId();
296 $q =
'DELETE FROM '.$this->table
297 .
' WHERE token = '.$ilDB->quote($token)
298 .
' AND obj_id = '.$ilDB->quote($objId)
299 .
' AND node_id = '.$ilDB->quote($nodeId)
301 $this->
writelog(
'unlock query='.$q);
303 $success = mysql_affected_rows() > 0;
306 if (rand(1,100) == 1)
331 $this->
writelog(
'getLocks('.$objDAV.
')');
332 $objId = $objDAV->getObjectId();
333 $nodeId = $objDAV->getNodeId();
335 $q =
'SELECT ilias_owner, dav_owner, expires, depth, scope'
336 .
' FROM '.$this->table
337 .
' WHERE obj_id = '.$ilDB->quote($objId)
338 .
' AND node_id = '.$ilDB->quote($nodeId)
339 .
' AND token = '.$ilDB->quote($token)
341 $this->
writelog(
'getLocks('.$objDAV.
') query='.$q);
342 $r = $ilDB->query($q);
347 if ($row[
'depth'] == -1) $row[
'depth'] =
'infinity';
348 $row[
'scope'] = ($row[
'scope'] ==
'x') ?
'exclusive' :
'shared';
349 $row[
'token'] = $token;
370 $objId = $objDAV->getObjectId();
371 $nodeId = $objDAV->getNodeId();
394 $this->
writelog(
'getLocks('.$objDAV.
')');
397 $q =
'SELECT ilias_owner, dav_owner, token, expires, depth, scope'
398 .
' FROM '.$this->table
399 .
' WHERE obj_id = '.$ilDB->quote($objId)
400 .
' AND node_id = '.$ilDB->quote($nodeId)
401 .
' AND expires > '.$ilDB->quote(time())
403 $this->
writelog(
'getLocks('.$objDAV.
') query='.$q);
404 $r = $ilDB->query($q);
409 if ($row[
'depth'] == -1) $row[
'depth'] =
'infinity';
410 $row[
'scope'] = ($row[
'scope'] ==
'x') ?
'exclusive' :
'shared';
433 $this->
writelog(
'getLocksOnPath('.$pathDAV.
')');
435 $q =
'SELECT obj_id, node_id, ilias_owner, dav_owner, token, expires, depth, scope'
436 .
' FROM '.$this->table
437 .
' WHERE expires > '.$ilDB->quote(time())
441 foreach ($pathDAV as $objDAV)
443 $objId = $objDAV->getObjectId();
444 $nodeId = $objDAV->getNodeId();
451 $q .=
'(obj_id = '.$objId.
' AND node_id = '.$nodeId.
')';
455 $this->
writelog(
'getLocksOnPath('.$objDAV.
') query='.$q);
456 $r = $ilDB->query($q);
461 if ($row[
'depth'] == -1) $row[
'depth'] =
'infinity';
462 $row[
'scope'] = ($row[
'scope'] ==
'x') ?
'exclusive' :
'shared';
485 $this->
writelog(
'getLocksOnPathForRefId('.$refId.
')');
487 $pathFull = $tree->getPathFull($refId);
489 $q =
'SELECT obj_id, node_id, ilias_owner, dav_owner, token, expires, depth, scope'
490 .
' FROM '.$this->table
491 .
' WHERE expires > '.$ilDB->quote(time())
495 foreach ($pathFull as $pathItem)
497 $objId = $pathItem[
'obj_id'];
505 $q .=
'(obj_id = '.$objId.
' AND node_id = '.$nodeId.
')';
509 $this->
writelog(
'getLocksOnPathRef('.$refId.
') query='.$q);
510 $r = $ilDB->query($q);
515 if ($row[
'depth'] == -1) $row[
'depth'] =
'infinity';
516 $row[
'scope'] = ($row[
'scope'] ==
'x') ?
'exclusive' :
'shared';
531 $old = time() - 3600;
533 .
' FROM '.$this->table
534 .
' WHERE expires < '.$ilDB->quote($old)
541 $q =
'SELECT dat.obj_id '
542 .
' FROM object_data AS dat'
543 .
' LEFT JOIN '.$this->table.
' AS lck'
544 .
' ON dat.obj_id = lck.obj_id'
545 .
' WHERE dat.type = \'null\''
546 .
' AND lck.obj_id IS NULL'
550 $r = $ilDB->query($q);
554 $obj =&
new ilObjNull($row[
'obj_id'],
false);
555 if (count($references) == 0)
559 foreach ($references as $refId)
561 $obj->setRefId($refId);
563 $nodeData = $tree->getNodeData($refId);
564 $tree->deleteTree($nodeData);
581 $ilias->account->getLogin()
582 .
' DAV ilDAVLocks.'.str_replace(
"\n",
";",$message)