-
Notifications
You must be signed in to change notification settings - Fork 195
/
Copy pathOrphanedForms.php
68 lines (59 loc) · 1.67 KB
/
OrphanedForms.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace Give\Campaigns\Actions;
use Give\Campaigns\ValueObjects\CampaignType;
use Give\Framework\Database\DB;
use Give\Framework\QueryBuilder\QueryBuilder;
/**
* @unreleased
*/
class OrphanedForms
{
private string $hookName = 'give_campaign_check_forms';
private string $optionName = 'give_campaign_orphaned_forms';
/**
* @unreleased
*/
public function registerAction()
{
if ( ! as_has_scheduled_action($this->hookName)) {
as_schedule_recurring_action(
time(),
DAY_IN_SECONDS,
$this->hookName
);
}
add_action($this->hookName, function () {
$this->runAction();
});
}
/**
* @unreleased
*/
private function runAction()
{
// Bail out if we already collected orphaned forms
if (give_get_option($this->optionName)) {
return;
}
$forms = DB::table('posts')
->select('ID', 'post_title')
->where('post_type', 'give_forms')
->whereNotIn('ID', function (QueryBuilder $builder) {
$builder
->from('give_campaign_forms')
->select('form_id');
})
// p2p forms
->whereNotIn('ID', function (QueryBuilder $builder) {
$builder
->from('give_campaigns')
->select('form_id')
->where('campaign_type', CampaignType::CORE, '!=');
})
->getAll(ARRAY_A);
if ( ! $forms) {
return;
}
give_update_option($this->optionName, $forms);
}
}