1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Delete record action file. |
4
|
|
|
* |
5
|
|
|
* @package Action |
6
|
|
|
* |
7
|
|
|
* @copyright YetiForce S.A. |
8
|
|
|
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Delete record action class. |
13
|
|
|
*/ |
14
|
|
|
class Vtiger_Delete_Action extends \App\Controller\Action |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Record model instance. |
18
|
|
|
* |
19
|
|
|
* @var Vtiger_Record_Model |
20
|
|
|
*/ |
21
|
|
|
protected $record; |
22
|
|
|
|
23
|
|
|
/** {@inheritdoc} */ |
24
|
|
|
public function checkPermission(App\Request $request) |
25
|
|
|
{ |
26
|
|
|
if ($request->isEmpty('record', true)) { |
27
|
|
|
throw new \App\Exceptions\NoPermittedToRecord('ERR_NO_PERMISSIONS_FOR_THE_RECORD', 406); |
28
|
|
|
} |
29
|
|
|
$this->record = Vtiger_Record_Model::getInstanceById($request->getInteger('record'), $request->getModule()); |
30
|
|
|
if (!$this->record->privilegeToDelete()) { |
31
|
|
|
throw new \App\Exceptions\NoPermittedToRecord('ERR_NO_PERMISSIONS_FOR_THE_RECORD', 406); |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** {@inheritdoc} */ |
36
|
|
|
public function process(App\Request $request) |
37
|
|
|
{ |
38
|
|
|
$result = []; |
39
|
|
|
$eventHandler = $this->record->getEventHandler(); |
40
|
|
|
$skipHandlers = $request->getArray('skipHandlers', \App\Purifier::ALNUM, [], \App\Purifier::INTEGER); |
41
|
|
|
foreach ($eventHandler->getHandlers(\App\EventHandler::PRE_DELETE) as $handler) { |
42
|
|
|
$handlerId = $handler['eventhandler_id']; |
43
|
|
|
$response = $eventHandler->triggerHandler($handler); |
44
|
|
|
if (!($response['result'] ?? null) && (!isset($response['hash'], $skipHandlers[$handlerId]) || $skipHandlers[$handlerId] !== $response['hash'])) { |
45
|
|
|
if ($result && 'confirm' === ($response['type'] ?? '')) { |
|
|
|
|
46
|
|
|
break; |
47
|
|
|
} |
48
|
|
|
$result[$handlerId] = $response; |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
if (!$result) { |
|
|
|
|
53
|
|
|
$this->record->delete(); |
54
|
|
|
if ('List' === $request->getByType('sourceView')) { |
55
|
|
|
$result = ['notify' => ['type' => 'success', 'text' => \App\Language::translate('LBL_RECORD_HAS_BEEN_DELETED')]]; |
56
|
|
|
} else { |
57
|
|
|
$result = ['url' => $this->record->getModule()->getListViewUrl()]; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$response = new Vtiger_Response(); |
62
|
|
|
$response->setEmitType(Vtiger_Response::$EMIT_JSON); |
63
|
|
|
$response->setResult($result); |
64
|
|
|
$response->emit(); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.