Skip to content

Instantly share code, notes, and snippets.

@Rachind
Created October 19, 2016 09:43
Show Gist options
  • Save Rachind/5e8f1d6af44c9804a9432445e7d641ed to your computer and use it in GitHub Desktop.
Save Rachind/5e8f1d6af44c9804a9432445e7d641ed to your computer and use it in GitHub Desktop.
MODX Regenerate Preview 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('msProduct');
$total = $modx->getCount('msProduct', $q);
$q->sortby('id','ASC');
$q->limit($step,$offset);
$resources = $modx->getCollection('msProduct', $q);
$q->prepare();
$q->stmt->execute();
$resources = $q->stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($resources as $resource) {
$c = $modx->newQuery('msProductFile', array(
'product_id' => $resource['msProduct_id'],
'parent' => 0
));
$c->prepare(); $c->stmt->execute();
$files = $c->stmt->fetchAll(PDO::FETCH_ASSOC);
foreach($files as $file) {
$modx->runProcessor('mgr/gallery/generate', array('id' => $file['msProductFile_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";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment