Перегенерировать все превью товаров miniShop2

<?php

$step = 5;

$offset = isset($_SESSION['galgenoffset']) && $_SESSION['galgenoffset'] ? $_SESSION['galgenoffset'] : 0;

$miniShop2 = $modx->getService('minishop2');

$modx->setLogLevel(MODX_LOG_LEVEL_ERROR);

$q = $modx->newQuery('msProductFile', array('parent' => 0));

$total = $modx->getCount('msProductFile', $q);

$q->sortby('id','ASC');

$q->limit($step,$offset);

$resources = $modx->getCollection('msProductFile', $q);

foreach ($resources as $resource) {

  $modx->runProcessor('mgr/gallery/generate', array('id' => $resource->id),

    array('processors_path' => $modx->getOption('core_path').'components/minishop2/processors/'));

}


$_SESSION['galgenoffset'] = $offset + $step;

if ($_SESSION['galgenoffset'] >= $total) {

 $sucsess = 100;

 $_SESSION['Console']['completed'] = true;

 unset($_SESSION['galgenoffset']);

} else {

 $sucsess = round($_SESSION['galgenoffset'] / $total, 2) * 100;

 $_SESSION['Console']['completed'] = false;

}

for ($i=0; $i<=100; $i++) {

  if ($i <= $sucsess) {

    print '=';

  } else {

    print '_';

  }

}

$current = $_SESSION['galgenoffset'] ?

      $_SESSION['galgenoffset'] :

      ($sucsess == 100 ? $total : 0);

print "\n";

print $sucsess.'% ('.$current.')'."\n\n";