Forum


Replies: 5   Views: 2862
Merging documents at same time as another mixes output
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by cem  · 15-06-2017 - 18:13

Hi,

We have version 7 Premium edition.  Right now I'm trying to merge many templates together and it works fine if I am the only one using it.  However, once someone else tries to run the documents, our info gets mixed up and merged into the output.  I have tested and confirmed this happens.

For example, if I'm running invoices for one customer, and another employee is running it for a different customer, the output has the two different customers filled in the variables if we are literally running at the same exact time. 

I believe it's because of the temp files.  There seems to be only one path and if we both run it, we overwrite each others temp files.  Is there any way to change this behavior?  A different method of merging and producing output?  A way for createDocx() to add something unique and only merge those set of docs? 

We do have sessions, so maybe I can use each person's session to create a path and overwrite whatever is the default path (which also seems random as it's not taking my set temp_path)?  But then every employee will need their own path.  If that is what we must do, I can set that up, but hoping there is a known solution or alternative method for merging.

Here's a sample code, this is the basics of what I'm running. 

// using in-memory temp files

require_once '../../../classes/CreateDocx.inc';

// array of the DOCX to be merged
$doc_arr = array();

$variables = array(
    'field1' => 'test text',
    'field2' => 'more test text'
);

// first DOCX
$docx = new CreateDocxFromTemplate('file1.docx');
$docx->setTemplateSymbol('^');
$docx->replaceVariableByText($variables);
$docx->createDocx('output_1.docx');

array_push($doc_arr, 'output_1.docx');

// second DOCX
$docx = new CreateDocxFromTemplate('file2.docx');
$docx->setTemplateSymbol('^');
$docx->replaceVariableByText($variables);
$docx->createDocx('output_2.docx');

array_push($doc_arr, 'output_2.docx');

// third DOCX
$docx = new CreateDocxFromTemplate('file3.docx');
$docx->setTemplateSymbol('^');
$docx->replaceVariableByText($variables);
$docx->createDocx('output_3.docx');

array_push($doc_arr, 'output_3.docx');

$merge = new MultiMerge();
$merge->mergeDocx('coversheet.docx', $doc_arr, 'output_merged_1.docx', array());