Merge pull request #16142 from eileenmcnaughton/deadlock_err
[civicrm-core.git] / CRM / Member / Form / Task / Delete.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 * $Id$
17 *
18 */
19
20/**
21 * This class provides the functionality to delete a group of
22 * members. This class provides functionality for the actual
23 * deletion.
24 */
25class CRM_Member_Form_Task_Delete extends CRM_Member_Form_Task {
26
27 /**
28 * Are we operating in "single mode", i.e. deleting one
29 * specific membership?
30 *
d51c6add 31 * @var bool
6a488035
TO
32 */
33 protected $_single = FALSE;
34
35 /**
fe482240 36 * Build all the data structures needed to build the form.
6a488035
TO
37 *
38 * @return void
03e04002 39 */
00be9182 40 public function preProcess() {
6a488035
TO
41 //check for delete
42 if (!CRM_Core_Permission::checkActionPermission('CiviMember', CRM_Core_Action::DELETE)) {
beb414cc 43 CRM_Core_Error::statusBounce(ts('You do not have permission to access this page.'));
6a488035
TO
44 }
45 parent::preProcess();
46 }
47
48 /**
fe482240 49 * Build the form object.
6a488035 50 *
6a488035
TO
51 *
52 * @return void
53 */
00be9182 54 public function buildQuickForm() {
04c56698 55 $this->addDefaultButtons(ts('Delete Memberships'), 'done');
6a488035
TO
56 }
57
58 /**
fe482240 59 * Process the form after the input has been submitted and validated.
6a488035 60 *
6a488035 61 *
355ba699 62 * @return void
6a488035
TO
63 */
64 public function postProcess() {
99483ce8 65 $deleted = $failed = 0;
6a488035 66 foreach ($this->_memberIds as $memberId) {
3506b6cd 67 if (CRM_Member_BAO_Membership::del($memberId)) {
99483ce8 68 $deleted++;
6a488035 69 }
99483ce8
CW
70 else {
71 $failed++;
72 }
73 }
74
75 if ($deleted) {
be2fb01f 76 $msg = ts('%count membership deleted.', ['plural' => '%count memberships deleted.', 'count' => $deleted]);
99483ce8 77 CRM_Core_Session::setStatus($msg, ts('Removed'), 'success');
6a488035
TO
78 }
79
99483ce8 80 if ($failed) {
be2fb01f 81 CRM_Core_Session::setStatus(ts('1 could not be deleted.', ['plural' => '%count could not be deleted.', 'count' => $failed]), ts('Error'), 'error');
99483ce8 82 }
6a488035 83 }
96025800 84
6a488035 85}