2
0
forked from Wavyzz/dolibarr

add new rule

This commit is contained in:
Frédéric FRANCE
2021-03-01 00:48:36 +01:00
parent ed3b637d7a
commit 6f9c639f08
24 changed files with 2330 additions and 2101 deletions

View File

@@ -22,7 +22,9 @@
* \brief This script create a xml checksum file
*/
if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Do not create database handler $db
if (! defined('NOREQUIREDB')) {
define('NOREQUIREDB', '1'); // Do not create database handler $db
}
$sapi_type = php_sapi_name();
$script_file = basename(__FILE__);
@@ -54,7 +56,9 @@ parse_str($argv[1]);
$i=0;
while ($i < $argc) {
if (! empty($argv[$i])) parse_str($argv[$i]);
if (! empty($argv[$i])) {
parse_str($argv[$i]);
}
if (preg_match('/includeconstant=/', $argv[$i])) {
$tmp=explode(':', $includeconstant, 3);
if (count($tmp) != 3) {
@@ -78,7 +82,9 @@ $savrelease = $release;
$tmpver=explode('-', $release, 2);
if ($tmpver[0] == 'auto' || $tmpver[0] == 'autostable') {
$release=DOL_VERSION;
if ($tmpver[1] && $tmpver[0] == 'auto') $release.='-'.$tmpver[1];
if ($tmpver[1] && $tmpver[0] == 'auto') {
$release.='-'.$tmpver[1];
}
}
if (empty($includecustom)) {
@@ -205,8 +211,9 @@ foreach ($files as $filetmp) {
$newdir = str_replace(DOL_DOCUMENT_ROOT, '', dirname($file));
$newdir = str_replace(dirname(__FILE__).'/../scripts', '', dirname($file));
if ($newdir!=$dir) {
if ($needtoclose)
if ($needtoclose) {
fputs($fp, ' </dir>'."\n");
}
fputs($fp, ' <dir name="'.$newdir.'" >'."\n");
$dir = $newdir;
$needtoclose=1;

View File

@@ -131,13 +131,16 @@ $fields = implode(',', $fieldArray);
//var_dump($fieldArray);die();
$maxLength = 0;
for ($i = 1; $i <= $record_numbers; $i++) {
if ($startlinenb && $i < $startlinenb)
if ($startlinenb && $i < $startlinenb) {
continue;
if ($endlinenb && $i > $endlinenb)
}
if ($endlinenb && $i > $endlinenb) {
continue;
}
$row = dbase_get_record_with_names($fhandle, $i);
if ($row === false || (isset($row["deleted"]) && $row["deleted"] == '1'))
if ($row === false || (isset($row["deleted"]) && $row["deleted"] == '1')) {
continue;
}
$sqlInsert = "INSERT INTO `$table_name`($fields) VALUES (null,";
array_shift($row); // remove delete column
foreach ($row as $value) {

View File

@@ -88,25 +88,29 @@ if (!$ret > 0) {
$sql = "SELECT * FROM `$table` WHERE 1";
$resql = $db->query($sql);
if ($resql)
if ($resql) {
while ($fields = $db->fetch_array($resql)) {
$errorrecord = 0;
if ($fields === false)
if ($fields === false) {
continue;
}
$nboflines++;
$produit = new Product($db);
$produit->type = 0;
$produit->status = 1;
$produit->ref = trim($fields['REF']);
if ($produit->ref == '')
if ($produit->ref == '') {
continue;
}
print "Process line nb " . $j . ", ref " . $produit->ref;
$produit->label = trim($fields['LIBELLE']);
if ($produit->label == '')
if ($produit->label == '') {
$produit->label = $produit->ref;
if (empty($produit->label))
}
if (empty($produit->label)) {
continue;
}
//$produit->description = trim($fields[4] . "\n" . ($fields[5] ? $fields[5] . ' x ' . $fields[6] . ' x ' . $fields[7] : ''));
// $produit->volume = price2num($fields[8]);
// $produit->volume_unit = 0;
@@ -166,8 +170,9 @@ while ($fields = $db->fetch_array($resql)) {
//$ret1 = $produit->updatePrice($produit->price_ttc, $produit->price_base_type, $user, $produit->tva_tx, $produit->price_min, 1, $produit->tva_npr, 0, 0, array());
$ret1 = false;
for ($i = 0; $i < 10; $i++) {
if ($fields['TARIF' . ($i)] == 0)
if ($fields['TARIF' . ($i)] == 0) {
continue;
}
$ret1 = $ret1 || $produit->updatePrice(price2num($fields['TARIF' . ($i)]), 'HT', $user, $produit->tva_tx, $produit->price_min, $i + 1, $produit->tva_npr, 0, 0, array()) < 0;
}
if ($ret1) {
@@ -227,7 +232,10 @@ while ($fields = $db->fetch_array($resql)) {
$error++; // $errorrecord will be reset
}
$j++;
} else die("error : $sql");
}
} else {
die("error : $sql");
}

View File

@@ -144,15 +144,17 @@ if (!$ret > 0) {
$sql = "SELECT * FROM `$table` WHERE 1 "; //ORDER BY REMISE DESC,`LCIVIL` DESC";
$resql = $db->query($sql);
//$db->begin();
if ($resql)
if ($resql) {
while ($fields = $db->fetch_array($resql)) {
$i++;
$errorrecord = 0;
if ($startlinenb && $i < $startlinenb)
if ($startlinenb && $i < $startlinenb) {
continue;
if ($endlinenb && $i > $endlinenb)
}
if ($endlinenb && $i > $endlinenb) {
continue;
}
$nboflines++;
@@ -170,16 +172,20 @@ while ($fields = $db->fetch_array($resql)) {
$object->address = trim($fields['FADR1']);
if ($fields['FADR2'])
if ($fields['FADR2']) {
$object->address .= "\n" . trim($fields['FADR2']);
if ($fields['FADR3'])
}
if ($fields['FADR3']) {
$object->address .= "\n" . trim($fields['FADR3']);
}
$object->zip = trim($fields['FPOSTE']);
$object->town = trim($fields['FVILLE']);
if ($fields['FPAYS'])
if ($fields['FPAYS']) {
$object->country_id = dol_getIdFromCode($db, trim(ucwords(strtolower($fields['FPAYS']))), 'c_country', 'label', 'rowid');
else $object->country_id = 1;
} else {
$object->country_id = 1;
}
$object->phone = trim($fields['FTEL']) ? trim($fields['FTEL']) : trim($fields['FCONTACT']);
$object->phone = substr($object->phone, 0, 20);
$object->fax = trim($fields['FFAX']) ? trim($fields['FFAX']) : trim($fields['FCONTACT']);
@@ -289,16 +295,20 @@ while ($fields = $db->fetch_array($resql)) {
$contact->lastname = $fields['LCIVIL'] . " " . $fields['LNOM'];
}
$contact->address = trim($fields['LADR1']);
if ($fields['LADR2'])
if ($fields['LADR2']) {
$contact->address .= "\n" . trim($fields['LADR2']);
if ($fields['LADR3'])
}
if ($fields['LADR3']) {
$contact->address .= "\n" . trim($fields['LADR3']);
}
$contact->zip = trim($fields['LPOSTE']);
$contact->town = trim($fields['LVILLE']);
if ($fields['FPAYS'])
if ($fields['FPAYS']) {
$contact->country_id = dol_getIdFromCode($db, trim(ucwords(strtolower($fields['LPAYS']))), 'c_country', 'label', 'rowid');
else $contact->country_id = 1;
} else {
$contact->country_id = 1;
}
$contact->email = $fields['LMAIL'];
$contact->phone = trim($fields['LTEL']) ? trim($fields['LTEL']) : trim($fields['LCONTACT']);
$contact->fax = trim($fields['LFAX']) ? trim($fields['LFAX']) : trim($fields['LCONTACT']);
@@ -338,7 +348,10 @@ while ($fields = $db->fetch_array($resql)) {
$error++; // $errorrecord will be reset
}
$j++;
} else die("error : $sql");
}
} else {
die("error : $sql");
}
$db->commit();

View File

@@ -28,24 +28,28 @@ class DBase
//resource dbase_open ( string $filename , int $mode )
public static function open($filename, $mode)
{
if (!file_exists($filename))
if (!file_exists($filename)) {
return false;
}
$modes = array('r', 'w', 'r+');
$mode = $modes[$mode];
$fd = fopen($filename, $mode);
if (!$fd)
if (!$fd) {
return false;
}
return new DBase($fd);
}
//resource dbase_create ( string $filename , array $fields [, int $type = DBASE_TYPE_DBASE ] )
public static function create($filename, $fields, $type = DBASE_TYPE_DBASE)
{
if (file_exists($filename))
if (file_exists($filename)) {
return false;
}
$fd = fopen($filename, 'c+');
if (!$fd)
if (!$fd) {
return false;
}
// Byte 0 (1 byte): Valid dBASE for DOS file; bits 0-2 indicate version number, bit 3
// indicates the presence of a dBASE for DOS memo file, bits 4-6 indicate the
// presence of a SQL table, bit 7 indicates the presence of any memo file
@@ -62,8 +66,9 @@ class DBase
// Byte 10-11 (16-bit number): Number of bytes in record.
// Make sure the include the byte for deleted flag
$len = 1;
foreach ($fields as &$field)
foreach ($fields as &$field) {
$len += self::length($field);
}
self::putInt16($fd, $len);
// Byte 12-13 (2 bytes): Reserved, 0 filled.
self::putInt16($fd, 0);
@@ -153,15 +158,17 @@ class DBase
//bool dbase_add_record ( resource $dbase_identifier , array $record )
public function add_record($record)
{
if (count($record) != $this->fieldCount)
if (count($record) != $this->fieldCount) {
return false;
}
// Seek to end of file, minus the end of file marker
fseek($this->fd, 0, SEEK_END);
// Put the deleted flag
self::putChar8($this->fd, 0x20);
// Put the record
if (!$this->putRecord($record))
if (!$this->putRecord($record)) {
return false;
}
// Update the record count
fseek($this->fd, 4);
self::putInt32($this->fd, ++$this->recordCount);
@@ -171,10 +178,12 @@ class DBase
//bool dbase_replace_record ( resource $dbase_identifier , array $record , int $record_number )
public function replace_record($record, $record_number)
{
if (count($record) != $this->fieldCount)
if (count($record) != $this->fieldCount) {
return false;
if ($record_number < 1 || $record_number > $this->recordCount)
}
if ($record_number < 1 || $record_number > $this->recordCount) {
return false;
}
// Skip to the record location, plus the 1 byte for the deleted flag
fseek($this->fd, $this->headerLength + ($this->recordLength * ($record_number - 1)) + 1);
return $this->putRecord($record);
@@ -183,8 +192,9 @@ class DBase
//bool dbase_delete_record ( resource $dbase_identifier , int $record_number )
public function delete_record($record_number)
{
if ($record_number < 1 || $record_number > $this->recordCount)
if ($record_number < 1 || $record_number > $this->recordCount) {
return false;
}
fseek($this->fd, $this->headerLength + ($this->recordLength * ($record_number - 1)));
self::putChar8($this->fd, 0x2A);
return true;
@@ -193,8 +203,9 @@ class DBase
//array dbase_get_record ( resource $dbase_identifier , int $record_number )
public function get_record($record_number)
{
if ($record_number < 1 || $record_number > $this->recordCount)
if ($record_number < 1 || $record_number > $this->recordCount) {
return false;
}
fseek($this->fd, $this->headerLength + ($this->recordLength * ($record_number - 1)));
$record = array(
'deleted' => self::getChar8($this->fd) == 0x2A ? 1 : 0
@@ -203,11 +214,13 @@ class DBase
$value = trim(fread($this->fd, $field['length']));
if ($field['type'] == 'L') {
$value = strtolower($value);
if ($value == 't' || $value == 'y')
if ($value == 't' || $value == 'y') {
$value = true;
elseif ($value == 'f' || $value == 'n')
} elseif ($value == 'f' || $value == 'n') {
$value = false;
else $value = null;
} else {
$value = null;
}
}
$record[$i] = $value;
}
@@ -217,8 +230,9 @@ class DBase
//array dbase_get_record_with_names ( resource $dbase_identifier , int $record_number )
public function get_record_with_names($record_number)
{
if ($record_number < 1 || $record_number > $this->recordCount)
if ($record_number < 1 || $record_number > $this->recordCount) {
return false;
}
$record = $this->get_record($record_number);
foreach ($this->fields as $i => &$field) {
$record[$field['name']] = $record[$i];
@@ -292,9 +306,11 @@ class DBase
{
$data = fread($fd, 2 * $n);
$i = unpack("S$n", $data);
if ($n == 1)
if ($n == 1) {
return (int) $i[1];
else return array_merge($i);
} else {
return array_merge($i);
}
}
private static function putInt16($fd, $value)
@@ -306,9 +322,11 @@ class DBase
{
$data = fread($fd, 4 * $n);
$i = unpack("L$n", $data);
if ($n == 1)
if ($n == 1) {
return (int) $i[1];
else return array_merge($i);
} else {
return array_merge($i);
}
}
private static function putInt32($fd, $value)

View File

@@ -100,8 +100,7 @@ $dates = array (mktime(12, 0, 0, 1, 3, $year),
);
$ret=$user->fetch('', 'admin');
if (! $ret > 0)
{
if (! $ret > 0) {
print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
exit;
}
@@ -111,12 +110,10 @@ $user->getrights();
$socids = array();
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe WHERE client in (1, 3)";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num_thirdparties = $db->num_rows($resql);
$i = 0;
while ($i < $num_thirdparties)
{
while ($i < $num_thirdparties) {
$i++;
$row = $db->fetch_row($resql);
$socids[$i] = $row[0];
@@ -126,12 +123,10 @@ if ($resql)
$prodids = array();
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product WHERE tosell=1";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num_prods = $db->num_rows($resql);
$i = 0;
while ($i < $num_prods)
{
while ($i < $num_prods) {
$i++;
$row = $db->fetch_row($resql);
$prodids[$i] = $row[0];
@@ -140,8 +135,7 @@ if ($resql)
$i=0;
$result=0;
while ($i < GEN_NUMBER_FACTURE && $result >= 0)
{
while ($i < GEN_NUMBER_FACTURE && $result >= 0) {
$i++;
$socid = mt_rand(1, $num_thirdparties);
@@ -158,26 +152,22 @@ while ($i < GEN_NUMBER_FACTURE && $result >= 0)
$fuser->getRights();
$result=$object->create($fuser);
if ($result >= 0)
{
if ($result >= 0) {
$nbp = mt_rand(2, 5);
$xnbp = 0;
while ($xnbp < $nbp)
{
while ($xnbp < $nbp) {
$prodid = mt_rand(1, $num_prods);
$product=new Product($db);
$result=$product->fetch($prodids[$prodid]);
$result=$object->addline($product->description, $product->price, mt_rand(1, 5), 0, 0, 0, $prodids[$prodid], 0, '', '', 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type);
if ($result < 0)
{
if ($result < 0) {
dol_print_error($db, $propal->error);
}
$xnbp++;
}
$result=$object->validate($fuser);
if ($result)
{
if ($result) {
print " OK with ref ".$object->ref."\n";;
} else {
dol_print_error($db, $object->error);

View File

@@ -106,8 +106,7 @@ $dates = array (mktime(12, 0, 0, 1, 3, $year),
);
$ret=$user->fetch('', 'admin');
if ($ret <= 0)
{
if ($ret <= 0) {
print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
exit;
}
@@ -124,7 +123,9 @@ if ($resql) {
$row = $db->fetch_row($resql);
$societesid[$i] = $row[0];
}
} else { print "err"; }
} else {
print "err";
}
$commandesid = array();
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande";
@@ -137,7 +138,9 @@ if ($resql) {
$row = $db->fetch_row($resql);
$commandesid[$i] = $row[0];
}
} else { print "err"; }
} else {
print "err";
}
$prodids = array();
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product WHERE tosell=1";
@@ -156,8 +159,7 @@ if ($resql) {
print "Build ".GEN_NUMBER_COMMANDE." orders\n";
for ($s = 0 ; $s < GEN_NUMBER_COMMANDE ; $s++)
{
for ($s = 0; $s < GEN_NUMBER_COMMANDE; $s++) {
print "Process order ".$s."\n";
$object = new Commande($db);
@@ -182,26 +184,22 @@ for ($s = 0 ; $s < GEN_NUMBER_COMMANDE ; $s++)
$db->begin();
$result=$object->create($fuser);
if ($result >= 0)
{
if ($result >= 0) {
$nbp = mt_rand(2, 5);
$xnbp = 0;
while ($xnbp < $nbp)
{
while ($xnbp < $nbp) {
$prodid = mt_rand(1, $num_prods);
$product=new Product($db);
$result=$product->fetch($prodids[$prodid]);
$result=$object->addline($product->description, $product->price, mt_rand(1, 5), 0, 0, 0, $prodids[$prodid], 0, 0, 0, $product->price_base_type, $product->price_ttc, '', '', $product->type);
if ($result <= 0)
{
if ($result <= 0) {
dol_print_error($db, $object->error);
}
$xnbp++;
}
$result=$object->valid($fuser);
if ($result > 0)
{
if ($result > 0) {
$db->commit();
print " OK with ref ".$object->ref."\n";
} else {

View File

@@ -54,8 +54,7 @@ define(GEN_NUMBER_PRODUIT, 100000);
$ret=$user->fetch('', 'admin');
if (! $ret > 0)
{
if (! $ret > 0) {
print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
exit;
}
@@ -66,27 +65,36 @@ $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product"; $productsid = array();
$resql=$db->query($sql);
if ($resql) {
$num = $db->num_rows($resql); $i = 0;
while ($i < $num) { $row = $db->fetch_row($resql); $productsid[$i] = $row[0]; $i++; }
while ($i < $num) {
$row = $db->fetch_row($resql); $productsid[$i] = $row[0]; $i++;
}
}
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe"; $societesid = array();
$resql=$db->query($sql);
if ($resql) {
$num = $db->num_rows($resql); $i = 0;
while ($i < $num) { $row = $db->fetch_row($resql); $societesid[$i] = $row[0]; $i++; }
} else { print "err"; }
while ($i < $num) {
$row = $db->fetch_row($resql); $societesid[$i] = $row[0]; $i++;
}
} else {
print "err";
}
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande"; $commandesid = array();
$resql=$db->query($sql);
if ($resql) {
$num = $db->num_rows($resql); $i = 0;
while ($i < $num) { $row = $db->fetch_row($resql); $commandesid[$i] = $row[0]; $i++; }
} else { print "err"; }
while ($i < $num) {
$row = $db->fetch_row($resql); $commandesid[$i] = $row[0]; $i++;
}
} else {
print "err";
}
print "Generates ".GEN_NUMBER_PRODUIT." products\n";
for ($s = 0 ; $s < GEN_NUMBER_PRODUIT ; $s++)
{
for ($s = 0; $s < GEN_NUMBER_PRODUIT; $s++) {
print "Product ".$s;
$produit = new Product($db);
$produit->type = mt_rand(0, 1);
@@ -97,6 +105,9 @@ for ($s = 0 ; $s < GEN_NUMBER_PRODUIT ; $s++)
$produit->price = mt_rand(1, 1000);
$produit->tva_tx = "19.6";
$ret=$produit->create($user);
if ($ret < 0) print "Error $ret - ".$produit->error."\n";
else print " OK with ref ".$produit->ref."\n";
if ($ret < 0) {
print "Error $ret - ".$produit->error."\n";
} else {
print " OK with ref ".$produit->ref."\n";
}
}

View File

@@ -102,8 +102,7 @@ $dates = array (mktime(12, 0, 0, 1, 3, $year),
);
$ret=$user->fetch('', 'admin');
if (! $ret > 0)
{
if (! $ret > 0) {
print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
exit;
}
@@ -113,12 +112,10 @@ $user->getrights();
$socids = array();
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe WHERE client in (1,3)";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num_thirdparties = $db->num_rows($resql);
$i = 0;
while ($i < $num_thirdparties)
{
while ($i < $num_thirdparties) {
$i++;
$row = $db->fetch_row($resql);
$socids[$i] = $row[0];
@@ -128,12 +125,10 @@ if ($resql)
$contids = array();
$sql = "SELECT rowid, fk_soc FROM ".MAIN_DB_PREFIX."socpeople";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num_conts = $db->num_rows($resql);
$i = 0;
while ($i < $num_conts)
{
while ($i < $num_conts) {
$i++;
$row = $db->fetch_row($resql);
$contids[$row[1]][0] = $row[0]; // A ameliorer
@@ -143,12 +138,10 @@ if ($resql)
$prodids = array();
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product WHERE tosell=1";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num_prods = $db->num_rows($resql);
$i = 0;
while ($i < $num_prods)
{
while ($i < $num_prods) {
$i++;
$row = $db->fetch_row($resql);
$prodids[$i] = $row[0];
@@ -159,15 +152,13 @@ $user->rights->propal->creer=1;
$user->rights->propal->propal_advance->validate=1;
if (! empty($conf->global->PROPALE_ADDON) && is_readable(DOL_DOCUMENT_ROOT ."/core/modules/propale/".$conf->global->PROPALE_ADDON.".php"))
{
if (! empty($conf->global->PROPALE_ADDON) && is_readable(DOL_DOCUMENT_ROOT ."/core/modules/propale/".$conf->global->PROPALE_ADDON.".php")) {
require_once DOL_DOCUMENT_ROOT ."/core/modules/propale/".$conf->global->PROPALE_ADDON.".php";
}
$i=0;
$result=0;
while ($i < GEN_NUMBER_PROPAL && $result >= 0)
{
while ($i < GEN_NUMBER_PROPAL && $result >= 0) {
$i++;
$socid = mt_rand(1, $num_thirdparties);
print "Proposal ".$i." for socid ".$socid;
@@ -188,26 +179,22 @@ while ($i < GEN_NUMBER_PROPAL && $result >= 0)
$object->mode_reglement_id = 3;
$result=$object->create($fuser);
if ($result >= 0)
{
if ($result >= 0) {
$nbp = mt_rand(2, 5);
$xnbp = 0;
while ($xnbp < $nbp)
{
while ($xnbp < $nbp) {
$prodid = mt_rand(1, $num_prods);
$product=new Product($db);
$result=$product->fetch($prodids[$prodid]);
$result=$object->addline($product->description, $product->price, mt_rand(1, 5), 0, 0, 0, $prodids[$prodid], 0);
if ($result < 0)
{
if ($result < 0) {
dol_print_error($db, $object->error);
}
$xnbp++;
}
$result=$object->valid($fuser);
if ($result > 0)
{
if ($result > 0) {
$db->commit();
print " OK with ref ".$object->ref."\n";
} else {

View File

@@ -57,8 +57,7 @@ define(GEN_NUMBER_SOCIETE, 10);
$ret=$user->fetch('', 'admin');
if (! $ret > 0)
{
if (! $ret > 0) {
print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
exit;
}
@@ -85,7 +84,9 @@ if ($resql) {
$societesid[$i] = $row[0];
$i++;
}
} else { print "err"; }
} else {
print "err";
}
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande"; $commandesid = array();
$resql=$db->query($sql);
@@ -96,13 +97,14 @@ if ($resql) {
$commandesid[$i] = $row[0];
$i++;
}
} else { print "err"; }
} else {
print "err";
}
print "Generates ".GEN_NUMBER_SOCIETE." companies\n";
for ($s = 0 ; $s < GEN_NUMBER_SOCIETE ; $s++)
{
for ($s = 0; $s < GEN_NUMBER_SOCIETE; $s++) {
print "Company $s\n";
$soc = new Societe($db);
$soc->name = "Company num ".time()."$s";
@@ -115,23 +117,22 @@ for ($s = 0 ; $s < GEN_NUMBER_SOCIETE ; $s++)
$soc->country_id=1;
$soc->country_code='FR';
// Un client sur 3 a une remise de 5%
$user_remise=mt_rand(1, 3); if ($user_remise==3) $soc->remise_percent=5;
$user_remise=mt_rand(1, 3); if ($user_remise==3) {
$soc->remise_percent=5;
}
print "> client=".$soc->client.", fournisseur=".$soc->fournisseur.", remise=".$soc->remise_percent."\n";
$soc->note_private = 'Company created by the script generate-societe.php';
$socid = $soc->create();
if ($socid >= 0)
{
if ($socid >= 0) {
$rand = mt_rand(1, 4);
print "> Generates $rand contact(s)\n";
for ($c = 0 ; $c < $rand ; $c++)
{
for ($c = 0; $c < $rand; $c++) {
$contact = new Contact($db);
$contact->socid = $soc->id;
$contact->lastname = "Lastname".$c;
$contact->firstname = $listoflastname[mt_rand(0, count($listoflastname)-1)];
if ( $contact->create($user) )
{
if ($contact->create($user)) {
}
}

View File

@@ -79,30 +79,26 @@ if (! file_exists($filepath)) {
}
$ret=$user->fetch('', 'admin');
if (! $ret > 0)
{
if (! $ret > 0) {
print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
exit;
}
$user->getrights();
// Ask confirmation
if (! $confirmed)
{
if (! $confirmed) {
print "Hit Enter to continue or CTRL+C to stop...\n";
$input = trim(fgets(STDIN));
}
// Open input and output files
$fhandle = fopen($filepath, 'r');
if (! $fhandle)
{
if (! $fhandle) {
print 'Error: Failed to open file '.$filepath."\n";
exit(1);
}
$fhandleerr = fopen($filepatherr, 'w');
if (! $fhandleerr)
{
if (! $fhandleerr) {
print 'Error: Failed to open file '.$filepatherr."\n";
exit(1);
}
@@ -114,13 +110,16 @@ $db->begin();
$i=0;
$nboflines++;
while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
{
while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape)) {
$i++;
$errorrecord=0;
if ($startlinenb && $i < $startlinenb) continue;
if ($endlinenb && $i > $endlinenb) continue;
if ($startlinenb && $i < $startlinenb) {
continue;
}
if ($endlinenb && $i > $endlinenb) {
continue;
}
$nboflines++;
@@ -159,8 +158,7 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
$produit->array_options['options_ecotaxdeee']=price2num($fields[17]);
$ret=$produit->create($user);
if ($ret < 0)
{
if ($ret < 0) {
print " - Error in create result code = ".$ret." - ".$produit->errorsToString();
$errorrecord++;
} else {
@@ -170,12 +168,10 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
dol_syslog("Add prices");
// If we use price level, insert price for each level
if (! $errorrecord && 1)
{
if (! $errorrecord && 1) {
$ret1=$produit->updatePrice($produit->price_ttc, $produit->price_base_type, $user, $produit->tva_tx, $produit->price_min, 1, $produit->tva_npr, 0, 0, array());
$ret2=$produit->updatePrice(price2num($fields[14]), 'HT', $user, $produit->tva_tx, $produit->price_min, 2, $produit->tva_npr, 0, 0, array());
if ($ret1 < 0 || $ret2 < 0)
{
if ($ret1 < 0 || $ret2 < 0) {
print " - Error in updatePrice result code = ".$ret1." ".$ret2." - ".$produit->errorsToString();
$errorrecord++;
} else {
@@ -186,14 +182,12 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
dol_syslog("Add multilangs");
// Add alternative languages
if (! $errorrecord && 1)
{
if (! $errorrecord && 1) {
$produit->multilangs['fr_FR']=array('label'=>$produit->label, 'description'=>$produit->description, 'note'=>$produit->note_private);
$produit->multilangs['en_US']=array('label'=>$fields[3], 'description'=>$produit->description, 'note'=>$produit->note_private);
$ret=$produit->setMultiLangs($user);
if ($ret < 0)
{
if ($ret < 0) {
print " - Error in setMultiLangs result code = ".$ret." - ".$produit->errorsToString();
$errorrecord++;
} else {
@@ -203,8 +197,7 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
print "\n";
if ($errorrecord)
{
if ($errorrecord) {
fwrite($fhandleerr, 'Error on record nb '.$i." - ".$produit->errorsToString()."\n");
$error++; // $errorrecord will be reset
}
@@ -217,8 +210,7 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
// commit or rollback
print "Nb of lines qualified: ".$nboflines."\n";
print "Nb of errors: ".$error."\n";
if ($mode != 'confirmforced' && ($error || $mode != 'confirm'))
{
if ($mode != 'confirmforced' && ($error || $mode != 'confirm')) {
print "Rollback any changes.\n";
$db->rollback();
} else {

View File

@@ -79,30 +79,26 @@ if (! file_exists($filepath)) {
}
$ret=$user->fetch('', 'admin');
if (! $ret > 0)
{
if (! $ret > 0) {
print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
exit;
}
$user->getrights();
// Ask confirmation
if (! $confirmed)
{
if (! $confirmed) {
print "Hit Enter to continue or CTRL+C to stop...\n";
$input = trim(fgets(STDIN));
}
// Open input and output files
$fhandle = fopen($filepath, 'r');
if (! $fhandle)
{
if (! $fhandle) {
print 'Error: Failed to open file '.$filepath."\n";
exit(1);
}
$fhandleerr = fopen($filepatherr, 'w');
if (! $fhandleerr)
{
if (! $fhandleerr) {
print 'Error: Failed to open file '.$filepatherr."\n";
exit(1);
}
@@ -114,13 +110,16 @@ $db->begin();
$i=0;
$nboflines=0;
while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
{
while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape)) {
$i++;
$errorrecord=0;
if ($startlinenb && $i < $startlinenb) continue;
if ($endlinenb && $i > $endlinenb) continue;
if ($startlinenb && $i < $startlinenb) {
continue;
}
if ($endlinenb && $i > $endlinenb) {
continue;
}
$nboflines++;
@@ -144,14 +143,16 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
$object->default_lang = trim($fields[43]);
//$condpayment = dol_string_unaccent(trim($fields[36]));
if ($fields[36])
{
if ($fields[36]) {
$condpayment = trim($fields[36]);
if ($condpayment == 'A la commande') $condpayment = 'A réception de commande';
if ($condpayment == 'A reception facture') $condpayment = 'Réception de facture';
if ($condpayment == 'A la commande') {
$condpayment = 'A réception de commande';
}
if ($condpayment == 'A reception facture') {
$condpayment = 'Réception de facture';
}
$object->cond_reglement_id = dol_getIdFromCode($db, $condpayment, 'c_payment_term', 'libelle_facture', 'rowid', 1);
if (empty($object->cond_reglement_id))
{
if (empty($object->cond_reglement_id)) {
print " - Error cant find payment mode for ".$condpayment."\n";
$errorrecord++;
}
@@ -165,7 +166,9 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
// Set price level
$object->price_level = 1;
if ($labeltype == 'Revendeur') $object->price_level = 2;
if ($labeltype == 'Revendeur') {
$object->price_level = 2;
}
print "Process line nb ".$i.", name ".$object->name;
@@ -174,11 +177,9 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
$object->array_options['options_anastate']=price2num($fields[20]);
$object->array_options['options_anaregion']=price2num($fields[17]);
if (! $errorrecord)
{
if (! $errorrecord) {
$ret=$object->create($user);
if ($ret < 0)
{
if ($ret < 0) {
print " - Error in create result code = ".$ret." - ".$object->errorsToString();
$errorrecord++;
} else {
@@ -186,28 +187,28 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
}
}
if (! $errorrecord)
{
if (! $errorrecord) {
dol_syslog("Set price level");
$object->set_price_level($object->price_level, $user);
}
// Assign sales representative
if (! $errorrecord && $fields[3])
{
if (! $errorrecord && $fields[3]) {
$salesrep=new User($db);
$tmp=explode(' ', $fields[3], 2);
$salesrep->firstname = trim($tmp[0]);
$salesrep->lastname = trim($tmp[1]);
if ($salesrep->lastname) $salesrep->login = strtolower(substr($salesrep->firstname, 0, 1)) . strtolower(substr($salesrep->lastname, 0));
else $salesrep->login=strtolower($salesrep->firstname);
if ($salesrep->lastname) {
$salesrep->login = strtolower(substr($salesrep->firstname, 0, 1)) . strtolower(substr($salesrep->lastname, 0));
} else {
$salesrep->login=strtolower($salesrep->firstname);
}
$salesrep->login=preg_replace('/ /', '', $salesrep->login);
$salesrep->fetch(0, $salesrep->login);
$result = $object->add_commercial($user, $salesrep->id);
if ($result < 0)
{
if ($result < 0) {
print " - Error in create link with sale representative result code = ".$result." - ".$object->errorsToString();
$errorrecord++;
} else {
@@ -217,8 +218,7 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
dol_syslog("Add invoice contacts");
// Insert an invoice contact if there is an invoice email != standard email
if (! $errorrecord && $fields[27] && $fields[26] != $fields[27])
{
if (! $errorrecord && $fields[27] && $fields[26] != $fields[27]) {
$ret1=$ret2=0;
$contact = new Contact($db);
@@ -231,12 +231,10 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
$contact->socid=$object->id;
$ret1=$contact->create($user);
if ($ret1 > 0)
{
if ($ret1 > 0) {
//$ret2=$contact->add_contact($object->id, 'BILLING');
}
if ($ret1 < 0 || $ret2 < 0)
{
if ($ret1 < 0 || $ret2 < 0) {
print " - Error in create contact result code = ".$ret1." ".$ret2." - ".$object->errorsToString();
$errorrecord++;
} else {
@@ -246,8 +244,7 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
dol_syslog("Add delivery contacts");
// Insert a delivery contact
if (! $errorrecord && $fields[47])
{
if (! $errorrecord && $fields[47]) {
$ret1=$ret2=0;
$contact2 = new Contact($db);
@@ -263,12 +260,10 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
$contact2->array_options['options_anazoneliv']=price2num($fields[53]);
$ret1=$contact2->create($user);
if ($ret1 > 0)
{
if ($ret1 > 0) {
//$ret2=$contact2->add_contact($object->id, 'SHIPPING');
}
if ($ret1 < 0 || $ret2 < 0)
{
if ($ret1 < 0 || $ret2 < 0) {
print " - Error in create contact result code = ".$ret1." ".$ret2." - ".$object->errorsToString();
$errorrecord++;
} else {
@@ -279,8 +274,7 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
print "\n";
if ($errorrecord)
{
if ($errorrecord) {
fwrite($fhandleerr, 'Error on record nb '.$i." - ".$object->errorsToString()."\n");
$error++; // $errorrecord will be reset
}
@@ -293,8 +287,7 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
// commit or rollback
print "Nb of lines qualified: ".$nboflines."\n";
print "Nb of errors: ".$error."\n";
if ($mode != 'confirmforced' && ($error || $mode != 'confirm'))
{
if ($mode != 'confirmforced' && ($error || $mode != 'confirm')) {
print "Rollback any changes.\n";
$db->rollback();
} else {

View File

@@ -79,30 +79,26 @@ if (! file_exists($filepath)) {
}
$ret=$user->fetch('', 'admin');
if (! $ret > 0)
{
if (! $ret > 0) {
print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
exit;
}
$user->getrights();
// Ask confirmation
if (! $confirmed)
{
if (! $confirmed) {
print "Hit Enter to continue or CTRL+C to stop...\n";
$input = trim(fgets(STDIN));
}
// Open input and output files
$fhandle = fopen($filepath, 'r');
if (! $fhandle)
{
if (! $fhandle) {
print 'Error: Failed to open file '.$filepath."\n";
exit(1);
}
$fhandleerr = fopen($filepatherr, 'w');
if (! $fhandleerr)
{
if (! $fhandleerr) {
print 'Error: Failed to open file '.$filepatherr."\n";
exit(1);
}
@@ -114,13 +110,16 @@ $db->begin();
$i=0;
$nboflines=0;
while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
{
while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape)) {
$i++;
$errorrecord=0;
if ($startlinenb && $i < $startlinenb) continue;
if ($endlinenb && $i > $endlinenb) continue;
if ($startlinenb && $i < $startlinenb) {
continue;
}
if ($endlinenb && $i > $endlinenb) {
continue;
}
$nboflines++;
@@ -130,16 +129,18 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
$tmp=explode(' ', $fields[3], 2);
$object->firstname = trim($tmp[0]);
$object->lastname = trim($tmp[1]);
if ($object->lastname) $object->login = strtolower(substr($object->firstname, 0, 1)) . strtolower(substr($object->lastname, 0));
else $object->login=strtolower($object->firstname);
if ($object->lastname) {
$object->login = strtolower(substr($object->firstname, 0, 1)) . strtolower(substr($object->lastname, 0));
} else {
$object->login=strtolower($object->firstname);
}
$object->login=preg_replace('/ /', '', $object->login);
$object->password = 'init';
print "Process line nb ".$i.", login ".$object->login;
$ret=$object->create($user);
if ($ret < 0)
{
if ($ret < 0) {
print " - Error in create result code = ".$ret." - ".$object->errorsToString();
$errorrecord++;
} else {
@@ -148,8 +149,7 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
print "\n";
if ($errorrecord)
{
if ($errorrecord) {
fwrite($fhandleerr, 'Error on record nb '.$i." - ".$object->errorsToString()."\n");
$error++; // $errorrecord will be reset
}
@@ -162,8 +162,7 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
// commit or rollback
print "Nb of lines qualified: ".$nboflines."\n";
print "Nb of errors: ".$error."\n";
if ($mode != 'confirmforced' && ($error || $mode != 'confirm'))
{
if ($mode != 'confirmforced' && ($error || $mode != 'confirm')) {
print "Rollback any changes.\n";
$db->rollback();
} else {

View File

@@ -188,18 +188,15 @@ if (empty($mode) || ! in_array($mode, array('test','confirm'))) {
print "option can be ".implode(',', array_keys($sqls))."\n";
exit(-1);
}
if (empty($option))
{
if (empty($option)) {
print "Usage: $script_file (test|confirm) (all|option) (all|YYYY-MM-DD) [dbtype dbhost dbuser dbpassword dbname dbport]\n";
print "\n";
print "option must be defined with a value in list ".implode(',', array_keys($sqls))."\n";
exit(-1);
}
if ($option != 'all')
{
if ($option != 'all') {
$listofoptions=explode(',', $option);
foreach ($listofoptions as $cursoroption)
{
foreach ($listofoptions as $cursoroption) {
if (! in_array($cursoroption, array_keys($sqls))) {
print "Usage: $script_file (test|confirm) (all|option) (all|YYYY-MM-DD) [dbtype dbhost dbuser dbpassword dbname dbport]\n";
print "\n";
@@ -216,11 +213,12 @@ if (empty($date) || (! preg_match('/\d\d\d\d\-\d\d\-\d\d$/', $date) && $date !=
exit(-1);
}
if ($date == 'all') $date = '2199-01-01';
if ($date == 'all') {
$date = '2199-01-01';
}
// Replace database handler
if (! empty($argv[4]))
{
if (! empty($argv[4])) {
$db->close();
unset($db);
$db=getDoliDBInstance($argv[4], $argv[5], $argv[6], $argv[7], $argv[8], $argv[9]);
@@ -229,8 +227,7 @@ if (! empty($argv[4]))
//var_dump($user->db->database_name);
$ret=$user->fetch('', 'admin');
if (! $ret > 0)
{
if (! $ret > 0) {
print 'An admin user with login "admin" must exists to use this script.'."\n";
exit;
}
@@ -245,8 +242,7 @@ print "Database port = ".$db->database_port."\n";
print "User = ".$db->database_user."\n";
print "\n";
if (! $confirmed)
{
if (! $confirmed) {
print "Hit Enter to continue or CTRL+C to stop...\n";
$input = trim(fgets(STDIN));
}
@@ -264,10 +260,8 @@ function processfamily($family, $date)
global $db, $sqls;
$error=0;
foreach ($sqls[$family] as $sql)
{
if (preg_match('/^@/', $sql))
{
foreach ($sqls[$family] as $sql) {
if (preg_match('/^@/', $sql)) {
$newfamily=preg_replace('/@/', '', $sql);
processfamily($newfamily, $date);
continue;
@@ -278,51 +272,51 @@ function processfamily($family, $date)
print "Run sql: ".$sql."\n";
$resql=$db->query($sql);
if (! $resql)
{
if ($db->errno() != 'DB_ERROR_NOSUCHTABLE')
{
if (! $resql) {
if ($db->errno() != 'DB_ERROR_NOSUCHTABLE') {
$error++;
}
}
if ($error)
{
if ($error) {
print $db->lasterror();
$error++;
break;
}
}
if ($error) return -1;
else return 1;
if ($error) {
return -1;
} else {
return 1;
}
}
$db->begin();
$listofoptions=explode(',', $option);
foreach ($listofoptions as $cursoroption)
{
foreach ($listofoptions as $cursoroption) {
$oldfamily='';
foreach ($sqls as $family => $familysql)
{
if ($cursoroption && $cursoroption != 'all' && $cursoroption != $family) continue;
foreach ($sqls as $family => $familysql) {
if ($cursoroption && $cursoroption != 'all' && $cursoroption != $family) {
continue;
}
if ($family != $oldfamily) print "Process action for family ".$family."\n";
if ($family != $oldfamily) {
print "Process action for family ".$family."\n";
}
$oldfamily = $family;
$result=processfamily($family, $date);
if ($result < 0)
{
if ($result < 0) {
$error++;
break;
}
}
}
if ($error || $mode != 'confirm')
{
if ($error || $mode != 'confirm') {
print "\nRollback any changes.\n";
$db->rollback();
} else {

View File

@@ -48,8 +48,9 @@ if (! ($argv[1] && $argv[2])) {
echo "Usage: php pg2mysql_cli.php <inputfilename> <outputfilename> [engine]\n";
exit();
} else {
if (isset($argv[3]))
if (isset($argv[3])) {
$config['engine'] = $argv[3];
}
pg2mysql_large($argv[1], $argv[2]);
echo <<<XHTML
@@ -74,14 +75,18 @@ function getfieldname($l)
// first check if its in nice quotes for us
$regs = array();
if (preg_match("/`(.*)`/", $l, $regs)) {
if ($regs[1])
if ($regs[1]) {
return $regs[1];
else return null;
} // if its not in quotes, then it should (we hope!) be the first "word" on the line, up to the first space.
elseif (preg_match("/([^\ ]*)/", trim($l), $regs)) {
if ($regs[1])
} else {
return null;
}
} elseif (preg_match("/([^\ ]*)/", trim($l), $regs)) {
// if its not in quotes, then it should (we hope!) be the first "word" on the line, up to the first space.
if ($regs[1]) {
return $regs[1];
else return null;
} else {
return null;
}
}
}
@@ -94,13 +99,15 @@ function getfieldname($l)
*/
function formatsize($s)
{
if ($s < pow(2, 14))
if ($s < pow(2, 14)) {
return "{$s}B";
elseif ($s < pow(2, 20))
} elseif ($s < pow(2, 20)) {
return sprintf("%.1f", round($s / 1024, 1)) . "K";
elseif ($s < pow(2, 30))
} elseif ($s < pow(2, 30)) {
return sprintf("%.1f", round($s / 1024 / 1024, 1)) . "M";
else return sprintf("%.1f", round($s / 1024 / 1024 / 1024, 1)) . "G";
} else {
return sprintf("%.1f", round($s / 1024 / 1024 / 1024, 1)) . "G";
}
}
/**
@@ -141,9 +148,11 @@ function pg2mysql_large($infilename, $outfilename)
$c = substr_count($instr, "'");
// we have an odd number of ' marks
if ($c % 2 != 0) {
if ($inquotes)
if ($inquotes) {
$inquotes = false;
else $inquotes = true;
} else {
$inquotes = true;
}
}
if ($linenum % 10000 == 0) {
@@ -323,9 +332,11 @@ function pg2mysql(&$input, &$arrayofprimaryalreadyintabledef, $header = true)
$line = str_replace(" bool DEFAULT false", " bool DEFAULT 0", $line);
if (preg_match("/ character varying\(([0-9]*)\)/", $line, $regs)) {
$num = $regs[1];
if ($num <= 255)
if ($num <= 255) {
$line = preg_replace("/ character varying\([0-9]*\)/", " varchar($num)", $line);
else $line = preg_replace("/ character varying\([0-9]*\)/", " text", $line);
} else {
$line = preg_replace("/ character varying\([0-9]*\)/", " text", $line);
}
}
// character varying with no size, we will default to varchar(255)
if (preg_match("/ character varying/", $line)) {
@@ -345,9 +356,11 @@ function pg2mysql(&$input, &$arrayofprimaryalreadyintabledef, $header = true)
$line = preg_replace("/::.*$/", "\n", $line);
if (preg_match("/character\(([0-9]*)\)/", $line, $regs)) {
$num = $regs[1];
if ($num <= 255)
if ($num <= 255) {
$line = preg_replace("/ character\([0-9]*\)/", " varchar($num)", $line);
else $line = preg_replace("/ character\([0-9]*\)/", " text", $line);
} else {
$line = preg_replace("/ character\([0-9]*\)/", " text", $line);
}
}
// timestamps
$line = str_replace(" timestamp with time zone", " datetime", $line);
@@ -457,9 +470,11 @@ function pg2mysql(&$input, &$arrayofprimaryalreadyintabledef, $header = true)
$c = substr_count($line, "'");
// we have an odd number of ' marks
if ($c % 2 != 0) {
if ($inquotes)
if ($inquotes) {
$inquotes = false;
else $inquotes = true;
} else {
$inquotes = true;
}
// echo "inquotes=$inquotes\n";
}
} while (substr($lines[$linenumber], - 3, - 1) != ");" || $inquotes);
@@ -524,8 +539,9 @@ function pg2mysql(&$input, &$arrayofprimaryalreadyintabledef, $header = true)
}
}
if (substr($line, 0, 13) == 'DROP DATABASE')
if (substr($line, 0, 13) == 'DROP DATABASE') {
$output .= $line;
}
if (substr($line, 0, 15) == 'CREATE DATABASE') {
$matches = array();

View File

@@ -4,6 +4,7 @@
use Dolibarr\Aaa as Aaa;
use function Dolibarr\faaa as faaa; // Need php 5.6+
//use const Dolibarr\AAA;
//use Bbb as Bbb;

View File

@@ -3,10 +3,11 @@
$a = microtime(true);
$i = 0;
while ($i < 1000000)
{
while ($i < 1000000) {
$key = '1234567890111213141516171819'.$i;
if ($i == 1000) $key = 'MAIN_MODULE_AAAAAiiiiiiiiiiiiiiiiiiiiiiiiiiiii';
if ($i == 1000) {
$key = 'MAIN_MODULE_AAAAAiiiiiiiiiiiiiiiiiiiiiiiiiiiii';
}
//if (preg_match('/^MAIN_MODULE_/', $key)) {
//if (substr($key, 0, 12) == 'MAIN_MODULE_') {

View File

@@ -89,8 +89,8 @@ $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 016', PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array('helvetica', '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array('helvetica', '', PDF_FONT_SIZE_DATA));
$pdf->setHeaderFont(array('helvetica', '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(array('helvetica', '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

View File

@@ -64,8 +64,8 @@ $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
$pdf->SetHeaderData('', PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 038', PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

View File

@@ -77,9 +77,10 @@ class autoTranslator
$files = $this->getTranslationFilesArray($this->_refLang);
$counter = 1;
foreach ($files as $file)
{
if ($this->_limittofile && $this->_limittofile != $file) continue;
foreach ($files as $file) {
if ($this->_limittofile && $this->_limittofile != $file) {
continue;
}
$counter++;
$fileContent = null;
$refPath = $this->_langDir.$this->_refLang.self::DIR_SEPARATOR.$file;
@@ -88,43 +89,56 @@ class autoTranslator
// Define target dirs
$targetlangs=array($this->_destlang);
if ($this->_destlang == 'all')
{
if ($this->_destlang == 'all') {
$targetlangs=array();
// If we must process all languages
$arraytmp=dol_dir_list($this->_langDir, 'directories', 0);
foreach ($arraytmp as $dirtmp)
{
if ($dirtmp['name'] === $this->_refLang) continue; // We discard source language
foreach ($arraytmp as $dirtmp) {
if ($dirtmp['name'] === $this->_refLang) {
continue; // We discard source language
}
$tmppart=explode('_', $dirtmp['name']);
if (preg_match('/^en/i', $dirtmp['name'])) continue; // We discard en_* languages
if (preg_match('/^fr/i', $dirtmp['name'])) continue; // We discard fr_* languages
if (preg_match('/^es/i', $dirtmp['name'])) continue; // We discard es_* languages
if (preg_match('/ca_ES/i', $dirtmp['name'])) continue; // We discard es_CA language
if (preg_match('/pt_BR/i', $dirtmp['name'])) continue; // We discard pt_BR language
if (preg_match('/nl_BE/i', $dirtmp['name'])) continue; // We discard nl_BE language
if (preg_match('/^\./i', $dirtmp['name'])) continue; // We discard files .*
if (preg_match('/^CVS/i', $dirtmp['name'])) continue; // We discard CVS
if (preg_match('/^en/i', $dirtmp['name'])) {
continue; // We discard en_* languages
}
if (preg_match('/^fr/i', $dirtmp['name'])) {
continue; // We discard fr_* languages
}
if (preg_match('/^es/i', $dirtmp['name'])) {
continue; // We discard es_* languages
}
if (preg_match('/ca_ES/i', $dirtmp['name'])) {
continue; // We discard es_CA language
}
if (preg_match('/pt_BR/i', $dirtmp['name'])) {
continue; // We discard pt_BR language
}
if (preg_match('/nl_BE/i', $dirtmp['name'])) {
continue; // We discard nl_BE language
}
if (preg_match('/^\./i', $dirtmp['name'])) {
continue; // We discard files .*
}
if (preg_match('/^CVS/i', $dirtmp['name'])) {
continue; // We discard CVS
}
$targetlangs[]=$dirtmp['name'];
}
//var_dump($targetlangs);
}
// Process translation of source file for each target languages
foreach ($targetlangs as $my_destlang)
{
foreach ($targetlangs as $my_destlang) {
$this->_translatedFiles = array();
$destPath = $this->_langDir.$my_destlang.self::DIR_SEPARATOR.$file;
// Check destination file presence
if (! file_exists($destPath))
{
if (! file_exists($destPath)) {
// No file present, we generate file
echo "File not found: " . $destPath . ". We generate it.<br>\n";
$this->createTranslationFile($destPath, $my_destlang);
}
else {
} else {
echo "Updating file: " . $destPath . "<br>\n";
}
@@ -134,8 +148,7 @@ class autoTranslator
foreach ($fileContent as $line) {
$key = $this->getLineKey($line);
$value = $this->getLineValue($line);
if ($key && $value)
{
if ($key && $value) {
$newlines+=$this->translateFileLine($fileContentDest, $file, $key, $value, $my_destlang);
}
}
@@ -159,8 +172,7 @@ class autoTranslator
{
$this->_time_end = date('Y-m-d H:i:s');
if (isset($this->_translatedFiles[$file]) && count($this->_translatedFiles[$file])>0)
{
if (isset($this->_translatedFiles[$file]) && count($this->_translatedFiles[$file])>0) {
$fp = fopen($destPath, 'a');
fwrite($fp, "\n");
fwrite($fp, "\n");
@@ -213,8 +225,7 @@ class autoTranslator
$destValue = $this->getLineValue($line);
// If translated return
//print "destKey=".$destKey."\n";
if ( trim($destKey) == trim($key) )
{ // Found already existing translation (key already exits in dest file)
if (trim($destKey) == trim($key)) { // Found already existing translation (key already exits in dest file)
return 0;
}
}
@@ -227,13 +238,18 @@ class autoTranslator
$val=$value;
} else {
// If not translated then translate
if ($this->_outputpagecode == 'UTF-8') $val=$this->translateTexts(array($value), substr($this->_refLang, 0, 2), substr($my_destlang, 0, 2));
else $val=utf8_decode($this->translateTexts(array($value), substr($this->_refLang, 0, 2), substr($my_destlang, 0, 2)));
if ($this->_outputpagecode == 'UTF-8') {
$val=$this->translateTexts(array($value), substr($this->_refLang, 0, 2), substr($my_destlang, 0, 2));
} else {
$val=utf8_decode($this->translateTexts(array($value), substr($this->_refLang, 0, 2), substr($my_destlang, 0, 2)));
}
}
$val=trim($val);
if (empty($val)) return 0;
if (empty($val)) {
return 0;
}
$this->_translatedFiles[$file][] = $key . '=' . $val ;
return 1;
@@ -293,9 +309,13 @@ class autoTranslator
{
// We want to be sure that src_lang and dest_lang are using 2 chars only
$tmp=explode('_', $src_lang);
if (! empty($tmp[1]) && $tmp[0] == $tmp[1]) $src_lang=$tmp[0];
if (! empty($tmp[1]) && $tmp[0] == $tmp[1]) {
$src_lang=$tmp[0];
}
$tmp=explode('_', $dest_lang);
if (! empty($tmp[1]) && $tmp[0] == $tmp[1]) $dest_lang=$tmp[0];
if (! empty($tmp[1]) && $tmp[0] == $tmp[1]) {
$dest_lang=$tmp[0];
}
//setting language pair
$lang_pair = $src_lang.'|'.$dest_lang;
@@ -313,8 +333,7 @@ class autoTranslator
// Send request
//print "Url to translate: ".$url."\n";
if (! function_exists("curl_init"))
{
if (! function_exists("curl_init")) {
print "Error, your PHP does not support curl functions.\n";
die();
}
@@ -331,8 +350,7 @@ class autoTranslator
$json = json_decode($body, true);
if ((! empty($json['responseStatus']) && $json['responseStatus'] != 200)
|| count($json['data']['translations']) == 0)
{
|| count($json['data']['translations']) == 0) {
print "Error: ".$json['responseStatus']." ".$url."\n";
return false;
}

View File

@@ -67,21 +67,17 @@ print 'Argument 1='.$argv[1]."\n";
print 'Argument 2='.$argv[2]."\n";
print 'Argument 3='.$argv[3]."\n";
$file='';
if (isset($argv[4]))
{
if (isset($argv[4])) {
$file=$argv[4];
print 'Argument 4='.$argv[4]."\n";
}
print 'Files will be generated/updated in directory '.$dir."\n";
if ($argv[2] != 'all')
{
if (! is_dir($dir.'/'.$argv[2]))
{
if ($argv[2] != 'all') {
if (! is_dir($dir.'/'.$argv[2])) {
print 'Create directory '.$dir.'/'.$argv[2]."\n";
$result=mkdir($dir.'/'.$argv[2]);
if (! $result)
{
if (! $result) {
$db->close();
return -1;
}

View File

@@ -25,14 +25,12 @@ $path=dirname(__FILE__).'/';
$web=0;
// Test if batch mode
if (substr($sapi_type, 0, 3) == 'cgi')
{
if (substr($sapi_type, 0, 3) == 'cgi') {
$web=1;
}
if ($web)
{
if ($web) {
echo "<html>";
echo "<head>";
@@ -87,9 +85,13 @@ if ($web)
}
echo "If you call this with argument \"unused=true\" it searches for the translation strings that exist in en_US but are never used.\n";
if ($web) print "<br>";
if ($web) {
print "<br>";
}
echo "IMPORTANT: that can take quite a lot of time (up to 10 minutes), you need to tune the max_execution_time on your php.ini accordingly.\n";
if ($web) print "<br>";
if ($web) {
print "<br>";
}
@@ -105,8 +107,7 @@ $workdir = $htdocs."langs/en_US/";
$files = scandir($workdir);
if (empty($files))
{
if (empty($files)) {
echo "Can't scan workdir = ".$workdir;
exit;
}
@@ -115,18 +116,17 @@ $dups=array();
$exludefiles = array('.','..','README');
$files = array_diff($files, $exludefiles);
// To force a file: $files=array('myfile.lang');
if (isset($argv[2]))
{
if (isset($argv[2])) {
$files = array($argv[2]);
}
$langstrings_3d = array();
$langstrings_full = array();
foreach ($files AS $file) {
foreach ($files as $file) {
$path_file = pathinfo($file);
// we're only interested in .lang files
if ($path_file['extension']=='lang') {
$content = file($workdir.$file);
foreach ($content AS $line => $row) {
foreach ($content as $line => $row) {
// don't want comment lines
if (substr($row, 0, 1) !== '#') {
// don't want lines without the separator (why should those even be here, anyway...)
@@ -142,26 +142,26 @@ foreach ($files AS $file) {
}
}
foreach ($langstrings_3d AS $filename => $file)
{
foreach ($file AS $linenum => $value)
{
foreach ($langstrings_3d as $filename => $file) {
foreach ($file as $linenum => $value) {
$keys = array_keys($langstrings_full, $value);
if (count($keys)>1)
{
foreach ($keys AS $key) {
if (count($keys)>1) {
foreach ($keys as $key) {
$dups[$value][$filename][$linenum] = trim($langstrings_3dtrans[$filename][$linenum]);
}
}
}
}
if ($web) print "<h2>";
if ($web) {
print "<h2>";
}
print "Duplicate strings in lang files in $workdir - ".count($dups)." found\n";
if ($web) print "</h2>";
if ($web) {
print "</h2>";
}
if ($web)
{
if ($web) {
echo '<table border_bottom="1">'."\n";
echo "<thead><tr><th align=\"center\">#</th><th>String</th><th>File and lines</th></thead>\n";
echo "<tbody>\n";
@@ -173,75 +173,126 @@ $sininstallandadmin='';
$sother='';
$count = 0;
foreach ($dups as $string => $pages)
{
foreach ($dups as $string => $pages) {
$count++;
$s='';
// Keyword $string
if ($web) $s.="<tr>";
if ($web) $s.="<td align=\"center\">";
if ($web) $s.=$count;
if ($web) $s.="</td>";
if ($web) $s.="<td>";
if ($web) {
$s.="<tr>";
}
if ($web) {
$s.="<td align=\"center\">";
}
if ($web) {
$s.=$count;
}
if ($web) {
$s.="</td>";
}
if ($web) {
$s.="<td>";
}
$s.=$string;
if ($web) $s.="</td>";
if ($web) $s.="<td>";
if (! $web) $s.= ' : ';
if ($web) {
$s.="</td>";
}
if ($web) {
$s.="<td>";
}
if (! $web) {
$s.= ' : ';
}
// Loop on each files keyword was found
$duplicateinsamefile=0;
$inmain=0;
$inadmin=0;
foreach ($pages AS $file => $lines)
{
if ($file == 'main.lang') { $inmain=1; $inadmin=0; }
if ($file == 'admin.lang' && ! $inmain) { $inadmin=1; }
foreach ($pages as $file => $lines) {
if ($file == 'main.lang') {
$inmain=1; $inadmin=0;
}
if ($file == 'admin.lang' && ! $inmain) {
$inadmin=1;
}
$s.=$file." ";
// Loop on each line keword was found into file.
$listoffilesforthisentry=array();
foreach ($lines as $line => $translatedvalue)
{
if (! empty($listoffilesforthisentry[$file])) $duplicateinsamefile=1;
foreach ($lines as $line => $translatedvalue) {
if (! empty($listoffilesforthisentry[$file])) {
$duplicateinsamefile=1;
}
$listoffilesforthisentry[$file]=1;
$s.= "(".$line." - ".htmlentities($translatedvalue).") ";
}
if ($web) $s.="<br>";
if ($web) {
$s.="<br>";
}
}
if ($web) {
$s.="</td></tr>";
}
if ($web) $s.="</td></tr>";
$s.="\n";
if ($duplicateinsamefile) $sduplicateinsamefile .= $s;
elseif ($inmain) $sinmainandother .= $s;
elseif ($inadmin) $sininstallandadmin .= $s;
else $sother .= $s;
if ($duplicateinsamefile) {
$sduplicateinsamefile .= $s;
} elseif ($inmain) {
$sinmainandother .= $s;
} elseif ($inadmin) {
$sininstallandadmin .= $s;
} else {
$sother .= $s;
}
}
if (! $web) print "\n***** Entries duplicated in same file\n";
if (! $web) {
print "\n***** Entries duplicated in same file\n";
}
print $sduplicateinsamefile;
if (! $web && empty($sduplicateinsamefile)) print "None\n";
if (! $web) print "\n";
if (! $web && empty($sduplicateinsamefile)) {
print "None\n";
}
if (! $web) {
print "\n";
}
if (! $web) print "***** Entries in main and another (keep only entry in main)\n";
if (! $web) {
print "***** Entries in main and another (keep only entry in main)\n";
}
print $sinmainandother;
if (! $web && empty($sinmainandother)) print "None\n";
if (! $web) print "\n";
if (! $web && empty($sinmainandother)) {
print "None\n";
}
if (! $web) {
print "\n";
}
if (! $web) print "***** Entries in admin and another\n";
if (! $web) {
print "***** Entries in admin and another\n";
}
print $sininstallandadmin;
if (! $web && empty($sininstallandadmin)) print "None\n";
if (! $web) print "\n";
if (! $web && empty($sininstallandadmin)) {
print "None\n";
}
if (! $web) {
print "\n";
}
if (! $web) print "***** Other\n";
if (! $web) {
print "***** Other\n";
}
print $sother;
if (! $web && empty($sother)) print "None\n";
if (! $web) print "\n";
if (! $web && empty($sother)) {
print "None\n";
}
if (! $web) {
print "\n";
}
if ($web)
{
if ($web) {
echo "</tbody>\n";
echo "</table>\n";
}
@@ -249,105 +300,254 @@ if ($web)
// STEP 2 - Search key not used
if ((! empty($_REQUEST['unused']) && $_REQUEST['unused'] == 'true') || (isset($argv[1]) && $argv[1]=='unused=true'))
{
if ((! empty($_REQUEST['unused']) && $_REQUEST['unused'] == 'true') || (isset($argv[1]) && $argv[1]=='unused=true')) {
print "***** Strings in en_US that are never used:\n";
$unused=array();
foreach ($langstrings_dist AS $value => $line)
{
foreach ($langstrings_dist as $value => $line) {
$qualifiedforclean=1;
// Check if we must keep this key to be into file for removal
if (preg_match('/^Module\d+/', $value)) $qualifiedforclean=0;
if (preg_match('/^Permission\d+/', $value)) $qualifiedforclean=0;
if (preg_match('/^PermissionAdvanced\d+/', $value)) $qualifiedforclean=0;
if (preg_match('/^ProfId\d+/', $value)) $qualifiedforclean=0;
if (preg_match('/^Delays_/', $value)) $qualifiedforclean=0;
if (preg_match('/^BarcodeDesc/', $value)) $qualifiedforclean=0;
if (preg_match('/^Extrafield/', $value)) $qualifiedforclean=0;
if (preg_match('/^LocalTax/', $value)) $qualifiedforclean=0;
if (preg_match('/^Country/', $value)) $qualifiedforclean=0;
if (preg_match('/^Civility/', $value)) $qualifiedforclean=0;
if (preg_match('/^Currency/', $value)) $qualifiedforclean=0;
if (preg_match('/^DemandReasonTypeSRC/', $value)) $qualifiedforclean=0;
if (preg_match('/^PaperFormat/', $value)) $qualifiedforclean=0;
if (preg_match('/^Duration/', $value)) $qualifiedforclean=0;
if (preg_match('/^AmountLT/', $value)) $qualifiedforclean=0;
if (preg_match('/^TotalLT/', $value)) $qualifiedforclean=0;
if (preg_match('/^Month/', $value)) $qualifiedforclean=0;
if (preg_match('/^MonthShort/', $value)) $qualifiedforclean=0;
if (preg_match('/^Day\d/', $value)) $qualifiedforclean=0;
if (preg_match('/^Short/', $value)) $qualifiedforclean=0;
if (preg_match('/^ExportDataset_/', $value)) $qualifiedforclean=0;
if (preg_match('/^ImportDataset_/', $value)) $qualifiedforclean=0;
if (preg_match('/^ActionAC_/', $value)) $qualifiedforclean=0;
if (preg_match('/^TypeLocaltax/', $value)) $qualifiedforclean=0;
if (preg_match('/^StatusProspect/', $value)) $qualifiedforclean=0;
if (preg_match('/^PL_/', $value)) $qualifiedforclean=0;
if (preg_match('/^TE_/', $value)) $qualifiedforclean=0;
if (preg_match('/^JuridicalStatus/', $value)) $qualifiedforclean=0;
if (preg_match('/^CalcMode/', $value)) $qualifiedforclean=0;
if (preg_match('/^newLT/', $value)) $qualifiedforclean=0;
if (preg_match('/^LT[0-9]/', $value)) $qualifiedforclean=0;
if (preg_match('/^TypeContact_contrat_/', $value)) $qualifiedforclean=0;
if (preg_match('/^ErrorPriceExpression/', $value)) $qualifiedforclean=0;
if (preg_match('/^Language_/', $value)) $qualifiedforclean=0;
if (preg_match('/^DescADHERENT_/', $value)) $qualifiedforclean=0;
if (preg_match('/^SubmitTranslation/', $value)) $qualifiedforclean=0;
if (preg_match('/^ModuleCompanyCode/', $value)) $qualifiedforclean=0;
if (preg_match('/InDolibarr$/', $value)) $qualifiedforclean=0;
if (preg_match('/^Module\d+/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^Permission\d+/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^PermissionAdvanced\d+/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^ProfId\d+/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^Delays_/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^BarcodeDesc/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^Extrafield/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^LocalTax/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^Country/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^Civility/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^Currency/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^DemandReasonTypeSRC/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^PaperFormat/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^Duration/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^AmountLT/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^TotalLT/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^Month/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^MonthShort/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^Day\d/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^Short/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^ExportDataset_/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^ImportDataset_/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^ActionAC_/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^TypeLocaltax/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^StatusProspect/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^PL_/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^TE_/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^JuridicalStatus/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^CalcMode/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^newLT/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^LT[0-9]/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^TypeContact_contrat_/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^ErrorPriceExpression/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^Language_/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^DescADHERENT_/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^SubmitTranslation/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^ModuleCompanyCode/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/InDolibarr$/', $value)) {
$qualifiedforclean=0;
}
// admin.lang
if (preg_match('/^DAV_ALLOW_PUBLIC_DIR/i', $value)) $qualifiedforclean=0;
if (preg_match('/^DAV_ALLOW_ECM_DIR/i', $value)) $qualifiedforclean=0;
if (preg_match('/^DAV_ALLOW_PUBLIC_DIR/i', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^DAV_ALLOW_ECM_DIR/i', $value)) {
$qualifiedforclean=0;
}
// boxes.lang
if (preg_match('/^BoxTitleLast/', $value)) $qualifiedforclean=0;
if (preg_match('/^BoxTitleLatest/', $value)) $qualifiedforclean=0;
if (preg_match('/^BoxTitleLast/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^BoxTitleLatest/', $value)) {
$qualifiedforclean=0;
}
// install.lang
if (preg_match('/^KeepDefaultValues/', $value)) $qualifiedforclean=0;
if (preg_match('/^KeepDefaultValues/', $value)) {
$qualifiedforclean=0;
}
// mail.lang
if (preg_match('/MailingModuleDesc/i', $value)) $qualifiedforclean=0;
if (preg_match('/MailingModuleDesc/i', $value)) {
$qualifiedforclean=0;
}
// main.lang
if (preg_match('/^Duration/', $value)) $qualifiedforclean=0;
if (preg_match('/^FormatDate/', $value)) $qualifiedforclean=0;
if (preg_match('/^DateFormat/', $value)) $qualifiedforclean=0;
if (preg_match('/^.b$/', $value)) $qualifiedforclean=0;
if (preg_match('/^.*Bytes$/', $value)) $qualifiedforclean=0;
if (preg_match('/^NoteSomeFeaturesAreDisabled/', $value)) $qualifiedforclean=0;
if (preg_match('/^(DoTest|Under|Limits|Cards|CurrentValue|DateLimit|DateAndHour|NbOfLines|NbOfObjects|NbOfReferes|TotalTTCShort|VATs)/', $value)) $qualifiedforclean=0;
if (preg_match('/^Duration/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^FormatDate/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^DateFormat/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^.b$/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^.*Bytes$/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^NoteSomeFeaturesAreDisabled/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^(DoTest|Under|Limits|Cards|CurrentValue|DateLimit|DateAndHour|NbOfLines|NbOfObjects|NbOfReferes|TotalTTCShort|VATs)/', $value)) {
$qualifiedforclean=0;
}
// modulebuilder
if (preg_match('/^ModuleBuilderDesc/', $value)) $qualifiedforclean=0;
if (preg_match('/^ModuleBuilderDesc/', $value)) {
$qualifiedforclean=0;
}
// orders
if (preg_match('/^OrderSource/', $value)) $qualifiedforclean=0;
if (preg_match('/^TypeContact_/', $value)) $qualifiedforclean=0;
if (preg_match('/^OrderSource/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^TypeContact_/', $value)) {
$qualifiedforclean=0;
}
// other.lang
if (preg_match('/^Notify_/', $value)) $qualifiedforclean=0;
if (preg_match('/^PredefinedMail/', $value)) $qualifiedforclean=0;
if (preg_match('/^DemoCompany/', $value)) $qualifiedforclean=0;
if (preg_match('/^WeightUnit/', $value)) $qualifiedforclean=0;
if (preg_match('/^LengthUnit/', $value)) $qualifiedforclean=0;
if (preg_match('/^SurfaceUnit/', $value)) $qualifiedforclean=0;
if (preg_match('/^VolumeUnit/', $value)) $qualifiedforclean=0;
if (preg_match('/^SizeUnit/', $value)) $qualifiedforclean=0;
if (preg_match('/^EMailText/', $value)) $qualifiedforclean=0;
if (preg_match('/ById$/', $value)) $qualifiedforclean=0;
if (preg_match('/ByLogin$/', $value)) $qualifiedforclean=0;
if (preg_match('/^Notify_/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^PredefinedMail/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^DemoCompany/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^WeightUnit/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^LengthUnit/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^SurfaceUnit/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^VolumeUnit/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^SizeUnit/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/^EMailText/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/ById$/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/ByLogin$/', $value)) {
$qualifiedforclean=0;
}
// printing
if (preg_match('/PrintingDriverDesc$/', $value)) $qualifiedforclean=0;
if (preg_match('/PrintTestDesc$/', $value)) $qualifiedforclean=0;
if (preg_match('/PrintingDriverDesc$/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/PrintTestDesc$/', $value)) {
$qualifiedforclean=0;
}
// products
if (preg_match('/GlobalVariableUpdaterType$/', $value)) $qualifiedforclean=0;
if (preg_match('/GlobalVariableUpdaterHelp$/', $value)) $qualifiedforclean=0;
if (preg_match('/OppStatus/', $value)) $qualifiedforclean=0;
if (preg_match('/AvailabilityType/', $value)) $qualifiedforclean=0;
if (preg_match('/CardProduct/', $value)) $qualifiedforclean=0;
if (preg_match('/GlobalVariableUpdaterType$/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/GlobalVariableUpdaterHelp$/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/OppStatus/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/AvailabilityType/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/CardProduct/', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/sms/i', $value)) $qualifiedforclean=0;
if (preg_match('/TF_/i', $value)) $qualifiedforclean=0;
if (preg_match('/WithBankUsing/i', $value)) $qualifiedforclean=0;
if (preg_match('/descWORKFLOW_/i', $value)) $qualifiedforclean=0;
if (preg_match('/sms/i', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/TF_/i', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/WithBankUsing/i', $value)) {
$qualifiedforclean=0;
}
if (preg_match('/descWORKFLOW_/i', $value)) {
$qualifiedforclean=0;
}
if (! $qualifiedforclean)
{
if (! $qualifiedforclean) {
continue;
}
@@ -359,28 +559,31 @@ if ((! empty($_REQUEST['unused']) && $_REQUEST['unused'] == 'true') || (isset($a
if (empty($output)) {
$unused[$value] = $line;
echo $line; // $trad contains the \n
}
else {
} else {
unset($output);
//print 'X'.$output.'Y';
}
}
if (empty($unused)) print "No string not used found.\n";
else {
if (empty($unused)) {
print "No string not used found.\n";
} else {
$filetosave='/tmp/'.($argv[2]?$argv[2]:"").'notused.lang';
print "Strings in en_US that are never used are saved into file ".$filetosave.":\n";
file_put_contents($filetosave, implode("", $unused));
print "To remove from original file, run command :\n";
if (($argv[2]?$argv[2]:"")) print 'cd htdocs/langs/en_US; mv '.($argv[2]?$argv[2]:"")." ".($argv[2]?$argv[2]:"").".tmp; ";
if (($argv[2]?$argv[2]:"")) {
print 'cd htdocs/langs/en_US; mv '.($argv[2]?$argv[2]:"")." ".($argv[2]?$argv[2]:"").".tmp; ";
}
print "diff ".($argv[2]?$argv[2]:"").".tmp ".$filetosave." | grep \< | cut -b 3- > ".($argv[2]?$argv[2]:"");
if (($argv[2]?$argv[2]:"")) print "; rm ".($argv[2]?$argv[2]:"").".tmp;\n";
if (($argv[2]?$argv[2]:"")) {
print "; rm ".($argv[2]?$argv[2]:"").".tmp;\n";
}
}
}
echo "\n";
if ($web)
{
if ($web) {
echo "</body>\n";
echo "</html>\n";
}

View File

@@ -63,8 +63,7 @@ $lSecondary = isset($argv[2])?$argv[2]:'';
$lEnglish = 'en_US';
$filesToProcess = isset($argv[3])?$argv[3]:'';
if (empty($lPrimary) || empty($lSecondary) || empty($filesToProcess))
{
if (empty($lPrimary) || empty($lSecondary) || empty($filesToProcess)) {
$rc = 1;
$msg = '***** Script to clean language files *****'."\n";
$msg.= 'Usage: ./dev/translation/strip_language_file.php xx_XX xx_YY [file.lang|all]'."\n";
@@ -77,8 +76,7 @@ $aSecondary = array();
$aEnglish = array();
// Define array $filesToProcess
if ($filesToProcess == 'all')
{
if ($filesToProcess == 'all') {
$dir = new DirectoryIterator('htdocs/langs/'.$lPrimary);
while ($dir->valid()) {
if (!$dir->isDot() && $dir->isFile() && ! preg_match('/^\./', $dir->getFilename())) {
@@ -87,15 +85,15 @@ if ($filesToProcess == 'all')
$dir->next();
}
$filesToProcess=$files;
} else {
$filesToProcess=explode(',', $filesToProcess);
}
else $filesToProcess=explode(',', $filesToProcess);
// Arguments should be OK here.
// Loop on each file
foreach ($filesToProcess as $fileToProcess)
{
foreach ($filesToProcess as $fileToProcess) {
$lPrimaryFile = 'htdocs/langs/'.$lPrimary.'/'.$fileToProcess;
$lSecondaryFile = 'htdocs/langs/'.$lSecondary.'/'.$fileToProcess;
$lEnglishFile = 'htdocs/langs/'.$lEnglish.'/'.$fileToProcess;
@@ -126,12 +124,10 @@ foreach ($filesToProcess as $fileToProcess)
// Start reading and parsing Secondary
if ( $handle = fopen($lSecondaryFile, 'r') )
{
if ($handle = fopen($lSecondaryFile, 'r')) {
print "Read Secondary File $lSecondaryFile:\n";
$cnt = 0;
while (($line = fgets($handle)) !== false)
{
while (($line = fgets($handle)) !== false) {
$cnt++;
// strip comments
@@ -165,16 +161,14 @@ foreach ($filesToProcess as $fileToProcess)
$aSecondary[$key] = trim($value);
}
if ( ! feof($handle) )
{
if (! feof($handle)) {
$rc = 5;
$msg = "Unexpected fgets() fail";
print $msg . " (rc=$rc).\n";
exit($rc);
}
fclose($handle);
}
else {
} else {
$rc = 6;
$msg = "Cannot open file $lSecondaryFile";
print $msg . " (rc=$rc).\n";
@@ -184,12 +178,10 @@ foreach ($filesToProcess as $fileToProcess)
// Start reading and parsing English
if ( $handle = fopen($lEnglishFile, 'r') )
{
if ($handle = fopen($lEnglishFile, 'r')) {
print "Read English File $lEnglishFile:\n";
$cnt = 0;
while (($line = fgets($handle)) !== false)
{
while (($line = fgets($handle)) !== false) {
$cnt++;
// strip comments
@@ -223,16 +215,14 @@ foreach ($filesToProcess as $fileToProcess)
$aEnglish[$key] = trim($value);
}
if ( ! feof($handle) )
{
if (! feof($handle)) {
$rc = 5;
$msg = "Unexpected fgets() fail";
print $msg . " (rc=$rc).\n";
exit($rc);
}
fclose($handle);
}
else {
} else {
$rc = 6;
$msg = "Cannot open file $lEnglishFile";
print $msg . " (rc=$rc).\n";
@@ -246,10 +236,8 @@ foreach ($filesToProcess as $fileToProcess)
$arrayofkeytoalwayskeep=array('DIRECTION','FONTFORPDF','FONTSIZEFORPDF','SeparatorDecimal','SeparatorThousand');
if ( $handle = fopen($lPrimaryFile, 'r') )
{
if ( ! $oh = fopen($output, 'w') )
{
if ($handle = fopen($lPrimaryFile, 'r')) {
if (! $oh = fopen($output, 'w')) {
print "ERROR in writing to file ".$output."\n";
exit;
}
@@ -259,8 +247,7 @@ foreach ($filesToProcess as $fileToProcess)
fwrite($oh, "# Dolibarr language file - Source file is en_US - ".(preg_replace('/\.lang$/', '', $fileToProcess))."\n");
$cnt = 0;
while (($line = fgets($handle)) !== false)
{
while (($line = fgets($handle)) !== false) {
$cnt++;
// strip comments
@@ -284,8 +271,7 @@ foreach ($filesToProcess as $fileToProcess)
if (array_key_exists($key, $aPrimary)) {
print "Key $key is redundant in file $lPrimaryFile (line: $cnt) - Already found into ".$fileFirstFound[$key]." (line: ".$lineFirstFound[$key].").\n";
continue;
}
else {
} else {
$fileFirstFound[$key] = $fileToProcess;
$lineFirstFound[$key] = $cnt;
}
@@ -305,23 +291,18 @@ foreach ($filesToProcess as $fileToProcess)
//print "Found primary key = ".$key."\n";
// Key not in other file
if (in_array($key, $arrayofkeytoalwayskeep) || preg_match('/^FormatDate/', $key) || preg_match('/^FormatHour/', $key))
{
if (in_array($key, $arrayofkeytoalwayskeep) || preg_match('/^FormatDate/', $key) || preg_match('/^FormatHour/', $key)) {
//print "Key $key is a key we always want to see into secondary file (line: $cnt).\n";
}
elseif ( ! array_key_exists($key, $aSecondary))
{
} elseif (! array_key_exists($key, $aSecondary)) {
//print "Key $key does NOT exist in secondary language (line: $cnt).\n";
continue;
}
// String exists in both files and value into alternative language differs from main language but also from english files
if (
(! empty($aSecondary[$key]) && $aSecondary[$key] != $aPrimary[$key]
if ((! empty($aSecondary[$key]) && $aSecondary[$key] != $aPrimary[$key]
&& ! empty($aEnglish[$key]) && $aSecondary[$key] != $aEnglish[$key])
|| in_array($key, $arrayofkeytoalwayskeep) || preg_match('/^FormatDate/', $key) || preg_match('/^FormatHour/', $key)
)
{
) {
//print "Key $key differs (aSecondary=".$aSecondary[$key].", aPrimary=".$aPrimary[$key].", aEnglish=".$aEnglish[$key].") so we add it into new secondary language (line: $cnt).\n";
fwrite($oh, $key."=".(empty($aSecondary[$key])?$aPrimary[$key]:$aSecondary[$key])."\n");
}
@@ -334,8 +315,7 @@ foreach ($filesToProcess as $fileToProcess)
}
fclose($oh);
fclose($handle);
}
else {
} else {
$rc = 8;
$msg = "Cannot open file $lPrimaryFile";
print $msg . " (rc=$rc).\n";