Admin
5 years ago
Commands
5 years ago
Helpers
5 years ago
Migrations
5 years ago
ValueObjects
5 years ago
Assets.php
5 years ago
Log.php
5 years ago
LogFactory.php
5 years ago
LogModel.php
5 years ago
LogRepository.php
5 years ago
LogServiceProvider.php
5 years ago
LogServiceProvider.php
71 lines
| 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 |