Fix missing thumbs images for products

This commit is contained in:
Laurent Destailleur 2017-06-09 00:27:44 +02:00
parent 75624376a5
commit 811b0d9af4

View File

@ -26,6 +26,7 @@
include_once 'inc.php'; include_once 'inc.php';
if (file_exists($conffile)) include_once $conffile; if (file_exists($conffile)) include_once $conffile;
require_once $dolibarr_main_document_root.'/core/lib/admin.lib.php'; require_once $dolibarr_main_document_root.'/core/lib/admin.lib.php';
include_once $dolibarr_main_document_root.'/core/lib/images.lib.php';
require_once $dolibarr_main_document_root.'/core/class/extrafields.class.php'; require_once $dolibarr_main_document_root.'/core/class/extrafields.class.php';
require_once 'lib/repair.lib.php'; require_once 'lib/repair.lib.php';
@ -72,11 +73,12 @@ $actiondone=1;
print '<h3>'.$langs->trans("Repair").'</h3>'; print '<h3>'.$langs->trans("Repair").'</h3>';
print 'Option restore_thirdparties_logos is '.(GETPOST('restore_thirdparties_logos')?GETPOST('restore_thirdparties_logos'):'0').'<br>'."\n"; print 'Option restore_thirdparties_logos is '.(GETPOST('restore_thirdparties_logos','alpha')?GETPOST('restore_thirdparties_logos','alpha'):'0').'<br>'."\n";
print 'Option clean_linked_elements is '.(GETPOST('clean_linked_elements')?GETPOST('clean_linked_elements'):'0').'<br>'."\n"; print 'Option clean_linked_elements is '.(GETPOST('clean_linked_elements','alpha')?GETPOST('clean_linked_elements','alpha'):'0').'<br>'."\n";
print 'Option clean_orphelin_dir (0 or \'test\' or \'confirmed\') is '.(GETPOST('clean_orphelin_dir')?GETPOST('clean_orphelin_dir'):'0').'<br>'."\n"; print 'Option clean_orphelin_dir (0 or \'test\' or \'confirmed\') is '.(GETPOST('clean_orphelin_dir','alpha')?GETPOST('clean_orphelin_dir','alpha'):'0').'<br>'."\n";
print 'Option clean_product_stock_batch (0 or \'test\' or \'confirmed\') is '.(GETPOST('clean_product_stock_batch')?GETPOST('clean_product_stock_batch'):'0').'<br>'."\n"; print 'Option clean_product_stock_batch (0 or \'test\' or \'confirmed\') is '.(GETPOST('clean_product_stock_batch','alpha')?GETPOST('clean_product_stock_batch','alpha'):'0').'<br>'."\n";
print 'Option set_empty_time_spent_amount (0 or \'test\' or \'confirmed\') is '.(GETPOST('set_empty_time_spent_amount')?GETPOST('set_empty_time_spent_amount'):'0').'<br>'."\n"; print 'Option set_empty_time_spent_amount (0 or \'test\' or \'confirmed\') is '.(GETPOST('set_empty_time_spent_amount','alpha')?GETPOST('set_empty_time_spent_amount','alpha'):'0').'<br>'."\n";
print 'Option rebuild_product_thumbs (0 or \'test\' or \'confirmed\') is '.(GETPOST('rebuild_product_thumbs','alpha')?GETPOST('rebuild_product_thumbs','alpha'):'0').'<br>'."\n";
print '<br>'; print '<br>';
print '<table cellspacing="0" cellpadding="1" border="0" width="100%">'; print '<table cellspacing="0" cellpadding="1" border="0" width="100%">';
@ -253,7 +255,7 @@ if ($ok)
{ {
print 'Found field '.$code.' declared into '.MAIN_DB_PREFIX.'extrafields table but not found into desc of table '.$tableextra." -> "; print 'Found field '.$code.' declared into '.MAIN_DB_PREFIX.'extrafields table but not found into desc of table '.$tableextra." -> ";
$type=$extrafields->attribute_type[$code]; $length=$extrafields->attribute_size[$code]; $attribute=''; $default=''; $extra=''; $null='null'; $type=$extrafields->attribute_type[$code]; $length=$extrafields->attribute_size[$code]; $attribute=''; $default=''; $extra=''; $null='null';
if ($type=='boolean') { if ($type=='boolean') {
$typedb='int'; $typedb='int';
$lengthdb='1'; $lengthdb='1';
@ -276,7 +278,7 @@ if ($ok)
$typedb=$type; $typedb=$type;
$lengthdb=$length; $lengthdb=$length;
} }
$field_desc=array( $field_desc=array(
'type'=>$typedb, 'type'=>$typedb,
'value'=>$lengthdb, 'value'=>$lengthdb,
@ -318,13 +320,13 @@ if ($ok)
// clean_linked_elements: Check and clean linked elements // restore_thirdparties_logos: Move logos to correct new directory.
if ($ok && GETPOST('restore_thirdparties_logos')) if ($ok && GETPOST('restore_thirdparties_logos'))
{ {
//$exts=array('gif','png','jpg'); //$exts=array('gif','png','jpg');
$ext=''; $ext='';
print '<tr><td colspan="2"><br>*** Restore thirdparties logo<br>'; print '<tr><td colspan="2"><br>*** Restore thirdparties logo<br>';
//foreach($exts as $ext) //foreach($exts as $ext)
//{ //{
@ -393,8 +395,66 @@ if ($ok && GETPOST('restore_thirdparties_logos'))
} }
// rebuild_product_thumbs: Rebuild thumbs for product files
if ($ok && GETPOST('rebuild_product_thumbs','alpha'))
{
$ext='';
global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini;
print '<tr><td colspan="2"><br>*** Rebuild product thumbs<br>';
$sql="SELECT s.rowid, s.ref FROM ".MAIN_DB_PREFIX."product as s ORDER BY s.ref";
$resql=$db->query($sql);
if ($resql)
{
$num=$db->num_rows($resql);
$i=0;
while($i < $num)
{
$obj=$db->fetch_object($resql);
if (! empty($obj->ref))
{
$files=dol_dir_list($dolibarr_main_data_root.'/produit/'.$obj->ref, 'files', 0);
foreach($files as $file)
{
// Generate thumbs.
if (image_format_supported($file['fullname']) == 1)
{
$imgThumbSmall='notbuild';
if (GETPOST('rebuild_product_thumbs','alpha') == 'confirmed')
{
// Used on logon for example
$imgThumbSmall = vignette($file['fullname'], $maxwidthsmall, $maxheightsmall, '_small', 50, "thumbs");
}
print 'Check product '.$obj->rowid.", file ".$file['fullname']." -> ".$imgThumbSmall." maxwidthsmall=".$maxwidthsmall." maxheightsmall=".$maxheightsmall."<br>\n";
$imgThumbMini='notbuild';
if (GETPOST('rebuild_product_thumbs','alpha') == 'confirmed')
{
// Create mini thumbs for image (Ratio is near 16/9)
// Used on menu or for setup page for example
$imgThumbMini = vignette($file['fullname'], $maxwidthmini, $maxheightmini, '_mini', 50, "thumbs");
}
print 'Check product '.$obj->rowid.", file ".$file['fullname']." -> ".$imgThumbMini." maxwidthmini=".$maxwidthmini." maxheightmini=".$maxheightmini."<br>\n";
}
}
}
$i++;
}
}
else
{
$ok=0;
dol_print_error($db);
}
print '</td></tr>';
}
// clean_linked_elements: Check and clean linked elements // clean_linked_elements: Check and clean linked elements
if ($ok && GETPOST('clean_linked_elements')) if ($ok && GETPOST('clean_linked_elements','alpha'))
{ {
print '<tr><td colspan="2"><br>*** Check table of linked elements and delete orphelins links</td></tr>'; print '<tr><td colspan="2"><br>*** Check table of linked elements and delete orphelins links</td></tr>';
// propal => order // propal => order
@ -418,7 +478,7 @@ if ($ok && GETPOST('clean_linked_elements'))
// clean_orphelin_dir: Run purge of directory // clean_orphelin_dir: Run purge of directory
if ($ok && GETPOST('clean_orphelin_dir')) if ($ok && GETPOST('clean_orphelin_dir','alpha'))
{ {
$conf->setValues($db); $conf->setValues($db);
@ -530,7 +590,7 @@ if ($ok && GETPOST('clean_orphelin_dir'))
// Clean of orphelins directories are done into repair.php // Clean of orphelins directories are done into repair.php
print '<tr><td colspan="2">'; print '<tr><td colspan="2">';
print 'Delete orphelins file '.$file['fullname'].'<br>'; print 'Delete orphelins file '.$file['fullname'].'<br>';
if (GETPOST('clean_orphelin_dir') == 'confirmed') if (GETPOST('clean_orphelin_dir','alpha') == 'confirmed')
{ {
dol_delete_file($file['fullname'],1,1,1); dol_delete_file($file['fullname'],1,1,1);
dol_delete_dir(dirname($file['fullname']),1); dol_delete_dir(dirname($file['fullname']),1);
@ -545,12 +605,12 @@ if ($ok && GETPOST('clean_orphelin_dir'))
} }
// clean_linked_elements: Check and clean linked elements // clean_linked_elements: Check and clean linked elements
if ($ok && GETPOST('clean_product_stock_batch')) if ($ok && GETPOST('clean_product_stock_batch','alpha'))
{ {
$methodtofix=GETPOST('methodtofix')?GETPOST('methodtofix'):'updatestock'; $methodtofix=GETPOST('methodtofix','alpha')?GETPOST('methodtofix','alpha'):'updatestock';
print '<tr><td colspan="2"><br>*** Clean table product_batch, methodtofix='.$methodtofix.' (possible values: updatestock or updatebatch)</td></tr>'; print '<tr><td colspan="2"><br>*** Clean table product_batch, methodtofix='.$methodtofix.' (possible values: updatestock or updatebatch)</td></tr>';
$sql ="SELECT p.rowid, p.ref, p.tobatch, ps.rowid as psrowid, ps.fk_entrepot, ps.reel, SUM(pb.qty) as reelbatch"; $sql ="SELECT p.rowid, p.ref, p.tobatch, ps.rowid as psrowid, ps.fk_entrepot, ps.reel, SUM(pb.qty) as reelbatch";
$sql.=" FROM ".MAIN_DB_PREFIX."product as p, ".MAIN_DB_PREFIX."product_stock as ps LEFT JOIN ".MAIN_DB_PREFIX."product_batch as pb ON ps.rowid = pb.fk_product_stock"; $sql.=" FROM ".MAIN_DB_PREFIX."product as p, ".MAIN_DB_PREFIX."product_stock as ps LEFT JOIN ".MAIN_DB_PREFIX."product_batch as pb ON ps.rowid = pb.fk_product_stock";
$sql.=" WHERE p.rowid = ps.fk_product"; $sql.=" WHERE p.rowid = ps.fk_product";
@ -562,7 +622,7 @@ if ($ok && GETPOST('clean_product_stock_batch'))
if ($resql) if ($resql)
{ {
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
if ($num) if ($num)
{ {
$i = 0; $i = 0;
@ -570,7 +630,7 @@ if ($ok && GETPOST('clean_product_stock_batch'))
{ {
$obj=$db->fetch_object($resql); $obj=$db->fetch_object($resql);
print '<tr><td>Product '.$obj->rowid.'-'.$obj->ref.' in warehose '.$obj->fk_entrepot.' -> '.$obj->psrowid.': '.$obj->reel.' (product_stock.reel) != '.($obj->reelbatch?$obj->reelbatch:'0').' (sum product_batch)'; print '<tr><td>Product '.$obj->rowid.'-'.$obj->ref.' in warehose '.$obj->fk_entrepot.' -> '.$obj->psrowid.': '.$obj->reel.' (product_stock.reel) != '.($obj->reelbatch?$obj->reelbatch:'0').' (sum product_batch)';
// Fix // Fix
if ($obj->reel != $obj->reelbatch) if ($obj->reel != $obj->reelbatch)
{ {
@ -599,9 +659,9 @@ if ($ok && GETPOST('clean_product_stock_batch'))
if (GETPOST('clean_product_stock_batch') == 'confirmed') if (GETPOST('clean_product_stock_batch') == 'confirmed')
{ {
$error=0; $error=0;
$db->begin(); $db->begin();
$sql2 ="UPDATE ".MAIN_DB_PREFIX."product_stock"; $sql2 ="UPDATE ".MAIN_DB_PREFIX."product_stock";
$sql2.=" SET reel = ".($obj->reelbatch?$obj->reelbatch:'0')." WHERE rowid = ".$obj->psrowid; $sql2.=" SET reel = ".($obj->reelbatch?$obj->reelbatch:'0')." WHERE rowid = ".$obj->psrowid;
$resql2=$db->query($sql2); $resql2=$db->query($sql2);
@ -610,26 +670,26 @@ if ($ok && GETPOST('clean_product_stock_batch'))
// We update product_stock, so we must field stock into product too. // We update product_stock, so we must field stock into product too.
$sql3='UPDATE llx_product p SET p.stock= (SELECT SUM(ps.reel) FROM llx_product_stock ps WHERE ps.fk_product = p.rowid)'; $sql3='UPDATE llx_product p SET p.stock= (SELECT SUM(ps.reel) FROM llx_product_stock ps WHERE ps.fk_product = p.rowid)';
$resql3=$db->query($sql3); $resql3=$db->query($sql3);
if (! $resql3) if (! $resql3)
{ {
$error++; $error++;
dol_print_error($db); dol_print_error($db);
} }
} }
else else
{ {
$error++; $error++;
dol_print_error($db); dol_print_error($db);
} }
if (!$error) $db->commit(); if (!$error) $db->commit();
else $db->rollback(); else $db->rollback();
} }
} }
} }
print'</td></tr>'; print'</td></tr>';
$i++; $i++;
} }
} }
@ -646,7 +706,7 @@ if ($ok && GETPOST('clean_product_stock_batch'))
// clean_linked_elements: Check and clean linked elements // clean_linked_elements: Check and clean linked elements
if ($ok && GETPOST('clean_product_stock_negative_if_batch')) if ($ok && GETPOST('clean_product_stock_negative_if_batch','alpha'))
{ {
print '<tr><td colspan="2"><br>Clean table product_batch, methodtofix='.$methodtofix.' (possible values: updatestock or updatebatch)</td></tr>'; print '<tr><td colspan="2"><br>Clean table product_batch, methodtofix='.$methodtofix.' (possible values: updatestock or updatebatch)</td></tr>';
@ -675,7 +735,7 @@ if ($ok && GETPOST('clean_product_stock_negative_if_batch'))
} }
// clean_linked_elements: Check and clean linked elements // clean_linked_elements: Check and clean linked elements
if ($ok && GETPOST('set_empty_time_spent_amount')) if ($ok && GETPOST('set_empty_time_spent_amount','alpha'))
{ {
print '<tr><td colspan="2"><br>*** Set value of time spent without amount</td></tr>'; print '<tr><td colspan="2"><br>*** Set value of time spent without amount</td></tr>';
@ -684,7 +744,7 @@ if ($ok && GETPOST('set_empty_time_spent_amount'))
$sql.=" WHERE ptt.fk_user = u.rowid"; $sql.=" WHERE ptt.fk_user = u.rowid";
$sql.=" AND ptt.thm IS NULL and u.thm > 0"; $sql.=" AND ptt.thm IS NULL and u.thm > 0";
$sql.=" GROUP BY u.rowid, u.login, u.thm"; $sql.=" GROUP BY u.rowid, u.login, u.thm";
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql)
{ {
@ -711,14 +771,14 @@ if ($ok && GETPOST('set_empty_time_spent_amount'))
dol_print_error($db); dol_print_error($db);
} }
} }
if (!$error) $db->commit(); if (!$error) $db->commit();
else $db->rollback(); else $db->rollback();
print'</td></tr>'; print'</td></tr>';
if ($error) break; if ($error) break;
$i++; $i++;
} }
} }
@ -732,7 +792,6 @@ if ($ok && GETPOST('set_empty_time_spent_amount'))
dol_print_error($db); dol_print_error($db);
} }
} }