1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package org.openpsa.directmarketing |
4
|
|
|
* @author The Midgard Project, http://www.midgard-project.org |
5
|
|
|
* @copyright The Midgard Project, http://www.midgard-project.org |
6
|
|
|
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Cron handler for clearing tokens from old send receipts |
11
|
|
|
* |
12
|
|
|
* @package org.openpsa.directmarketing |
13
|
|
|
*/ |
14
|
|
|
class org_openpsa_directmarketing_cron_cleartokens extends midcom_baseclasses_components_cron_handler |
15
|
|
|
{ |
16
|
|
|
private int $cutoff; |
17
|
|
|
|
18
|
|
|
public function _on_initialize() : bool |
19
|
|
|
{ |
20
|
|
|
$days = $this->_config->get('send_token_max_age'); |
21
|
|
|
if ($days == 0) { |
22
|
|
|
debug_add('send_token_max_age evaluates to zero, aborting'); |
23
|
|
|
return false; |
24
|
|
|
} |
25
|
|
|
$this->cutoff = time() - ($days * 3600 * 24); |
26
|
|
|
|
27
|
|
|
return true; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Find all old send tokens and clear them. |
32
|
|
|
*/ |
33
|
|
|
public function execute() |
34
|
|
|
{ |
35
|
|
|
//Disable limits, TODO: think if this could be done in smaller chunks to save memory. |
36
|
|
|
midcom::get()->disable_limits(); |
37
|
|
|
|
38
|
|
|
$qb = org_openpsa_directmarketing_campaign_messagereceipt_dba::new_query_builder(); |
39
|
|
|
$qb->add_constraint('token', '<>', ''); |
40
|
|
|
$qb->add_constraint('metadata.created', '<', $this->cutoff); |
41
|
|
|
$qb->add_constraint('orgOpenpsaObtype', '=', org_openpsa_directmarketing_campaign_messagereceipt_dba::SENT); |
42
|
|
|
$ret = $qb->execute_unchecked(); |
43
|
|
|
|
44
|
|
|
foreach ($ret as $receipt) { |
45
|
|
|
debug_add("clearing token '{$receipt->token}' from receipt #{$receipt->id}"); |
46
|
|
|
$receipt->token = ''; |
47
|
|
|
if (!$receipt->update()) { |
48
|
|
|
debug_add("FAILED to update receipt #{$receipt->id}, errstr: " . midcom_connection::get_error_string(), MIDCOM_LOG_WARN); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|