<?php
require_once __DIR__ . '/../vendor/autoload.php';

use Blazemedia\Blackhole\Tools\DotEnv;
use Blazemedia\Blackhole\Tools\SimpleDB;
use Blazemedia\Blackhole\OffersReaper;


/** prepara l'istanza del DB */
(new DotEnv(__DIR__ . '/../../../../../.env'))->load();

$postType = getenv('OFFERS_POST_TYPE') !== false ? getenv('OFFERS_POST_TYPE') : 'news';

$limit = getenv('OFFERS_LIMIT') !== false ? getenv('OFFERS_LIMIT') : 500;

$db = SimpleDB::getInstance(  getenv('DB_HOST'), getenv('DB_NAME'), getenv('DB_USER'), getenv('DB_PASSWORD'), getenv('DB_PREFIX'), $postType);


/** Legge i parametri */
[ $cmd, $rollback ] = array_pad( $argv, 2, null);

$rollback = $rollback == 'rollback';

$offersReaper = new OffersReaper( $db );

if( $rollback ) {

    echo "reset all posts to 'publish'\n";
    $offersReaper->rollback();

} else {

    echo "set posts to blackhole \n";
    $offersReaper->blackhole( $limit );
}







