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
AssignDuplicatedFormToCampaign.php
55 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Campaigns\Actions; |
| 4 | |
| 5 | use Give\Campaigns\Repositories\CampaignRepository; |
| 6 | use Give\Log\Log; |
| 7 | |
| 8 | /** |
| 9 | * @since 4.0.0 |
| 10 | */ |
| 11 | class AssignDuplicatedFormToCampaign |
| 12 | { |
| 13 | /** |
| 14 | * @since 4.0.0 |
| 15 | * @var CampaignRepository |
| 16 | */ |
| 17 | protected $campaignRepository; |
| 18 | |
| 19 | /** |
| 20 | * @since 4.0.0 |
| 21 | */ |
| 22 | public function __construct(CampaignRepository $campaignRepository) |
| 23 | { |
| 24 | $this->campaignRepository = $campaignRepository; |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * @since 4.0.0 |
| 29 | */ |
| 30 | public function __invoke($duplicatedFormID, $originalFormID) |
| 31 | { |
| 32 | $campaign = $this->campaignRepository->queryByFormId($originalFormID)->get(); |
| 33 | |
| 34 | if(!$campaign) { |
| 35 | Log::error('Campaign does not exist for duplicated form.', [ |
| 36 | 'duplicated_form_id' => $duplicatedFormID, |
| 37 | 'original_form_id' => $originalFormID, |
| 38 | ]); |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | try { |
| 43 | $this->campaignRepository->addCampaignForm($campaign, $duplicatedFormID, true); |
| 44 | } catch (\Exception $e) { |
| 45 | Log::error('Failed to assign duplicated form to campaign.', [ |
| 46 | 'campaign_id' => $campaign->id, |
| 47 | 'duplicated_form_id' => $duplicatedFormID, |
| 48 | 'original_form_id' => $originalFormID, |
| 49 | 'error' => $e->getMessage(), |
| 50 | ]); |
| 51 | return; |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 |