wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.DeleteController.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.DeleteController.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.PersistenceFacade.php");
21 require_once(BASE."wcmf/lib/persistence/class.LockManager.php");
22 require_once(BASE."wcmf/lib/model/class.Node.php");
23 
24 /**
25  * @class DeleteController
26  * @ingroup Controller
27  * @brief DeleteController is a controller that delete Nodes.
28  *
29  * <b>Input actions:</b>
30  * - unspecified: Delete given Nodes
31  *
32  * <b>Output actions:</b>
33  * - @em ok In any case
34  *
35  * @param[in] deleteoids A comma-separated string of the oids of the Nodes to delete.
36  * @param[out] oids A comma-separated string of the oids of the deleted Nodes.
37  * @param[out] poid The last parent oid of the last deleted Node.
38  *
39  * @author ingo herwig <ingo@wemove.com>
40  */
42 {
43  /**
44  * @see Controller::hasView()
45  */
46  function hasView()
47  {
48  return false;
49  }
50  /**
51  * Delete given Nodes.
52  * @return Array of given context and action 'ok' in every case.
53  * @attention This controller always does a recursive delete
54  * @see Controller::executeKernel()
55  */
56  function executeKernel()
57  {
58  $persistenceFacade = &PersistenceFacade::getInstance();
59  $lockManager = &LockManager::getInstance();
60 
61  // for deleting nodes we need not know the correct relations between the nodes
62  // so we store the nodes to delete in an array and iterate over it when deleting
63  $deleteArray = array();
64  $removedOIDs = array();
65 
66  // start the persistence transaction
67  $persistenceFacade->startTransaction();
68 
69  // load doomed children
70  foreach(split(",", $this->_request->getValue('deleteoids')) as $doid)
71  {
72  // if the current user has a lock on the object, release it
73  $lockManager->releaseLock($doid);
74 
75  // check if the object belonging to doid is locked and continue with next if so
76  $lock = $lockManager->getLock($doid);
77  if ($lock != null)
78  {
79  $this->appendErrorMsg($lockManager->getLockMessage($lock, $doid));
80  continue;
81  }
82 
83  $doomedChild = &$persistenceFacade->load($doid, BUILDDEPTH_SINGLE);
84  if ($doomedChild != null)
85  {
86  if($this->confirmDelete($doomedChild))
87  {
88  $poids = $doomedChild->getProperty('parentoids');
89  $removedOIDs[$doid] = $poids;
90  $doomedChild->setState(STATE_DELETED);
91  $deleteArray[sizeof($deleteArray)] = &$doomedChild;
92  }
93  }
94  else
95  Log::warn(Message::get("An object with oid %1% is does not exist.", array($doid)), __CLASS__);
96  }
97 
98  // commit changes
99  $localization = Localization::getInstance();
100  for($i=0; $i<sizeof($deleteArray); $i++)
101  {
102  $curObj = &$deleteArray[$i];
103  if ($this->isLocalizedRequest())
104  {
105  // delete the translations for the requested language
106  $localization->deleteTranslation($curObj->getOID(), $this->_request->getValue('language'));
107  }
108  else
109  {
110  // delete the real object data and all translations
111  $localization->deleteTranslation($curObj->getOID());
112  $curObj->delete();
113  }
114  }
115 
116  // after delete
117  $lastPOID = null;
118  foreach($removedOIDs as $oid => $poids)
119  {
120  $this->afterDelete($oid, $poids);
121  $lastPOID = $poids[sizeof($poids)-1];
122  }
123 
124  // end the persistence transaction
125  $persistenceFacade->commitTransaction();
126 
127  $this->_response->setValue('poid', $lastPOID);
128  $this->_response->setValue('oids', array_keys($removedOIDs));
129  $this->_response->setAction('ok');
130  return true;
131  }
132  /**
133  * Confirm delete action on given Node.
134  * @note subclasses will override this to implement special application requirements.
135  * @param node A reference to the Node to confirm.
136  * @return True/False whether the Node should be deleted [default: true].
137  */
138  function confirmDelete(&$node)
139  {
140  return true;
141  }
142  /**
143  * Called after delete.
144  * @note subclasses will override this to implement special application requirements.
145  * @param oid The oid of the Node deleted.
146  * @param poids An array of oids of the Nodes from that the Node was deleted.
147  * @note The method is called for all delete candidates even if they are not deleted.
148  */
149  function afterDelete($oid, $poids) {}
150 }
151 ?>
DeleteController is a controller that delete Nodes.
const STATE_DELETED
get($message, $parameters=null, $domain='', $lang='')
warn($message, $category)
Definition: class.Log.php:59
Controller is the base class of all controllers. If a Controller has a view it is expected to reside ...
const BUILDDEPTH_SINGLE