<?php

if (!empty($_SERVER['DOCUMENT_ROOT'])) {
    die("Access denied");
}

define('CRON_TASKS_BASE_PATH', __DIR__);
define('WP_USE_THEMES', false);
require(CRON_TASKS_BASE_PATH . '/../../../../wp-load.php');

use auctionforge\inc\abs\Importer;
use auctionforge\inc\helpers\SettingsHelper;
use auctionforge\inc\ImageUploader;
use auctionforge\inc\model\Lot;

if (!is_plugin_active(basename(dirname(__DIR__)) . '/' . basename(dirname(__DIR__)) . '.php')) {
    die("Plugin AuctionForge disabled\r\n");
}

$limit = 100;
$i = 0;
while ($lots = get_posts(
    array(
        'post_type' => 'lot',
        'numberposts' => $limit,
        'post_status' => array(
            SettingsHelper::STATUS_PUBLISH,
            SettingsHelper::STATUS_DRAFT,
            SettingsHelper::STATUS_TRASH,
            SettingsHelper::STATUS_FUTURE
        ),
        'offset' => $limit * $i,
        'lang' => ''
    )
)) {
    /** @var WP_Post $lot */
    foreach ($lots as $lot) {
        ImageUploader::deleteLotAttachment($lot->ID);
        Lot::updateMetaValue($lot->ID, 'load_images', '0');
        Lot::updateMetaValue($lot->ID, 'lot_lastUpdate', time() * 1000);
    }
    $i++;
}
