User Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
en:devel:updateimagefield [2019/03/21 23:23]
joebordes
en:devel:updateimagefield [2019/03/21 23:53] (current)
joebordes
Line 30: Line 30:
 </​code>​ </​code>​
  
-Now, if you need to do this from inside a workflow task you could run into a loop because vtws_revise will actually launch the workflows again. In this case I suppose that the best thing to do is copy the update code from web service ​and call save_entity instead of save:+Now, if you need to do this from inside a workflow task you could run into a loop because vtws_revise will actually launch the workflows again. In this case setup the environment for a direct file upload ​and call **insertIntoAttachment** like this:
  
 <code PHP> <code PHP>
-global $adb+require_once '​include/​tcpdf/​tcpdf_barcodes_2d.php'​
-$module='Assets'; +require_once ​'include/​tcpdf/​tcpdf_barcodes_1d.php'; 
-$ids vtws_getIdComponents($assetData['id']); +$barcodeobj ​new TCPDF2DBarcode('http://​www.tcpdf.org',​ '​QRCODE,​H'); 
-$meta = new VtigerCRMObjectMeta($module$current_user); +//$barcodeobj ​= new TCPDFBarcode('​http://​www.tcpdf.org'​'​bar_codes'​); 
-$element ​DataTransform::​sanitizeForInsert($assetData$meta); + 
-$crmObject = new VtigerCRMObject(getTabid($module)true); +// export as PNG image 
-$crmObject->​setObjectId($ids[1])+$data = $barcodeobj->​getBarcodePngData(33, array(0,128,0)); 
-$cfields ​= $crmObject->​getFields()+$attachment_name = '​BARCODEname.png'​
-$cfields = DataTransform::​sanitizeRetrieveEntityInfo($cfields, $meta); +$filepath ​= $root_directory.'​cache/'​.$attachment_name
-$element ​array_merge($cfields$assetData);​ +file_put_contents($filepath, $data); 
-$error = false; +$_FILES['​cf_1114'​] ​array( 
-foreach ($assetData as $k => $v{ + '​name'​ => $attachment_name
- $crmObject->​instance->​column_fields[$k] ​$v; + '​type'​ => '​image/​png',​ 
-} + '​tmp_name'​ => $filepath, 
-$adb->startTransaction()+ 'error' ​=> 0, 
-$crmObject->​instance->mode = '​edit';​ + '​size' ​=> strlen($data)
-$crmObject->instance->​save_entity($module)+); 
-$error = $adb->hasFailedTransaction(); +$CRMEntity::​getInstance('​Assets'​)
-$adb->completeTransaction(); +$a->id = 4062
-// control ​$error+$a->mode = '​edit';​ 
 +$a->DirectImageFieldValues['​cf_1114'​] = $attachment_name// this is to delete previous image with the same name 
 +$a->retrieve_entity_info(4062, '​Assets'​); 
 +$a->insertIntoAttachment(4062, '​Assets'​); 
 +unlink($filepath);
 </​code>​ </​code>​