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