PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.17.0
GiveWP – Donation Plugin and Fundraising Platform v2.17.0
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 2.31.0 2.31.1 All 253 releases
give / src / Log / LogServiceProvider.php

LogServiceProvider.php in GiveWP – Donation Plugin and Fundraising Platform 2.17.0, at src/Log/LogServiceProvider.php

71 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Log;
4
5 use WP_CLI;
6 use Give\Helpers\Hooks;
7 use Give\Log\Commands\FlushLogsCommand;
8 use Give\ServiceProviders\ServiceProvider;
9 use Give\Framework\Migrations\MigrationsRegister;
10 use Give\Log\Migrations\CreateNewLogTable;
11 use Give\Log\Migrations\MigrateExistingLogs;
12 use Give\Log\Migrations\DeleteOldLogTables;
13 use Give\Log\Helpers\Environment;
14
15 /**
16 * Class LogServiceProvider
17 * @package Give\Log
18 *
19 * @since 2.10.0
20 */
21 class LogServiceProvider implements ServiceProvider {
22 /**
23 * @inheritdoc
24 */
25 public function register() {
26 global $wpdb;
27
28 $wpdb->give_log = "{$wpdb->prefix}give_log";
29
30 give()->singleton( Log::class );
31 give()->singleton( LogRepository::class );
32 }
33
34 /**
35 * @inheritdoc
36 */
37 public function boot() {
38 $this->registerMigrations();
39
40 if ( defined( 'WP_CLI' ) && WP_CLI ) {
41 $this->registerCliCommands();
42 }
43
44 Hooks::addAction( 'give_register_updates', MigrateExistingLogs::class, 'register' );
45
46 // Hook up
47 if ( Environment::isLogsPage() ) {
48 Hooks::addAction( 'admin_enqueue_scripts', Assets::class, 'enqueueScripts' );
49 }
50 }
51
52 /**
53 * Register migration
54 */
55 private function registerMigrations() {
56 give( MigrationsRegister::class )->addMigration( CreateNewLogTable::class );
57
58 // Check if Logs migration batch processing is completed
59 if ( give_has_upgrade_completed( MigrateExistingLogs::id() ) ) {
60 give( MigrationsRegister::class )->addMigration( DeleteOldLogTables::class );
61 }
62 }
63
64 /**
65 * Register CLI commands
66 */
67 private function registerCliCommands() {
68 WP_CLI::add_command( 'give flush-logs', give()->make( FlushLogsCommand::class ) );
69 }
70 }
71