PluginProbe ʕ •ᴥ•ʔ
Hostinger Reach – AI-Powered Email Marketing for WordPress / 1.5.9
Hostinger Reach – AI-Powered Email Marketing for WordPress v1.5.9
1.6.0 1.5.9 1.5.8 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 1.5.2 1.5.1 1.5.0 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 trunk 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6
hostinger-reach / src / Jobs / CleanupCartsJob.php
hostinger-reach / src / Jobs Last commit date
AbandonedCartsJob.php 7 months ago AbstractBatchedJob.php 7 months ago AbstractJob.php 5 months ago ActionScheduler.php 7 months ago CleanupCartsJob.php 2 weeks ago ImportJob.php 7 months ago JobInterface.php 8 months ago RecurringJobInterface.php 8 months ago
CleanupCartsJob.php
55 lines
1 <?php
2
3 namespace Hostinger\Reach\Jobs;
4
5 use Hostinger\Reach\Api\Handlers\ReachApiHandler;
6 use Hostinger\Reach\Repositories\CartRepository;
7
8 class CleanupCartsJob extends AbstractBatchedJob implements RecurringJobInterface {
9
10 public const JOB_NAME = 'cleanup_carts';
11 public const JOB_INTERVAL_SECONDS = DAY_IN_SECONDS;
12 protected CartRepository $cart_repository;
13
14 public function __construct( ActionScheduler $action_scheduler, ReachApiHandler $reach_api_handler, CartRepository $cart_repository ) {
15 parent::__construct( $action_scheduler, $reach_api_handler );
16 $this->cart_repository = $cart_repository;
17 }
18
19 public function get_name(): string {
20 return self::JOB_NAME;
21 }
22
23 public function schedule( array $args = array() ): void {
24 $this->schedule_create_batch_action( 1, $args );
25 }
26
27 public function can_schedule( array $args = array() ): bool {
28 return ! $this->is_running( $args );
29 }
30
31 public function get_interval(): int {
32 return self::JOB_INTERVAL_SECONDS;
33 }
34
35 protected function get_batch_size(): int {
36 return 20;
37 }
38
39 protected function get_batch( int $batch_number, array $args ): array {
40 return $this->cart_repository->old_carts( $this->get_batch_size(), array( 'hash' ) );
41 }
42
43 protected function process_items( array $args = array() ): void {
44 $items = $args['items'] ?? array();
45
46 if ( empty( $items ) ) {
47 return;
48 }
49
50 foreach ( $items as $item ) {
51 $this->cart_repository->delete( $item['hash'] );
52 }
53 }
54 }
55