Actions
2 years ago
Commands
2 years ago
Concerns
2 years ago
Contracts
2 years ago
Controllers
2 years ago
DataTransferObjects
2 years ago
Steps
2 years ago
FormMetaDecorator.php
2 years ago
Pipeline.php
2 years ago
ServiceProvider.php
2 years ago
StepProcessor.php
2 years ago
functions.php
2 years ago
ServiceProvider.php
143 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\FormMigration; |
| 4 | |
| 5 | use Give\DonationForms\V2\Models\DonationForm as DonationFormV2; |
| 6 | use Give\FormMigration\Commands\MigrationCommand; |
| 7 | use Give\FormMigration\Commands\TransferCommand; |
| 8 | use Give\FormMigration\Controllers\MigrationController; |
| 9 | use Give\FormMigration\Controllers\TransferController; |
| 10 | use Give\FormMigration\DataTransferObjects\TransferOptions; |
| 11 | use Give\ServiceProviders\ServiceProvider as ServiceProviderInterface; |
| 12 | use WP_CLI; |
| 13 | use WP_REST_Request; |
| 14 | use WP_REST_Server; |
| 15 | |
| 16 | /** |
| 17 | * @since 3.0.0 |
| 18 | */ |
| 19 | class ServiceProvider implements ServiceProviderInterface |
| 20 | { |
| 21 | /** |
| 22 | * @inheritDoc |
| 23 | */ |
| 24 | public function register() |
| 25 | { |
| 26 | give()->singleton(Pipeline::class, function () { |
| 27 | return new Pipeline([ |
| 28 | Steps\MigrateMeta::class, |
| 29 | Steps\FormTitle::class, |
| 30 | Steps\FormTemplate\ClassicTemplateSettings::class, |
| 31 | Steps\FormTemplate\SequoiaTemplateSettings::class, |
| 32 | Steps\FormTemplate\LegacyTemplateSettings::class, |
| 33 | Steps\DonationOptions::class, |
| 34 | Steps\RecurringDonationOptions::class, |
| 35 | Steps\FormFields::class, |
| 36 | Steps\FormFields\LoginRegistration::class, |
| 37 | Steps\FormFields\CompanyDonations::class, |
| 38 | Steps\DonationGoal::class, |
| 39 | Steps\TermsAndConditions::class, |
| 40 | Steps\FormGrid::class, |
| 41 | Steps\FormFieldManager::class, |
| 42 | Steps\OfflineDonations::class, |
| 43 | Steps\PaymentGateways::class, |
| 44 | Steps\EmailSettings::class, |
| 45 | Steps\FormMeta::class, |
| 46 | Steps\PdfSettings::class, |
| 47 | Steps\FeeRecovery::class, |
| 48 | Steps\ConstantContact::class, |
| 49 | Steps\PerFormGateways::class, |
| 50 | Steps\Mailchimp::class, |
| 51 | Steps\FundsAndDesignations::class, |
| 52 | Steps\GiftAid::class, |
| 53 | Steps\FormFeaturedImage::class, |
| 54 | Steps\FormExcerpt::class, |
| 55 | Steps\ConvertKit::class, |
| 56 | Steps\ActiveCampaign::class, |
| 57 | Steps\DoubleTheDonation::class, |
| 58 | ]); |
| 59 | }); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * @inheritDoc |
| 64 | */ |
| 65 | public function boot() |
| 66 | { |
| 67 | $this->registerRoutes(); |
| 68 | $this->registerCommands(); |
| 69 | } |
| 70 | |
| 71 | protected function registerRoutes() |
| 72 | { |
| 73 | add_action('rest_api_init', function () { |
| 74 | // give-api/v2/admin/forms/migrate |
| 75 | register_rest_route('give-api/v2', 'admin/forms/migrate/(?P<id>\d+)', [ |
| 76 | 'methods' => WP_REST_Server::CREATABLE, |
| 77 | 'callback' => function (WP_REST_Request $request) { |
| 78 | return (new MigrationController($request))( |
| 79 | DonationFormV2::find($request->get_param('id')) |
| 80 | ); |
| 81 | }, |
| 82 | 'permission_callback' => function () { |
| 83 | return current_user_can('manage_options'); |
| 84 | }, |
| 85 | 'args' => [ |
| 86 | 'id' => [ |
| 87 | 'type' => 'integer', |
| 88 | 'sanitize_callback' => 'absint', |
| 89 | 'description' => __('The ID of the form (v2) to migrate to v3.', 'give'), |
| 90 | ], |
| 91 | ], |
| 92 | ]); |
| 93 | |
| 94 | // give-api/v2/admin/forms/transfer |
| 95 | register_rest_route('give-api/v2', 'admin/forms/transfer', [ |
| 96 | 'methods' => WP_REST_Server::CREATABLE, |
| 97 | 'callback' => function (WP_REST_Request $request) { |
| 98 | return (new TransferController($request))( |
| 99 | DonationFormV2::find($request->get_param('formId')), |
| 100 | TransferOptions::fromRequest($request) |
| 101 | ); |
| 102 | }, |
| 103 | 'permission_callback' => function () { |
| 104 | return current_user_can('manage_options'); |
| 105 | }, |
| 106 | 'args' => [ |
| 107 | 'formId' => [ |
| 108 | 'type' => 'integer', |
| 109 | 'sanitize_callback' => function ($value) { |
| 110 | return intval($value); |
| 111 | // return array_map('intval', explode(',', $value)); |
| 112 | }, |
| 113 | 'description' => __('The ID of the form (v3) to transfer donations (from v2).', 'give'), |
| 114 | ], |
| 115 | 'changeUrl' => [ |
| 116 | 'type' => 'boolean', |
| 117 | 'required' => false, |
| 118 | 'default' => true, |
| 119 | ], |
| 120 | 'delete' => [ |
| 121 | 'type' => 'boolean', |
| 122 | 'required' => true, |
| 123 | ], |
| 124 | 'redirect' => [ |
| 125 | 'type' => 'boolean', |
| 126 | 'required' => false, |
| 127 | 'default' => true, |
| 128 | ], |
| 129 | ], |
| 130 | ]); |
| 131 | }, 9); |
| 132 | } |
| 133 | |
| 134 | protected function registerCommands() |
| 135 | { |
| 136 | if (defined('WP_CLI') && WP_CLI) { |
| 137 | error_reporting(E_ALL & ~E_DEPRECATED); |
| 138 | WP_CLI::add_command('givewp form:migrate', MigrationCommand::class); |
| 139 | WP_CLI::add_command('givewp form:transfer', TransferCommand::class); |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 |