Handling file creation on the cloud

Hi,

we face an issue with a piece of customisation we wrote some time ago that is not working anymore on the cloud. We have a logic hook that works on Opportunities. When the opportunity reaches a certain state we create a PDF file add it to a new note and link that note to the specified opportunity. After that a mail is being send out where all the attachments that are attached to the related notes is attached on the mail that is being sent out. 

The code for generating the PDF is like this. As you can see we are using the blacklisted functions file_put_contents and copy to do some magic. Is there another way of doing this which is cloud ready??

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
global $sugar_config;
AcuityLog::log("OppMails", "Building Note for PDF Opportunitity {$bean->id}");
//save the email as pdf
require_once('custom/include/customPDF.php');
AcuityLog::log("OppMails", "Building PDF");
// create new PDF document
//$bean, $sugarpdf_object_map, $orientation, $unit, $format, $unicode, $encoding, $diskcache
$pdf = new MYPDF($bean, array(), PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetHeaderMargin(5);
$pdf->SetFooterMargin(65);
$pdf->setMargins(15, 45, 15);
$pdf->SetFont('helvetica', '', 11);
$pdf->SetAutoPageBreak(TRUE, 65);
$pdf->AddPage();
$pdf->setPage($pdf->getPage());
$pdf->writeHTML($processedFileContent_pdf, true, false, true, false, '');
//clear buffer first
//Close and output PDF document
$name = $subject_pdf.".pdf";
$tmp = $pdf->Output($name, 'S');
file_put_contents('upload://'.$name, ltrim($tmp));
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • This is pretty simple:

    Fullscreen
    1
    2
    3
    4
    5
    $imageFile = 'upload://' . $note_id;
    $fh = new UploadStream();
    $fh->stream_open($imageFile, 'w');
    $fh->stream_write($data);
    $fh->stream_close();
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Cheers

    André Lopes
    Lampada Global
    Skype: andre.lampada