Skip to content

Commit

Permalink
Merge branch 'develop' into documentationUX
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy authored Nov 13, 2024
2 parents db7ea74 + 714dc0c commit 730a92b
Show file tree
Hide file tree
Showing 21 changed files with 136 additions and 52 deletions.
4 changes: 3 additions & 1 deletion dev/tools/phan/baseline_extended.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ return [
'htdocs/accountancy/admin/productaccount.php' => ['PhanTypeMismatchArgumentNullableInternal'], // false positive
'internal' => ['PhanUndeclaredConstant'],
],
// 'directory_suppressions' => ['src/directory_name' => ['PhanIssueName1', 'PhanIssueName2']] can be manually added if needed.
'directory_suppressions' => [
'htdocs/admin/tools' => ['PhanPluginUnknownArrayPropertyType', 'PhanTypeArraySuspiciousNull', 'PhanPluginUnknownArrayMethodParamType', 'PhanTypeSuspiciousEcho']
]
// (directory_suppressions will currently be ignored by subsequent calls to --save-baseline, but may be preserved in future Phan releases)
];
1 change: 1 addition & 0 deletions dev/tools/phan/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@
// mymodule seen in cti, but not in git.
.'|htdocs/custom/.*' // Ignore all custom modules @phpstan-ignore-line
.'|htdocs/.*/canvas/.*/tpl/.*.tpl.php' // @phpstan-ignore-line
.'|htdocs/admin/tools/ui/.*' // @phpstan-ignore-line
//.'|htdocs/modulebuilder/template/.*' // @phpstan-ignore-line
// Included as stub (better analysis)
.'|htdocs/includes/nusoap/.*' // @phpstan-ignore-line
Expand Down
4 changes: 2 additions & 2 deletions dev/tools/phan/config_fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
$config['exclude_file_regex'] = '@^(' // @phpstan-ignore-line
.'dummy' // @phpstan-ignore-line
.'|htdocs/.*/canvas/.*/tpl/.*.tpl.php' // @phpstan-ignore-line
.'|htdocs/modulebuilder/template/.*' // @phpstan-ignore-line
.'|htdocs/admin/tools/ui/.*' // @phpstan-ignore-line
//.'|htdocs/modulebuilder/template/.*' // @phpstan-ignore-line
// Included as stub (old version + incompatible typing hints)
.'|htdocs/includes/restler/.*' // @phpstan-ignore-line
// Included as stub (did not seem properly analysed by phan without it)
Expand All @@ -33,7 +34,6 @@

// $config['plugins'][] = __DIR__.'/plugins/ParamMatchRegexPlugin.php';
$config['plugins'][] = 'DeprecateAliasPlugin';
$config['plugins'][] = 'DeprecateAliasPlugin';
// $config['plugins'][] = __DIR__.'/plugins/GetPostFixerPlugin.php';
// $config['plugins'][] = 'PHPDocToRealTypesPlugin';

Expand Down
9 changes: 5 additions & 4 deletions htdocs/core/class/commonstickergenerator.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,14 @@ public function __construct($db)
/**
* Function to build PDF on disk, then output on HTTP stream.
*
* @param array<string,mixed> $arrayofrecords Array of record information (array('textleft'=>,'textheader'=>, ..., 'id'=>,'photo'=>)
* @param Adherent|array<array{textleft:string,textheader:string,textfooter:string,textright:string,id:string,photo:string}> $arrayofrecords Array of record information (array('textleft'=>,'textheader'=>, ..., 'id'=>,'photo'=>)
* @param Translate $outputlangs Lang object for output language
* @param string $srctemplatepath Full path of source filename for generator using a template file
* @param string $outputdir Output directory for pdf file
* @return int 1=OK, 0=KO
* @param string $outputdir Output directory for pdf file
* @param string $filename Short file name of output file
* @return int<-1,1> 1=OK, <=0=KO
*/
abstract public function write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir = '');
abstract public function write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir = '', $filename = '');
// phpcs:enable

/**
Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/modules/cheque/doc/pdf_blochet.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function __construct($db)
* @param string $_dir Directory
* @param string $number Number
* @param Translate $outputlangs Lang output object
* @return int 1=ok, 0=ko
* @return int<-1,1> 1 if OK, <=0 if KO
*/
public function write_file($object, $_dir, $number, $outputlangs)
{
Expand Down
5 changes: 4 additions & 1 deletion htdocs/core/modules/cheque/modules_chequereceipts.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ public static function liste_modeles($db, $maxfilenamelength = 0)

return $list;
}


// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Fonction to generate document on disk
Expand Down Expand Up @@ -167,7 +169,8 @@ function chequereceipt_pdf_create($db, $id, $message, $modele, $outputlangs)
// We save charset_output to restore it because write_file can change it if needed for
// output format that does not support UTF8.
$sav_charset_output = $outputlangs->charset_output;
if ($obj->write_file($id, $outputlangs) > 0) {
// TODO: write_file seems invalid, function is likely no longer used - delete ?
if ($obj->write_file($id, $outputlangs) > 0) { // @phan-suppress-current-line PhanParamTooFew,PhanPluginSuspiciousParamPosition
$outputlangs->charset_output = $sav_charset_output;
return 1;
} else {
Expand Down
6 changes: 3 additions & 3 deletions htdocs/core/modules/dons/html_cerfafr.modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ public function isEnabled()
/**
* Write the object to document file to disk
*
* @param Don $don Donation object
* @param Translate $outputlangs Lang object for output language
* @param Don $don Donation object
* @param Translate $outputlangs Lang object for output language
* @param string $currency Currency code
* @return int >0 if OK, <0 if KO
* @return int<-1,1> >0 if OK, <0 if KO
*/
public function write_file($don, $outputlangs, $currency = '')
{
Expand Down
6 changes: 3 additions & 3 deletions htdocs/core/modules/dons/html_generic.modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ private function saveFile($path, $contents)
/**
* Write the object to document file to disk
*
* @param Don $don Donation object
* @param Translate $outputlangs Lang object for output language
* @param Don $don Donation object
* @param Translate $outputlangs Lang object for output language
* @param string $currency Currency code
* @return int >0 if OK, <0 if KO
* @return int<-1,1> >0 if OK, <0 if KO
*/
public function write_file($don, $outputlangs, $currency = '')
{
Expand Down
11 changes: 11 additions & 0 deletions htdocs/core/modules/dons/modules_don.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ public static function liste_modeles($db, $maxfilenamelength = 0)

return $list;
}

// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Write the object to document file to disk
*
* @param Don $don Donation object
* @param Translate $outputlangs Lang object for output language
* @param string $currency Currency code
* @return int<-1,1> >0 if OK, <0 if KO
*/
abstract public function write_file($don, $outputlangs, $currency = '');
}


Expand Down
18 changes: 9 additions & 9 deletions htdocs/core/modules/member/doc/pdf_standard_member.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,17 +262,17 @@ public function Add_PDF_card(&$pdf, $textleft, $header, $footer, $outputlangs, $

// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Function to build PDF on disk, then output on HTTP stream.
* Function to build PDF on disk, then output on HTTP stream.
*
* @param Adherent|array $object Member object. Old usage: Array of record information (array('textleft'=>,'textheader'=>, ...'id'=>,'photo'=>)
* @param Translate $outputlangs Lang object for output language
* @param string $srctemplatepath Full path of source filename for generator using a template file. Example: '5161', 'AVERYC32010', 'CARD', ...
* @param string $mode Tell if doc module is called for 'member', ...
* @param int $nooutput 1=Generate only file on disk and do not return it on response
* @param string $filename Name of output file (without extension)
* @return int 1=OK, 0=KO
* @param Adherent|array<array{textleft:string,textheader:string,textfooter:string,textright:string,id:string,photo:string}> $object Array of record information (array('textleft'=>,'textheader'=>, ..., 'id'=>,'photo'=>)
* @param Translate $outputlangs Lang object for output language
* @param string $srctemplatepath file. Example: '5161', 'AVERYC32010', 'CARD', ...
* @param string $mode Tell if doc module is called
* @param string $nooutput 1=Generate only file on disk and do not return it on response // TODO: Fix not compatible parameter signature.
* @param string $filename Name of output file (without extension)
* @return int<-1,1> 1=OK, <=0=KO
*/
public function write_file($object, $outputlangs, $srctemplatepath, $mode = 'member', $nooutput = 0, $filename = 'tmp_cards')
public function write_file($object, $outputlangs, $srctemplatepath, $mode = 'member', $nooutput = '', $filename = 'tmp_cards')
{
// phpcs:enable
global $user, $conf, $langs, $mysoc, $_Avery_Labels;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,12 @@ public function Add_PDF_label(&$pdf, $textleft, $header, $footer, $outputlangs,
/**
* Function to build PDF on disk, then output on HTTP stream.
*
* @param array<array{textleft:string,textheader:string,textfooter:string,textright:string,photo:string}> $arrayofrecords Array of record information (array('textleft'=>,'textheader'=>, ..., 'id'=>,'photo'=>)
* @param array<array{textleft:string,textheader:string,textfooter:string,textright:string,id:string,photo:string}> $arrayofrecords Array of record information (array('textleft'=>,'textheader'=>, ..., 'id'=>,'photo'=>)
* @param Translate $outputlangs Lang object for output language
* @param string $srctemplatepath Full path of source filename for generator using a template file
* @param string $outputdir Output directory for pdf file
* @param string $filename Short file name of PDF output file
* @return int 1=OK, 0=KO
* @return int<-1,1> 1=OK, <=0=KO
*/
public function write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir = '', $filename = 'tmp_address_sheet.pdf')
{
Expand Down
4 changes: 2 additions & 2 deletions htdocs/core/modules/printsheet/doc/pdf_tcpdflabel.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,14 @@ public function addSticker(&$pdf, $outputlangs, $param)

// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Function to build PDF on disk, then output on HTTP stream.
* Function to build PDF on disk, then output on HTTP stream.
*
* @param Adherent|array<array{textleft:string,textheader:string,textfooter:string,textright:string,code:string,encoding:string,is2d:int<0,1>|bool}> $arrayofrecords Array of record information (array('textleft'=>,'textheader'=>, ..., 'id'=>,'photo'=>)
* @param Translate $outputlangs Lang object for output language
* @param string $srctemplatepath Full path of source filename for generator using a template file
* @param string $outputdir Output directory for pdf file
* @param string $filename Short file name of PDF output file
* @return int 1=OK, 0=KO
* @return int<-1,1> 1=OK, <=0=KO
*/
public function write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir = '', $filename = 'tmp_address_sheet.pdf')
{
Expand Down
5 changes: 3 additions & 2 deletions htdocs/core/modules/stocktransfer/doc/pdf_eagle.modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,18 @@ public function __construct(DoliDB $db)
}
}


// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Function to build pdf onto disk
*
* @param StockTransfer $object Object StockTransfer to generate (or id if old method)
* @param Translate $outputlangs Lang output object
* @param Translate $outputlangs Lang output object
* @param string $srctemplatepath Full path of source filename for generator using a template file
* @param int<0,1> $hidedetails Do not show line details
* @param int<0,1> $hidedesc Do not show desc
* @param int<0,1> $hideref Do not show ref
* @return int<-1,1> 1=OK, 0=KO
* @return int<-1,1> 1 if OK, <=0 if KO
*/
public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
{
Expand Down
12 changes: 7 additions & 5 deletions htdocs/don/class/don.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1019,14 +1019,14 @@ public function info($id)


/**
* Create a document onto disk according to template module.
* Create a document on disk according to template module.
*
* @param string $modele Force template to use ('' to not force)
* @param Translate $outputlangs object lang a utiliser pour traduction
* @param int $hidedetails Hide details of lines
* @param int $hidedesc Hide description
* @param int $hideref Hide ref
* @return int 0 if KO, 1 if OK
* @param int<0,1> $hidedetails Hide details of lines
* @param int<0,1> $hidedesc Hide description
* @param int<0,1> $hideref Hide ref
* @return int<-1,1> 0 if KO, 1 if OK
*/
public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
{
Expand Down Expand Up @@ -1098,6 +1098,8 @@ public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hided
$classname = $modele;
$obj = new $classname($this->db);

'@phan-var-force ModeleDon $obj';

// We save charset_output to restore it because write_file can change it if needed for
// output format that does not support UTF8.
$sav_charset_output = $outputlangs->charset_output;
Expand Down
52 changes: 51 additions & 1 deletion htdocs/install/upgrade2.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,15 @@
$afterversionarray = explode('.', '18.0.9');
$beforeversionarray = explode('.', '19.0.9');
if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
migrate_contractdet_rank();
}
*/

// Scripts for 20.0
$afterversionarray = explode('.', '19.0.9');
$beforeversionarray = explode('.', '20.0.9');
if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
migrate_productlot_path();
}
}


Expand Down Expand Up @@ -4380,6 +4386,50 @@ function migrate_reload_menu($db, $langs, $conf)
return 1;
}

/**
* Migrate file from old path to new one for lot path
*
* @return void
*/
function migrate_productlot_path()
{
global $conf, $db, $langs, $user;

print '<tr><td colspan="4">';

print '<b>'.$langs->trans('MigrationProductLotPath')."</b><br>\n";

$sql = "SELECT rowid , entity, batch, fk_product from ".MAIN_DB_PREFIX."product_lot";
$resql = $db->query($sql);
if ($resql) {
$modulepart="product_batch";
while ($obj = $db->fetch_object($resql)) {
$entity = (empty($obj->entity) ? 1 : $obj->entity);
if ($entity > 1) {
$dir = DOL_DATA_ROOT.'/'.$entity.'/'.$conf->productbatch->multidir_output[$entity];
} else {
$dir = $conf->productbatch->multidir_output[$entity];
}

$lot = new Productlot($db);
$res = $lot->fetch($obj->rowid, $obj->fk_product, $obj->batch);

if ($dir && $res > 0) {
$lot->ref = $obj->batch;
$origin = $dir . '/' . get_exdir(0, 0, 0, 1, $lot, $modulepart);

$lot->fetch($obj->rowid, $obj->fk_product, $obj->batch);
$destin = $dir . '/' . get_exdir(0, 0, 0, 1, $lot, $modulepart);

if (dol_is_dir($origin) && !dol_is_dir($destin)) {
dol_move_dir($origin, $destin, 0);
}
}
}
}
print '</td></tr>';
}

/**
* Migrate file from old path to new one for users
*
Expand Down
1 change: 1 addition & 0 deletions htdocs/langs/en_US/install.lang
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,4 @@ FunctionTest=Function test
NodoUpgradeAfterDB=No action requested by external modules after upgrade of database
NodoUpgradeAfterFiles=No action requested by external modules after upgrade of files or directories
MigrationContractLineRank=Migrate Contract Line to use Rank (and enable Reorder)
MigrationProductLotPath=Migrate Product Batch files path
12 changes: 6 additions & 6 deletions htdocs/product/stock/productlot_card.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@
$productid = GETPOSTINT('productid');
$ref = GETPOST('ref', 'alpha'); // ref is productid_batch


$modulepart = 'product_batch';


// Initialize a technical objects

$object = new Productlot($db);
$extrafields = new ExtraFields($db);
$hookmanager->initHooks(array('productlotcard', 'globalcard')); // Note that conf->hooks_modules contains array
Expand Down Expand Up @@ -103,13 +108,8 @@
$batch = $tmp[1];
}
$object->fetch($id, $productid, $batch);
$object->ref = $object->batch; // Old system for document management ( it uses $object->ref)
$upload_dir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, $modulepart);
$filearray = dol_dir_list($upload_dir, "files");
if (empty($filearray)) {
// If no files linked yet, use new system on lot id. (Batch is not unique and can be same on different product)
$object->fetch($id, $productid, $batch);
}
}

// Initialize a technical object to manage hooks of modules. Note that conf->hooks_modules contains array array
Expand Down Expand Up @@ -602,7 +602,7 @@
// Documents
if ($includedocgeneration) {
$objref = dol_sanitizeFileName($object->ref);
$relativepath = $objref.'/'.$objref.'.pdf';
$relativepath = $object->id.'/'.$objref.'.pdf';
$filedir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, 'product_batch');
$urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
$genallowed = $usercanread; // If you can read, you can build the PDF to read content
Expand Down
6 changes: 0 additions & 6 deletions htdocs/product/stock/productlot_document.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,10 @@
$batch = $tmp[1];
}
$object->fetch($id, $productid, $batch);
$object->ref = $object->batch; // Old system for document management ( it uses $object->ref)

if (isModEnabled('productbatch')) {
$upload_dir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, $modulepart);
$filearray = dol_dir_list($upload_dir, "files");
if (empty($filearray)) {
// If no files linked yet, use new system on lot id. (Batch is not unique and can be same on different product)
$object->fetch($id, $productid, $batch);
$upload_dir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, $modulepart);
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions htdocs/recruitment/admin/setup_candidatures.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@

$module = new $classname($db);

'@phan-var-force ModelePDFRecruitmentCandidature $module';

if ($module->write_file($tmpobject, $langs) > 0) {
header("Location: ".DOL_URL_ROOT."/document.php?modulepart=".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ public static function liste_modeles($db, $maxfilenamelength = 0)

return $list;
}


// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Function to build a document on disk using the generic odt module.
*
* @param RecruitmentCandidature $object Object source to build document
* @param Translate $outputlangs Lang output object
* @param string $srctemplatepath Full path of source filename for generator using a template file
* @param int<0,1> $hidedetails Do not show line details
* @param int<0,1> $hidedesc Do not show desc
* @param int<0,1> $hideref Do not show ref
* @return int<-1,1> 1 if OK, <=0 if KO
*/
abstract public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0);
// phpcs:enable
}


Expand Down
Loading

0 comments on commit 730a92b

Please sign in to comment.