LegacyListeners
2 years ago
Listeners
5 months ago
Migrations
9 months ago
Repositories
1 year ago
DonationHandler.php
1 year ago
RevenueServiceProvider.php
5 months ago
RevenueServiceProvider.php
64 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Revenue; |
| 4 | |
| 5 | use Give\Framework\Migrations\MigrationsRegister; |
| 6 | use Give\Helpers\Hooks; |
| 7 | use Give\Revenue\Listeners\DeleteRevenueWhenDonationPostDeleted; |
| 8 | use Give\Revenue\Listeners\DeleteRevenueWhenDonationDeleted; |
| 9 | use Give\Revenue\Listeners\UpdateRevenueWhenDonationUpdated; |
| 10 | use Give\Revenue\Migrations\AddPastDonationsToRevenueTable; |
| 11 | use Give\Revenue\Migrations\CreateRevenueTable; |
| 12 | use Give\Revenue\Migrations\RemoveRevenueForeignKeys; |
| 13 | use Give\ServiceProviders\ServiceProvider; |
| 14 | |
| 15 | class RevenueServiceProvider implements ServiceProvider |
| 16 | { |
| 17 | /** |
| 18 | * @inheritDoc |
| 19 | * |
| 20 | * @since 2.9.0 |
| 21 | */ |
| 22 | public function register() |
| 23 | { |
| 24 | global $wpdb; |
| 25 | |
| 26 | $wpdb->give_revenue = "{$wpdb->prefix}give_revenue"; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * @inheritDoc |
| 31 | * |
| 32 | * @since 4.14.0 rename delete_post handler to DeleteRevenueWhenDonationPostDeleted and add givewp_donation_deleted listener |
| 33 | * @since 3.3.0 added support for givewp_donation_updated and updated give_updated_edited_donation implementation |
| 34 | * @since 2.9.0 |
| 35 | */ |
| 36 | public function boot() |
| 37 | { |
| 38 | $this->registerMigrations(); |
| 39 | |
| 40 | Hooks::addAction('delete_post', DeleteRevenueWhenDonationPostDeleted::class); |
| 41 | Hooks::addAction('givewp_donation_deleted', DeleteRevenueWhenDonationDeleted::class); |
| 42 | Hooks::addAction('give_insert_payment', DonationHandler::class, 'handle', 999, 1); |
| 43 | Hooks::addAction('give_register_updates', AddPastDonationsToRevenueTable::class, 'register', 10, 1); |
| 44 | Hooks::addAction('givewp_donation_updated', UpdateRevenueWhenDonationUpdated::class); |
| 45 | Hooks::addAction('give_updated_edited_donation',LegacyListeners\UpdateRevenueWhenDonationAmountUpdated::class); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Registers database migrations with the MigrationsRunner |
| 50 | */ |
| 51 | private function registerMigrations() |
| 52 | { |
| 53 | /** @var MigrationsRegister $register */ |
| 54 | $register = give(MigrationsRegister::class); |
| 55 | |
| 56 | $register->addMigrations( |
| 57 | [ |
| 58 | CreateRevenueTable::class, |
| 59 | RemoveRevenueForeignKeys::class, |
| 60 | ] |
| 61 | ); |
| 62 | } |
| 63 | } |
| 64 |