DeleteController.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2020 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
12 
19 
20 /**
21  * DeleteController is used to delete Node instances.
22  *
23  * The controller supports the following actions:
24  *
25  * <div class="controller-action">
26  * <div> __Action__ _default_ </div>
27  * <div>
28  * Delete the given Node instance.
29  * | Parameter | Description
30  * |-----------------------|-------------------------
31  * | _in_ / _out_ `oid` | The object id of the Node to delete
32  * | __Response Actions__ | |
33  * | `ok` | In all cases
34  * </div>
35  * </div>
36  *
37  * @author ingo herwig <ingo@wemove.com>
38  */
40 
41  /**
42  * @see Controller::validate()
43  */
44  protected function validate() {
45  if (!$this->checkLanguageParameter()) {
46  return false;
47  }
48  // do default validation
49  return parent::validate();
50  }
51 
52  /**
53  * @see Controller::doExecute()
54  */
55  protected function doExecute($method=null) {
56  $this->requireTransaction();
57  $persistenceFacade = $this->getPersistenceFacade();
58  $request = $this->getRequest();
59  $response = $this->getResponse();
60  $logger = $this->getLogger();
61 
62  $oid = ObjectId::parse($request->getValue('oid'));
63 
64  try {
65  // load the doomed node
66  if ($oid) {
67  $doomedNode = $persistenceFacade->load($oid, BuildDepth::SINGLE);
68  if ($doomedNode == null) {
69  $logger->warn("An object with oid ".$oid." is does not exist.");
70  }
71  else {
72  // commit changes
73  $localization = $this->getLocalization();
74  if ($this->isLocalizedRequest()) {
75  // delete the translations for the requested language
76  $localization->deleteTranslation($doomedNode->getOID(), $request->getValue('language'));
77  }
78  else {
79  // delete the real object data and all translations
80  $localization->deleteTranslation($doomedNode->getOID());
81  $doomedNode->delete();
82  }
83  }
84  }
85  }
86  catch (PessimisticLockException $ex) {
87  throw new ApplicationException($request, $response,
88  ApplicationError::get('OBJECT_IS_LOCKED', ['lockedOids' => [$oid->__toString()]])
89  );
90  }
91 
92  $response->setValue('oid', $oid);
93  $response->setStatus(204);
94  $response->setAction('ok');
95  }
96 }
97 ?>
PessimisticLockException signals an exception when trying to create an pessimistic lock.
ObjectId is the unique identifier of an object.
Definition: ObjectId.php:27
BuildDepth values are used to define the depth when loading object trees.
Definition: BuildDepth.php:19
requireTransaction()
Start or join a transaction that will be committed at the end of execution.
Definition: Controller.php:334
getLogger()
Get the Logger instance.
Definition: Controller.php:267
ApplicationError is used to signal errors that occur while processing a request.
static parse($oid)
Parse a serialized object id string into an ObjectId instance.
Definition: ObjectId.php:134
static get($code, $data=null)
Factory method for retrieving a predefined error instance.
ApplicationException signals a general application exception.
getPersistenceFacade()
Get the PersistenceFacade instance.
Definition: Controller.php:283
getRequest()
Get the Request instance.
Definition: Controller.php:251
Application controllers.
Definition: namespaces.php:3
getLocalization()
Get the Localization instance.
Definition: Controller.php:307
Controller is the base class of all controllers.
Definition: Controller.php:49
isLocalizedRequest()
Check if the current request is localized.
Definition: Controller.php:366
DeleteController is used to delete Node instances.
getResponse()
Get the Response instance.
Definition: Controller.php:259
checkLanguageParameter()
Checks the language request parameter and adds an response error, if it is not contained in the Local...
Definition: Controller.php:381