wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.LockManagerRDB.php
Go to the documentation of this file.
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2014 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of any of the following licenses
7  * at your choice:
8  *
9  * - GNU Lesser General Public License (LGPL)
10  * http://www.gnu.org/licenses/lgpl.html
11  * - Eclipse Public License (EPL)
12  * http://www.eclipse.org/org/documents/epl-v10.php
13  *
14  * See the license.txt file distributed with this work for
15  * additional information.
16  *
17  * $Id: class.LockManagerRDB.php 1462 2014-02-04 23:52:27Z iherwig $
18  */
19 require_once(BASE."wcmf/lib/persistence/class.LockManager.php");
20 require_once(BASE."wcmf/lib/util/class.InifileParser.php");
21 require_once(BASE."wcmf/lib/persistence/class.PersistenceFacade.php");
22 
23 /**
24  * @class LockManagerRDB
25  * @ingroup Persistence
26  * @brief LockManagerRDB implements a LockManager for relational databases.
27  * Locks are represented by the entity type 'Locktable' with attributes
28  * 'sessionid', 'objectid', 'since' (all DATATYPE_ATTRIBUTE). Locktable
29  * instances are children of the user entity.
30  *
31  * @author ingo herwig <ingo@wemove.com>
32  */
34 {
35  /**
36  * @see LockManager::aquireLockImpl();
37  */
38  function aquireLockImpl($useroid, $sessid, $oid, $lockDate)
39  {
40  $persistenceFacade = &PersistenceFacade::getInstance();
41  $lock = &$persistenceFacade->create('Locktable', BUILDDEPTH_REQUIRED);
42  $lock->setValue('sessionid', $sessid, DATATYPE_ATTRIBUTE);
43  $lock->setValue('objectid', $oid, DATATYPE_ATTRIBUTE);
44  $lock->setValue('since', $lockDate, DATATYPE_ATTRIBUTE);
45  // create a temporary user instance just for creating the relation
46  // if a user has many objects attached, loading it takes too long
47  $user = $persistenceFacade->create(UserManager::getUserClassName(), BUILDDEPTH_SINGLE);
48  $user->setOID($useroid);
49  $user->addChild($lock);
50  $lock->save();
51  }
52  /**
53  * @see LockManager::releaseLockImpl();
54  */
55  function releaseLockImpl($useroid, $sessid, $oid)
56  {
57  $query = &PersistenceFacade::createObjectQuery('Locktable');
58  $tpl = &$query->getObjectTemplate('Locktable');
59  if ($sessid != null) {
60  $tpl->setValue('sessionid', "= '".$sessid."'", DATATYPE_ATTRIBUTE);
61  }
62  if ($oid != null) {
63  $tpl->setValue('objectid', "= '".$oid."'", DATATYPE_ATTRIBUTE);
64  }
65  if ($useroid != null)
66  {
67  $userTpl = &$query->getObjectTemplate(UserManager::getUserClassName());
68  $userTpl->setOID($useroid);
69  $userTpl->addChild($tpl);
70  }
71  $locks = $query->execute(BUILDDEPTH_SINGLE);
72  foreach($locks as $lock)
73  $lock->delete();
74  }
75  /**
76  * @see LockManager::releaseAllLocksImpl();
77  */
78  function releaseAllLocksImpl($useroid, $sessid)
79  {
80  $this->releaseLockImpl($useroid, $sessid, null);
81  }
82  /**
83  * @see LockManager::getLockImpl();
84  */
85  function getLockImpl($oid)
86  {
87  // deactivate locking
88  $parser = &InifileParser::getInstance();
89  $oldLocking = $parser->getValue('locking', 'cms');
90  $parser->setValue('locking', false, 'cms');
91 
92  // load locks
94  $tpl1 = &$query->getObjectTemplate(UserManager::getUserClassName());
95  $tpl2 = &$query->getObjectTemplate('Locktable');
96  $tpl2->setValue('objectid', "= '".$oid."'", DATATYPE_ATTRIBUTE);
97  $tpl1->addChild($tpl2);
98  $users = $query->execute(BUILDDEPTH_SINGLE);
99 
100  // reactivate locking
101  $parser->setValue('locking', $oldLocking, 'cms');
102 
103  if (sizeof($users) == 0) {
104  return null;
105  }
106  else
107  {
108  $user = &$users[0];
109  $user->loadChildren('Locktable');
110  $locks = $user->getChildrenEx(null, 'Locktable', array('objectid' => $oid), null);
111  if (sizeof($locks) > 0) {
112  $lock = &$locks[0];
113  }
114  else {
115  $lock = &$tpl2;
116  }
117  return new Lock($oid, $user->getOID(), $user->getLogin(),
118  $lock->getValue('sessionid', DATATYPE_ATTRIBUTE),
119  $lock->getValue('since', DATATYPE_ATTRIBUTE));
120  }
121  }
122 }
123 ?>
LockManager is used to handle lock requests on objects.
const DATATYPE_ATTRIBUTE
releaseLockImpl($useroid, $sessid, $oid)
releaseAllLocksImpl($useroid, $sessid)
LockManagerRDB implements a LockManager for relational databases. Locks are represented by the entity...
const BUILDDEPTH_REQUIRED
aquireLockImpl($useroid, $sessid, $oid, $lockDate)
const BUILDDEPTH_SINGLE
Lock represents a lock on an object.
Definition: class.Lock.php:27