PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
give / src / Campaigns / Actions / ArchiveCampaignFormsAsDraftStatus.php

ArchiveCampaignFormsAsDraftStatus.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/Campaigns/Actions/ArchiveCampaignFormsAsDraftStatus.php

49 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Campaigns\Actions;
4
5
6 use Give\Campaigns\Models\Campaign;
7 use Give\Framework\Database\DB;
8 use Give\Framework\QueryBuilder\JoinQueryBuilder;
9
10 /**
11 * When a Campaign is archived, set all Forms to Draft Status
12 *
13 * @since 4.0.0
14 */
15 class ArchiveCampaignFormsAsDraftStatus
16 {
17 /**
18 * TODO: update this to use single update query (QB was not working with whereIn and update)
19 * @since 4.0.0
20 */
21 public function __invoke(Campaign $campaign)
22 {
23 if (!$campaign->status->isArchived()) {
24 return;
25 }
26
27 $query = DB::table('posts')
28 ->where('post_type', 'give_forms')
29 ->where('post_status', 'publish')
30 ->join(function (JoinQueryBuilder $builder) {
31 $builder
32 ->leftJoin("give_campaign_forms", "campaign_forms")
33 ->on("campaign_forms.form_id", "id");
34 })
35 ->where("campaign_forms.campaign_id", $campaign->id)
36 ->getAll();
37
38 $ids = array_values(array_column($query, 'ID'));
39
40 foreach ($ids as $id) {
41 DB::table('posts')
42 ->where('ID', $id)
43 ->update(
44 ['post_status' => 'draft']
45 );
46 }
47 }
48 }
49