wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.ConcurrencyController.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.ConcurrencyController.php 1462 2014-02-04 23:52:27Z iherwig $
18  */
19 require_once(BASE."wcmf/lib/presentation/class.Controller.php");
20 require_once(BASE."wcmf/lib/persistence/class.LockManager.php");
21 require_once(BASE."wcmf/lib/security/class.RightsManager.php");
22 
23 /**
24  * @class ConcurrencyController
25  * @ingroup Controller
26  * @brief ConcurrencyController is a controller that allows to lock/unlock objects.
27  *
28  * <b>Input actions:</b>
29  * - @em lock Lock an entity
30  * - @em unlock Unlock an entity
31  *
32  * <b>Output actions:</b>
33  * - @em ok In any case
34  *
35  * @param[in] oid The object id of the entity to lock/unlock
36  * @param[out] oid The object id of the entity to lock/unlock
37  *
38  * @author ingo herwig <ingo@wemove.com>
39  */
41 {
42  /**
43  * @see Controller::validate()
44  */
45  function validate()
46  {
47  if(!PersistenceFacade::isValidOID($this->_request->getValue('oid')))
48  {
49  $this->setErrorMsg("No valid 'oid' given in data.");
50  return false;
51  }
52  return true;
53  }
54  /**
55  * @see Controller::hasView()
56  */
57  function hasView()
58  {
59  return false;
60  }
61  /**
62  * (Un-)Lock the Node.
63  * @return Array of given context and action 'ok' in every case.
64  * @see Controller::executeKernel()
65  */
66  function executeKernel()
67  {
68  $lockManager = &LockManager::getInstance();
69  $rightsManager = &RightsManager::getInstance();
70  $session = &SessionData::getInstance();
71  $oid = $this->_request->getValue('oid');
72 
73  // process actions
74  if ($this->_request->getAction() == 'lock')
75  {
76  $lock = $lockManager->aquireLock($oid);
77  $authUser = $rightsManager->getAuthUser();
78  if ($lock && $authUser && ($lock->getLogin() != $authUser->getLogin() || $lock->getSessionID() != $session->getID()))
79  {
80  $this->appendErrorMsg($lockManager->getLockMessage($lock));
81  }
82  }
83  elseif ($this->_request->getAction() == 'unlock')
84  {
85  $lockManager->releaseLock($oid);
86  }
87 
88  $this->_response->setValue('oid', $oid);
89  $this->_response->setAction('ok');
90  return true;
91  }
92 }
93 ?>
94 
ConcurrencyController is a controller that allows to lock/unlock objects.
Controller is the base class of all controllers. If a Controller has a view it is expected to reside ...