Fixing style errors.

This commit is contained in:
stickler-ci
2020-01-14 14:34:36 +00:00
parent 43aa5ec658
commit ece3face5e
4 changed files with 373 additions and 338 deletions

View File

@@ -116,7 +116,7 @@ foreach ($header as $value) {
} }
$sqlCreate .= ", PRIMARY KEY (`id`)) ENGINE = InnoDB"; $sqlCreate .= ", PRIMARY KEY (`id`)) ENGINE = InnoDB";
$resql = $db->query($sqlCreate); $resql = $db->query($sqlCreate);
if ($resql !== FALSE) { if ($resql !== false) {
print "Table $table_name created\n"; print "Table $table_name created\n";
} else { } else {
var_dump($db->errno()); var_dump($db->errno());
@@ -136,7 +136,7 @@ for ($i = 1; $i <= $record_numbers; $i++) {
if ($endlinenb && $i > $endlinenb) if ($endlinenb && $i > $endlinenb)
continue; continue;
$row = dbase_get_record_with_names($fhandle, $i); $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; continue;
$sqlInsert = "INSERT INTO `$table_name`($fields) VALUES (null,"; $sqlInsert = "INSERT INTO `$table_name`($fields) VALUES (null,";
array_shift($row); // remove delete column array_shift($row); // remove delete column
@@ -152,8 +152,8 @@ for ($i = 1; $i <= $record_numbers; $i++) {
var_dump($row, $db->errno()); var_dump($row, $db->errno());
die(); die();
} }
// $fields = (object) $row; // $fields = (object) $row;
// var_dump($fields); // var_dump($fields);
continue; continue;
} }
die(); die();
@@ -179,7 +179,8 @@ fclose($fhandleerr);
exit($error); exit($error);
function replaceable_echo($message, $force_clear_lines = NULL) { function replaceable_echo($message, $force_clear_lines = null)
{
static $last_lines = 0; static $last_lines = 0;
if (!is_null($force_clear_lines)) { if (!is_null($force_clear_lines)) {

View File

@@ -89,9 +89,9 @@ if (!$ret > 0) {
$sql = "SELECT * FROM `$table` WHERE 1"; $sql = "SELECT * FROM `$table` WHERE 1";
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql)
while ($fields = $db->fetch_array($resql)) { while ($fields = $db->fetch_array($resql)) {
$errorrecord = 0; $errorrecord = 0;
if ($fields === FALSE) if ($fields === false)
continue; continue;
$nboflines++; $nboflines++;
@@ -108,8 +108,8 @@ if ($resql)
if (empty($produit->label)) if (empty($produit->label))
continue; continue;
//$produit->description = trim($fields[4] . "\n" . ($fields[5] ? $fields[5] . ' x ' . $fields[6] . ' x ' . $fields[7] : '')); //$produit->description = trim($fields[4] . "\n" . ($fields[5] ? $fields[5] . ' x ' . $fields[6] . ' x ' . $fields[7] : ''));
// $produit->volume = price2num($fields[8]); // $produit->volume = price2num($fields[8]);
// $produit->volume_unit = 0; // $produit->volume_unit = 0;
$produit->weight = price2num($fields['MASSE']); $produit->weight = price2num($fields['MASSE']);
$produit->weight_units = 0; // -3 = g $produit->weight_units = 0; // -3 = g
//$produit->customcode = $fields[10]; //$produit->customcode = $fields[10];
@@ -122,33 +122,33 @@ if ($resql)
$produit->finished = 1; $produit->finished = 1;
// $produit->multiprices[0] = price2num($fields['TARIF0']); // $produit->multiprices[0] = price2num($fields['TARIF0']);
// $produit->multiprices[1] = price2num($fields['TARIF1']); // $produit->multiprices[1] = price2num($fields['TARIF1']);
// $produit->multiprices[2] = price2num($fields['TARIF2']); // $produit->multiprices[2] = price2num($fields['TARIF2']);
// $produit->multiprices[3] = price2num($fields['TARIF3']); // $produit->multiprices[3] = price2num($fields['TARIF3']);
// $produit->multiprices[4] = price2num($fields['TARIF4']); // $produit->multiprices[4] = price2num($fields['TARIF4']);
// $produit->multiprices[5] = price2num($fields['TARIF5']); // $produit->multiprices[5] = price2num($fields['TARIF5']);
// $produit->multiprices[6] = price2num($fields['TARIF6']); // $produit->multiprices[6] = price2num($fields['TARIF6']);
// $produit->multiprices[7] = price2num($fields['TARIF7']); // $produit->multiprices[7] = price2num($fields['TARIF7']);
// $produit->multiprices[8] = price2num($fields['TARIF8']); // $produit->multiprices[8] = price2num($fields['TARIF8']);
// $produit->multiprices[9] = price2num($fields['TARIF9']); // $produit->multiprices[9] = price2num($fields['TARIF9']);
// $produit->price_min = null; // $produit->price_min = null;
// $produit->price_min_ttc = null; // $produit->price_min_ttc = null;
// $produit->price = price2num($fields[11]); // $produit->price = price2num($fields[11]);
// $produit->price_ttc = price2num($fields[12]); // $produit->price_ttc = price2num($fields[12]);
// $produit->price_base_type = 'TTC'; // $produit->price_base_type = 'TTC';
// $produit->tva_tx = price2num($fields[13]); // $produit->tva_tx = price2num($fields[13]);
$produit->tva_tx = (int) ($tvas[$fields['CODTVA']]); $produit->tva_tx = (int) ($tvas[$fields['CODTVA']]);
$produit->tva_npr = 0; $produit->tva_npr = 0;
// $produit->cost_price = price2num($fields[16]); // $produit->cost_price = price2num($fields[16]);
//compta //compta
$produit->accountancy_code_buy = trim($fields['COMACH']); $produit->accountancy_code_buy = trim($fields['COMACH']);
$produit->accountancy_code_sell = trim($fields['COMVEN']); $produit->accountancy_code_sell = trim($fields['COMVEN']);
// $produit->accountancy_code_sell_intra=trim($fields['COMVEN']); // $produit->accountancy_code_sell_intra=trim($fields['COMVEN']);
// $produit->accountancy_code_sell_export=trim($fields['COMVEN']); // $produit->accountancy_code_sell_export=trim($fields['COMVEN']);
// Extrafields // Extrafields
// $produit->array_options['options_ecotaxdeee'] = price2num($fields[17]); // $produit->array_options['options_ecotaxdeee'] = price2num($fields[17]);
$produit->seuil_stock_alerte = $fields['STALERTE']; $produit->seuil_stock_alerte = $fields['STALERTE'];
$ret = $produit->create($user, 0); $ret = $produit->create($user, 0);
@@ -179,20 +179,20 @@ if ($resql)
} }
// dol_syslog("Add multilangs"); // dol_syslog("Add multilangs");
// Add alternative languages // 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['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); // $produit->multilangs['en_US'] = array('label' => $fields[3], 'description' => $produit->description, 'note' => $produit->note_private);
// //
// $ret = $produit->setMultiLangs($user); // $ret = $produit->setMultiLangs($user);
// if ($ret < 0) { // if ($ret < 0) {
// print " - Error in setMultiLangs result code = " . $ret . " - " . $produit->errorsToString(); // print " - Error in setMultiLangs result code = " . $ret . " - " . $produit->errorsToString();
// $errorrecord++; // $errorrecord++;
// } else { // } else {
// print " - setMultiLangs OK"; // print " - setMultiLangs OK";
// } // }
// } // }
dol_syslog("Add stocks"); dol_syslog("Add stocks");
@@ -227,7 +227,7 @@ if ($resql)
$error++; // $errorrecord will be reset $error++; // $errorrecord will be reset
} }
$j++; $j++;
} else } else
die("error : $sql"); die("error : $sql");

View File

@@ -145,7 +145,7 @@ $sql = "SELECT * FROM `$table` WHERE 1 "; //ORDER BY REMISE DESC,`LCIVIL` DESC";
$resql = $db->query($sql); $resql = $db->query($sql);
//$db->begin(); //$db->begin();
if ($resql) if ($resql)
while ($fields = $db->fetch_array($resql)) { while ($fields = $db->fetch_array($resql)) {
$i++; $i++;
$errorrecord = 0; $errorrecord = 0;
@@ -186,7 +186,7 @@ if ($resql)
$object->fax = trim($fields['FFAX']) ? trim($fields['FFAX']) : trim($fields['FCONTACT']); $object->fax = trim($fields['FFAX']) ? trim($fields['FFAX']) : trim($fields['FCONTACT']);
$object->fax = substr($object->fax, 0, 20); $object->fax = substr($object->fax, 0, 20);
$object->email = trim($fields['FMAIL']); $object->email = trim($fields['FMAIL']);
// $object->idprof2 = trim($fields[29]); // $object->idprof2 = trim($fields[29]);
$object->tva_intra = str_replace(['.', ' '], '', $fields['TVAINTRA']); $object->tva_intra = str_replace(['.', ' '], '', $fields['TVAINTRA']);
$object->tva_intra = substr($object->tva_intra, 0, 20); $object->tva_intra = substr($object->tva_intra, 0, 20);
$object->default_lang = 'fr_FR'; $object->default_lang = 'fr_FR';
@@ -198,8 +198,8 @@ if ($resql)
$object->remise_percent = abs($fields['REMISE']); $object->remise_percent = abs($fields['REMISE']);
} }
// $object->code_client = $fields[9]; // $object->code_client = $fields[9];
// $object->code_fournisseur = $fields[10]; // $object->code_fournisseur = $fields[10];
if ($fields['FCIVIL']) { if ($fields['FCIVIL']) {
@@ -209,8 +209,8 @@ if ($resql)
// Set price level // Set price level
$object->price_level = $fields['TARIF'] + 1; $object->price_level = $fields['TARIF'] + 1;
// if ($labeltype == 'Revendeur') // if ($labeltype == 'Revendeur')
// $object->price_level = 2; // $object->price_level = 2;
print "Process line nb " . $i . ", code " . $fields['CODE'] . ", name " . $object->name; print "Process line nb " . $i . ", code " . $fields['CODE'] . ", name " . $object->name;
@@ -335,12 +335,12 @@ if ($resql)
if ($errorrecord) { if ($errorrecord) {
print( 'Error on record nb ' . $i . " - " . $object->errorsToString() . "\n"); print( 'Error on record nb ' . $i . " - " . $object->errorsToString() . "\n");
var_dump($db, $object, $contact); var_dump($db, $object, $contact);
// $db->rollback(); // $db->rollback();
die(); die();
$error++; // $errorrecord will be reset $error++; // $errorrecord will be reset
} }
$j++; $j++;
} else } else
die("error : $sql"); die("error : $sql");
$db->commit(); $db->commit();

View File

@@ -8,7 +8,8 @@ define('DBASE_RDWR', 2);
define('DBASE_TYPE_DBASE', 0); define('DBASE_TYPE_DBASE', 0);
define('DBASE_TYPE_FOXPRO', 1); define('DBASE_TYPE_FOXPRO', 1);
class DBase { class DBase
{
private $fd; private $fd;
private $headerLength = 0; private $headerLength = 0;
@@ -18,7 +19,8 @@ class DBase {
private $recordCount = 0; private $recordCount = 0;
//resource dbase_open ( string $filename , int $mode ) //resource dbase_open ( string $filename , int $mode )
public static function open($filename, $mode) { public static function open($filename, $mode)
{
if (!file_exists($filename)) if (!file_exists($filename))
return false; return false;
$modes = array('r', 'w', 'r+'); $modes = array('r', 'w', 'r+');
@@ -30,7 +32,8 @@ class DBase {
} }
//resource dbase_create ( string $filename , array $fields [, int $type = DBASE_TYPE_DBASE ] ) //resource dbase_create ( string $filename , array $fields [, int $type = DBASE_TYPE_DBASE ] )
public static function create($filename, $fields, $type = DBASE_TYPE_DBASE) { public static function create($filename, $fields, $type = DBASE_TYPE_DBASE)
{
if (file_exists($filename)) if (file_exists($filename))
return false; return false;
$fd = fopen($filename, 'c+'); $fd = fopen($filename, 'c+');
@@ -93,7 +96,8 @@ class DBase {
} }
// Create DBase instance // Create DBase instance
private function __construct($fd) { private function __construct($fd)
{
$this->fd = $fd; $this->fd = $fd;
// Byte 4-7 (32-bit number): Number of records in the database file. Currently 0 // Byte 4-7 (32-bit number): Number of records in the database file. Currently 0
fseek($this->fd, 4, SEEK_SET); fseek($this->fd, 4, SEEK_SET);
@@ -116,27 +120,32 @@ class DBase {
} }
//bool dbase_close ( resource $dbase_identifier ) //bool dbase_close ( resource $dbase_identifier )
public function close() { public function close()
{
fclose($this->fd); fclose($this->fd);
} }
//array dbase_get_header_info ( resource $dbase_identifier ) //array dbase_get_header_info ( resource $dbase_identifier )
public function get_header_info() { public function get_header_info()
{
return $this->fields; return $this->fields;
} }
//int dbase_numfields ( resource $dbase_identifier ) //int dbase_numfields ( resource $dbase_identifier )
public function numfields() { public function numfields()
{
return $this->fieldCount; return $this->fieldCount;
} }
//int dbase_numrecords ( resource $dbase_identifier ) //int dbase_numrecords ( resource $dbase_identifier )
public function numrecords() { public function numrecords()
{
return $this->recordCount; return $this->recordCount;
} }
//bool dbase_add_record ( resource $dbase_identifier , array $record ) //bool dbase_add_record ( resource $dbase_identifier , array $record )
public function add_record($record) { public function add_record($record)
{
if (count($record) != $this->fieldCount) if (count($record) != $this->fieldCount)
return false; return false;
// Seek to end of file, minus the end of file marker // Seek to end of file, minus the end of file marker
@@ -153,7 +162,8 @@ class DBase {
} }
//bool dbase_replace_record ( resource $dbase_identifier , array $record , int $record_number ) //bool dbase_replace_record ( resource $dbase_identifier , array $record , int $record_number )
public function replace_record($record, $record_number) { public function replace_record($record, $record_number)
{
if (count($record) != $this->fieldCount) if (count($record) != $this->fieldCount)
return false; return false;
if ($record_number < 1 || $record_number > $this->recordCount) if ($record_number < 1 || $record_number > $this->recordCount)
@@ -164,7 +174,8 @@ class DBase {
} }
//bool dbase_delete_record ( resource $dbase_identifier , int $record_number ) //bool dbase_delete_record ( resource $dbase_identifier , int $record_number )
public function delete_record($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; return false;
fseek($this->fd, $this->headerLength + ($this->recordLength * ($record_number - 1))); fseek($this->fd, $this->headerLength + ($this->recordLength * ($record_number - 1)));
@@ -173,7 +184,8 @@ class DBase {
} }
//array dbase_get_record ( resource $dbase_identifier , int $record_number ) //array dbase_get_record ( resource $dbase_identifier , int $record_number )
public function get_record($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; return false;
fseek($this->fd, $this->headerLength + ($this->recordLength * ($record_number - 1))); fseek($this->fd, $this->headerLength + ($this->recordLength * ($record_number - 1)));
@@ -186,7 +198,7 @@ class DBase {
$value = strtolower($value); $value = strtolower($value);
if ($value == 't' || $value == 'y') if ($value == 't' || $value == 'y')
$value = true; $value = true;
else if ($value == 'f' || $value == 'n') elseif ($value == 'f' || $value == 'n')
$value = false; $value = false;
else else
$value = null; $value = null;
@@ -197,7 +209,8 @@ class DBase {
} }
//array dbase_get_record_with_names ( resource $dbase_identifier , int $record_number ) //array dbase_get_record_with_names ( resource $dbase_identifier , int $record_number )
public function get_record_with_names($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; return false;
$record = $this->get_record($record_number); $record = $this->get_record($record_number);
@@ -209,7 +222,8 @@ class DBase {
} }
//bool dbase_pack ( resource $dbase_identifier ) //bool dbase_pack ( resource $dbase_identifier )
public function pack() { public function pack()
{
$in_offset = $out_offset = $this->headerLength; $in_offset = $out_offset = $this->headerLength;
$new_count = 0; $new_count = 0;
$rec_count = $this->recordCount; $rec_count = $this->recordCount;
@@ -236,7 +250,8 @@ class DBase {
* A few utilitiy functions * A few utilitiy functions
*/ */
private static function length($field) { private static function length($field)
{
switch ($field[1]) { switch ($field[1]) {
case 'D': // Date: Numbers and a character to separate month, day, and year (stored internally as 8 digits in YYYYMMDD format) case 'D': // Date: Numbers and a character to separate month, day, and year (stored internally as 8 digits in YYYYMMDD format)
return 8; return 8;
@@ -257,15 +272,18 @@ class DBase {
* Functions for reading and writing bytes * Functions for reading and writing bytes
*/ */
private static function getChar8($fd) { private static function getChar8($fd)
{
return ord(fread($fd, 1)); return ord(fread($fd, 1));
} }
private static function putChar8($fd, $value) { private static function putChar8($fd, $value)
{
return fwrite($fd, chr($value)); return fwrite($fd, chr($value));
} }
private static function getInt16($fd, $n = 1) { private static function getInt16($fd, $n = 1)
{
$data = fread($fd, 2 * $n); $data = fread($fd, 2 * $n);
$i = unpack("S$n", $data); $i = unpack("S$n", $data);
if ($n == 1) if ($n == 1)
@@ -274,11 +292,13 @@ class DBase {
return array_merge($i); return array_merge($i);
} }
private static function putInt16($fd, $value) { private static function putInt16($fd, $value)
{
return fwrite($fd, pack('S', $value)); return fwrite($fd, pack('S', $value));
} }
private static function getInt32($fd, $n = 1) { private static function getInt32($fd, $n = 1)
{
$data = fread($fd, 4 * $n); $data = fread($fd, 4 * $n);
$i = unpack("L$n", $data); $i = unpack("L$n", $data);
if ($n == 1) if ($n == 1)
@@ -287,15 +307,18 @@ class DBase {
return array_merge($i); return array_merge($i);
} }
private static function putInt32($fd, $value) { private static function putInt32($fd, $value)
{
return fwrite($fd, pack('L', $value)); return fwrite($fd, pack('L', $value));
} }
private static function putString($fd, $value, $length = 254) { private static function putString($fd, $value, $length = 254)
{
$ret = fwrite($fd, pack('A' . $length, $value)); $ret = fwrite($fd, pack('A' . $length, $value));
} }
private function putRecord($record) { private function putRecord($record)
{
foreach ($this->fields as $i => &$field) { foreach ($this->fields as $i => &$field) {
$value = $record[$i]; $value = $record[$i];
// Number types are right aligned with spaces // Number types are right aligned with spaces
@@ -306,56 +329,67 @@ class DBase {
} }
return true; return true;
} }
} }
if (!function_exists('dbase_open')) { if (!function_exists('dbase_open')) {
function dbase_open($filename, $mode) { function dbase_open($filename, $mode)
{
return DBase::open($filename, $mode); return DBase::open($filename, $mode);
} }
function dbase_create($filename, $fields, $type = DBASE_TYPE_DBASE) { function dbase_create($filename, $fields, $type = DBASE_TYPE_DBASE)
{
return DBase::create($filename, $fields, $type); return DBase::create($filename, $fields, $type);
} }
function dbase_close($dbase_identifier) { function dbase_close($dbase_identifier)
{
return $dbase_identifier->close(); return $dbase_identifier->close();
} }
function dbase_get_header_info($dbase_identifier) { function dbase_get_header_info($dbase_identifier)
{
return $dbase_identifier->get_header_info(); return $dbase_identifier->get_header_info();
} }
function dbase_numfields($dbase_identifier) { function dbase_numfields($dbase_identifier)
{
$dbase_identifier->numfields(); $dbase_identifier->numfields();
} }
function dbase_numrecords($dbase_identifier) { function dbase_numrecords($dbase_identifier)
{
return $dbase_identifier->numrecords(); return $dbase_identifier->numrecords();
} }
function dbase_add_record($dbase_identifier, $record) { function dbase_add_record($dbase_identifier, $record)
{
return $dbase_identifier->add_record($record); return $dbase_identifier->add_record($record);
} }
function dbase_delete_record($dbase_identifier, $record_number) { function dbase_delete_record($dbase_identifier, $record_number)
{
return $dbase_identifier->delete_record($record_number); return $dbase_identifier->delete_record($record_number);
} }
function dbase_replace_record($dbase_identifier, $record, $record_number) { function dbase_replace_record($dbase_identifier, $record, $record_number)
{
return $dbase_identifier->replace_record($record, $record_number); return $dbase_identifier->replace_record($record, $record_number);
} }
function dbase_get_record($dbase_identifier, $record_number) { function dbase_get_record($dbase_identifier, $record_number)
{
return $dbase_identifier->get_record($record_number); return $dbase_identifier->get_record($record_number);
} }
function dbase_get_record_with_names($dbase_identifier, $record_number) { function dbase_get_record_with_names($dbase_identifier, $record_number)
{
return $dbase_identifier->get_record_with_names($record_number); return $dbase_identifier->get_record_with_names($record_number);
} }
function dbase_pack($dbase_identifier) { function dbase_pack($dbase_identifier)
{
return $dbase_identifier->pack(); return $dbase_identifier->pack();
} }