AddCampaignFormFromRequest.php
1 year ago
AddNewBadgeToAdminMenuItem.php
1 year ago
AllowGiveRolesToEditCampaignPages.php
1 month ago
ArchiveCampaignFormsAsDraftStatus.php
1 year ago
ArchiveCampaignPagesAsDraftStatus.php
1 year ago
AssignDuplicatedFormToCampaign.php
1 year ago
AssociateCampaignPageWithCampaign.php
1 year ago
CacheCampaignData.php
7 months ago
ConvertQueryDataToCampaign.php
1 year ago
CreateCampaignPage.php
1 year ago
CreateDefaultCampaignForm.php
4 months ago
CreateDefaultLayoutForCampaignPage.php
1 year ago
DuplicateCampaign.php
7 months ago
EnqueueCampaignPageEditorAssets.php
1 year ago
FormInheritsCampaignGoal.php
1 year ago
LoadCampaignAdminOptions.php
11 months ago
LoadCampaignDetailsAssets.php
1 year ago
LoadCampaignPublicOptions.php
11 months ago
LoadCampaignsListTableAssets.php
11 months ago
PreventDeleteDefaultForm.php
1 year ago
RedirectLegacyCreateFormToCreateCampaign.php
4 months ago
RegisterCampaignBlocks.php
6 months ago
RegisterCampaignIdRestField.php
1 year ago
RegisterCampaignShortcodes.php
10 months ago
RenderDonateButton.php
9 months ago
ReplaceGiveFormsCptLabels.php
1 year ago
UnarchiveCampaignFormAsPublishStatus.php
1 year ago
ArchiveCampaignFormsAsDraftStatus.php
49 lines
| 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 |