403Webshell
Server IP : 104.21.14.103  /  Your IP : 18.223.158.160
Web Server : LiteSpeed
System : Linux business53.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64
User : giankuin ( 1871)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /proc/self/root/home/giankuin/thietke365.net/wp-content/plugins/mailpoet/lib/Cron/Workers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /proc/self/root/home/giankuin/thietke365.net/wp-content/plugins/mailpoet/lib/Cron/Workers//WooCommercePastOrders.php
<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing

namespace MailPoet\Cron\Workers;

if (!defined('ABSPATH')) exit;


use MailPoet\Entities\ScheduledTaskEntity;
use MailPoet\Entities\StatisticsClickEntity;
use MailPoet\Statistics\StatisticsClicksRepository;
use MailPoet\Statistics\Track\WooCommercePurchases;
use MailPoet\WooCommerce\Helper as WCHelper;
use MailPoetVendor\Carbon\Carbon;

class WooCommercePastOrders extends SimpleWorker {
  const TASK_TYPE = 'woocommerce_past_orders';
  const BATCH_SIZE = 20;

  /** @var WCHelper */
  private $woocommerceHelper;

  /** @var WooCommercePurchases */
  private $woocommercePurchases;

  /** @var StatisticsClicksRepository */
  private $statisticsClicksRepository;

  public function __construct(
    WCHelper $woocommerceHelper,
    StatisticsClicksRepository $statisticsClicksRepository,
    WooCommercePurchases $woocommercePurchases
  ) {
    $this->woocommerceHelper = $woocommerceHelper;
    $this->woocommercePurchases = $woocommercePurchases;
    $this->statisticsClicksRepository = $statisticsClicksRepository;
    parent::__construct();
  }

  public function checkProcessingRequirements() {
    return $this->woocommerceHelper->isWooCommerceActive() && empty($this->getCompletedTasks()); // run only once
  }

  public function processTaskStrategy(ScheduledTaskEntity $task, $timer) {
    $oldestClick = $this->statisticsClicksRepository->findOneBy([], ['createdAt' => 'asc']);
    if (!$oldestClick instanceof StatisticsClickEntity) {
      return true;
    }

    // continue from 'last_processed_id' from previous run
    $meta = $task->getMeta();
    $lastId = isset($meta['last_processed_id']) ? $meta['last_processed_id'] : 0;
    add_filter('posts_where', function ($where = '') use ($lastId) {
      global $wpdb;
      return $where . " AND {$wpdb->prefix}posts.ID > " . $lastId;
    }, 10, 2);

    $orderIds = $this->woocommerceHelper->wcGetOrders([
      'status' => 'completed',
      'date_completed' => '>=' . (($createdAt = $oldestClick->getCreatedAt()) ? $createdAt->format('Y-m-d H:i:s') : null),
      'orderby' => 'ID',
      'order' => 'ASC',
      'limit' => self::BATCH_SIZE,
      'return' => 'ids',
    ]);

    if (empty($orderIds)) {
      return true;
    }

    foreach ($orderIds as $orderId) {
      $this->woocommercePurchases->trackPurchase($orderId, false);
    }

    $task->setMeta(['last_processed_id' => end($orderIds)]);
    $this->scheduledTasksRepository->persist($task);
    $this->scheduledTasksRepository->flush();

    return false;
  }

  public function getNextRunDate() {
    return Carbon::createFromTimestamp($this->wp->currentTime('timestamp')); // schedule immediately
  }
}

Youez - 2016 - github.com/yon3zu
LinuXploit