job-logger-trait.php
2 years ago
job-trait.php
2 years ago
self-execution-job-trait.php
2 years ago
time-based-trait.php
2 years ago
job-logger-trait.php
39 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace JFB_Modules\Jobs\Traits; |
| 5 | |
| 6 | use JFB_Modules\Jobs; |
| 7 | |
| 8 | // If this file is called directly, abort. |
| 9 | if ( ! defined( 'WPINC' ) ) { |
| 10 | die(); |
| 11 | } |
| 12 | |
| 13 | trait Job_Logger_Trait { |
| 14 | |
| 15 | private $logs = array(); |
| 16 | |
| 17 | public function log( string $message ) { |
| 18 | /** @var Jobs\Module $jobs */ |
| 19 | /** @noinspection PhpUnhandledExceptionInspection */ |
| 20 | $jobs = jet_form_builder()->module( 'jobs' ); |
| 21 | |
| 22 | if ( ! $jobs->get_action_id() ) { |
| 23 | $this->logs[] = $message; |
| 24 | |
| 25 | return; |
| 26 | } |
| 27 | |
| 28 | \ActionScheduler_Logger::instance()->log( |
| 29 | $jobs->get_action_id(), |
| 30 | $message |
| 31 | ); |
| 32 | } |
| 33 | |
| 34 | public function get_logs(): array { |
| 35 | return $this->logs; |
| 36 | } |
| 37 | |
| 38 | } |
| 39 |