Merge pull request #17641 from MegaphoneJon/core-1590
[civicrm-core.git] / CRM / Contact / Form / Task / Unhold.php
CommitLineData
6a488035 1<?php
86538308
EM
2
3/**
4 * Class CRM_Contact_Form_Task_Unhold
5 */
6a488035
TO
6class CRM_Contact_Form_Task_Unhold extends CRM_Contact_Form_Task {
7
8 /**
fe482240 9 * Set variables up before form is built.
6a488035 10 */
00be9182 11 public function preProcess() {
6a488035
TO
12 parent::preProcess();
13 }
14
00be9182 15 public function buildQuickForm() {
6a488035
TO
16 $this->addDefaultButtons(ts('Unhold Email'), 'done');
17 }
18
19 public function postProcess() {
20 // Query to unhold emails of selected contacts
21 $num = count($this->_contactIds);
22 if ($num >= 1) {
23 $queryString = "
8ef12e64 24UPDATE civicrm_email SET on_hold = 0, hold_date = null
6a488035 25WHERE on_hold = 1 AND hold_date is not null AND contact_id in (" . implode(",", $this->_contactIds) . ")";
c299571d 26 $result = CRM_Core_DAO::executeQuery($queryString);
27 $rowCount = $result->affectedRows();
28
29 if ($rowCount) {
be2fb01f 30 CRM_Core_Session::setStatus(ts('%count email was found on hold and updated.', [
69078420
SL
31 'count' => $rowCount,
32 'plural' => '%count emails were found on hold and updated.',
33 ]), ts('Emails Restored'), 'success');
6a488035
TO
34 }
35 else {
be2fb01f 36 CRM_Core_Session::setStatus(ts('The selected contact does not have an email on hold.', [
69078420
SL
37 'plural' => 'None of the selected contacts have an email on hold.',
38 ]), ts('No Emails to Restore'), 'info');
6a488035
TO
39 }
40 }
41 else {
42 CRM_Core_Session::setStatus(ts('Please select one or more contact for this action'), ts('No Contacts Selected'), 'error');
43 }
44 }
96025800 45
6a488035 46}