Hello everyone,
Is there an easy way to change from overwriting generated documents to a mode where the existing files are kept for good and new files are saved with consecutive version numbers?
I’ve tried and search for answers on different plattforms. Please forgive me if the answer is already written somewhere.
As I understood, if a PDF is generated (Invoice, Purchase Order, …) this (one many?) path is taken:
include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
-> $obj->generateDocument
-> CommonObject::commonGenerateDocument
-> $obj->write_file
If the call comes from a custom module the method is defined at core/modules/MyModuleName/doc/pdf_MyModuleName_ReportName.modules.php
and member of ‘class pdf_MyModuleName_ReportName extends CommonDocGenerator’
public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
is where the PDF is designed and written to file.
By default (what the module builder creates) the name of the file is defined here
$objectref = dol_sanitizeFileName($object->ref);
$dir = $conf->lims->dir_output."/".$objectref;
$file = $dir."/".$objectref.".pdf";
and could be later changed by hook beforePDFCreation
After object $pdf has been prepared, this will finally write the document:
$pdf->Close();
$pdf->Output($file, ‘F’);
As I understand, $file could be manipulated so that the file doesn’t get constantly overwritten.
For example the original (1st generated file) has name FancyReport_0010.pdf
, the next time the report is generated using FancyReport_0001-1.pdf
.
How do other people solve a versioning of reports? Is there a better way?
Thanks!!