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