Ed,
I figured out how to fix the function to work with both file and MultipleFile fields in grids.
Edit
workflow/engine/classes/class.pmFunctions.php, and change the definition of
PMFAssociateUploadedFilesWithInputFile() (which starts on line 3493 in version 3.2.3) to:
Code: Select allfunction PMFAssociateUploadedFilesWithInputFile($inputDocumentUid, $gridVariableName, $fileVariableName, $caseUid, $userUid, $currentDelIndex)
{
try {
require_once 'classes/model/AppDocument.php';
$appDocument = new AppDocument();
//First step: get all the documents from this case and this grid that are not associated
$criteria = new Criteria('workflow');
$criteria->add(AppDocumentPeer::APP_UID, $caseUid, Criteria::EQUAL);
$criteria->add(AppDocumentPeer::APP_DOC_TYPE, 'ATTACHED', Criteria::EQUAL);
//doesn't work for MultipleFile fields:
//$criteria->add(AppDocumentPeer::APP_DOC_FIELDNAME, $gridVariableName . '_%_' . $fileVariableName, Criteria::LIKE);
//ABB edit: Find both file and multipleFile fields in grids:
$criteria->add(
$criteria->getNewCriterion(AppDocumentPeer::APP_DOC_FIELDNAME, $gridVariableName .'\_%\_'. $fileVariableName, Criteria::LIKE)->addOr(
$criteria->getNewCriterion(AppDocumentPeer::APP_DOC_FIELDNAME, "[$gridVariableName][%][$fileVariableName]", Criteria::LIKE)
)
);
//ABB edit end
$criteria->add(AppDocumentPeer::APP_DOC_STATUS, 'ACTIVE', Criteria::EQUAL);
$criteria->add(AppDocumentPeer::DOC_UID, '-1', Criteria::EQUAL);
$criteria->addAscendingOrderByColumn(AppDocumentPeer::APP_DOC_INDEX);
$numRecTotal = AppDocumentPeer::doCount($criteria);
//If we have an error in the result set, do not continue
if ($numRecTotal == 0) {
//Return
return false;
}
//ABB edit: Get the Input Document's folder UID (and create it if necessary):
require_once 'classes/model/InputDocument.php';
require_once 'classes/model/AppFolder.php';
$oInpDoc = new InputDocument();
$oFolder = new AppFolder();
$aInpDocInfo = $oInpDoc->load($inputDocumentUid);
$folderUid = $oFolder->createFromPath( $aInpDocInfo["INP_DOC_DESTINATION_PATH"] );
//ABB edit end
//Query
$rsCriteria = AppDocumentPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
//Search file in the process, associate with the Input document
while ($rsCriteria->next()) {
$row = $rsCriteria->getRow();
//Load the file by its unique identifier, its name, its extension and the path where it's stored
$file = $appDocument->load($row['APP_DOC_UID']);
$ext = pathinfo($file['APP_DOC_FILENAME'], PATHINFO_EXTENSION);
$fileName = $file['APP_DOC_UID'] . '_' . $file['DOC_VERSION'] . '.' . $ext;
$pathFile = PATH_DOCUMENT . G::getPathFromUID($caseUid) . PATH_SEP . $fileName;
$comment = $file['APP_DOC_COMMENT']; //ABB edit
//Delete this file so it can't be uploaded again (Includes Mark Database Record)
$appDocument->remove($file['APP_DOC_UID'], $file['DOC_VERSION']);
$fields = array (
'APP_UID' => $caseUid,
'DEL_INDEX' => $currentDelIndex,
'USR_UID' => $userUid,
'DOC_UID' => $inputDocumentUid,
'APP_DOC_TYPE' => 'INPUT',
'APP_DOC_CREATE_DATE' => date('Y-m-d H:i:s'),
'APP_DOC_COMMENT' => $comment,
'APP_DOC_TITLE' => $file['APP_DOC_TITLE'],
'APP_DOC_FILENAME' => $file['APP_DOC_FILENAME'],
'APP_DOC_FIELDNAME' => '',
'FOLDER_UID' => $folderUid //ABB edit
);
$result = $appDocument->create($fields);
//Copy the file
$appUid = $appDocument->getAppUid();
$appDocUid = $appDocument->getAppDocUid();
$docVersion = $appDocument->getDocVersion();
$info = pathinfo( $appDocument->getAppDocFilename() );
$extAux = (isset( $info['extension'] )) ? $info['extension'] : '';
//Save the file
$pathName = PATH_DOCUMENT . G::getPathFromUID($appUid) . PATH_SEP;
$pathFileName = $appDocUid . '_' . $docVersion . '.' . $extAux;
copy($pathFile, $pathName . $pathFileName);
//Update
$result = $appDocument->update([
'APP_DOC_UID' => $appDocUid,
'DOC_VERSION' => $docVersion,
'APP_DOC_TAGS' => 'INPUT',
'APP_DOC_FIELDNAME' => $file['APP_DOC_FIELDNAME']
]);
//Remove the old submitted file completely from file system
unlink($pathFile);
}
} catch (Exception $e) {
throw $e;
}
}