Skip to content

Commit

Permalink
Merge pull request #515 from DiamondLightSource/prerelease
Browse files Browse the repository at this point in the history
Prerelease
  • Loading branch information
John-Holt-Tessella authored Mar 31, 2023
2 parents fd1ce45 + a8b92df commit 08138f1
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 74 deletions.
6 changes: 3 additions & 3 deletions api/src/Page/PDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ function __construct(Slim $app, $db, $user)
// Creating the temp folder here means we have the correct permissions
// Using separate folders for temp and font data so mpdf does not try to delete ttfontdata
global $pdf_tmp_dir;
$this->pdf_tmp_dir = $pdf_tmp_dir;
$mpdf_temp = $pdf_tmp_dir . "/mpdf/temp/";
$mpdf_font_data = $pdf_tmp_dir . "/mpdf/ttfontdata/";
$this->pdf_tmp_dir = $pdf_tmp_dir ? $pdf_tmp_dir : "/tmp";
$mpdf_temp = $this->pdf_tmp_dir . "/mpdf/temp/";
$mpdf_font_data = $this->pdf_tmp_dir . "/mpdf/ttfontdata/";

if (!is_dir($mpdf_temp)) {
mkdir($mpdf_temp, 0775, true);
Expand Down
138 changes: 67 additions & 71 deletions api/src/Page/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -1049,92 +1049,88 @@ function _dispatch_dewar()
// Case insensitive search
if (stripos($dewar_location, 'ebic') !== false) {
$dispatch_from_location = 'eBIC';
}

// Update dewar transport history with provided location.
$this->db->pq(
"INSERT INTO dewartransporthistory (dewartransporthistoryid,dewarid,dewarstatus,storagelocation,arrivaldate)
VALUES (s_dewartransporthistory.nextval,:1,'dispatch-requested',:2,CURRENT_TIMESTAMP)
RETURNING dewartransporthistoryid INTO :id",
array($dew['DEWARID'], $dewar_location)
);
// Update dewar transport history with provided location.
$this->db->pq(
"INSERT INTO dewartransporthistory (dewartransporthistoryid,dewarid,dewarstatus,storagelocation,arrivaldate)
VALUES (s_dewartransporthistory.nextval,:1,'dispatch-requested',:2,CURRENT_TIMESTAMP)
RETURNING dewartransporthistoryid INTO :id",
array($dew['DEWARID'], $dewar_location)
);

$data = $this->args;
$data = $this->args;

if (Utils::getValueOrDefault($use_shipping_service) && in_array($country, $facility_courier_countries)) {
$terms = $this->db->pq(
"SELECT cta.couriertermsacceptedid FROM couriertermsaccepted cta WHERE cta.shippingid=:1",
array($dew['SHIPPINGID'])
);
$terms_accepted = sizeof($terms) ? true : false;
if ($terms_accepted) {
try {
$shipment_id = $this->_dispatch_dewar_in_shipping_service($data, $dew);
if (Utils::getValueOrDefault($shipping_service_links_in_emails)) {
$data['AWBURL'] = $this->shipping_service->get_awb_pdf_url($shipment_id);
}
} catch (Exception $e) {
error_log($e);
$data['AWBURL'] = "";
if (Utils::getValueOrDefault($use_shipping_service) && in_array($country, $facility_courier_countries)) {
$terms = $this->db->pq(
"SELECT cta.couriertermsacceptedid FROM couriertermsaccepted cta WHERE cta.shippingid=:1",
array($dew['SHIPPINGID'])
);
$terms_accepted = sizeof($terms) ? true : false;
if ($terms_accepted) {
try {
$shipment_id = $this->_dispatch_dewar_in_shipping_service($data, $dew);
if (Utils::getValueOrDefault($shipping_service_links_in_emails)) {
$data['AWBURL'] = $this->shipping_service->get_awb_pdf_url($shipment_id);
}
} catch (Exception $e) {
error_log($e);
$data['AWBURL'] = "";
}
}
}

# Prepare e-mail response for dispatch request
$subject_line = '*** Dispatch requested for Dewar ' . $dew['BARCODE'] . ' from ' . $dispatch_from_location . ' - Pickup Date: ' . $this->args['DELIVERYAGENT_SHIPPINGDATE'] . ' ***';
$email = new Email('dewar-dispatch', $subject_line);

// If a local contact is given, try to find their email address
// First try LDAP, if unsuccessful look at the ISPyB person record for a matching staff user
$local_contact = $this->has_arg('LOCALCONTACT') ? $this->args['LOCALCONTACT'] : '';
if ($local_contact) {
$this->args['LCEMAIL'] = $this->_get_email_fn($local_contact);
if (!$this->args['LCEMAIL']) {
$this->args['LCEMAIL'] = $this->_get_ispyb_email_fn($local_contact);
}
}
# Prepare e-mail response for dispatch request
$subject_line = '*** Dispatch requested for Dewar ' . $dew['BARCODE'] . ' from ' . $dispatch_from_location . ' - Pickup Date: ' . $this->args['DELIVERYAGENT_SHIPPINGDATE'] . ' ***';
$email = new Email('dewar-dispatch', $subject_line);

if (!array_key_exists('FACILITYCODE', $data))
$data['FACILITYCODE'] = '';
if (!array_key_exists('AWBNUMBER', $data))
$data['AWBNUMBER'] = '';
if (!array_key_exists('DELIVERYAGENT_AGENTNAME', $data))
$data['DELIVERYAGENT_AGENTNAME'] = '';
if (!array_key_exists('DELIVERYAGENT_AGENTCODE', $data))
$data['DELIVERYAGENT_AGENTCODE'] = '';
if (!array_key_exists('LOCATION', $data))
$data['LOCATION'] = $dewar_location;
if (!array_key_exists('LOCALCONTACT', $data))
$data['LOCALCONTACT'] = $local_contact;
if (!array_key_exists('LCEMAIL', $data))
$data['LCEMAIL'] = '';
$data['ADDRESS'] = $data['ADDRESS'] . PHP_EOL . $country;
$email->data = $data;

if ($country != $facility_country && !is_null($dispatch_email_intl)) {
$recpts = $dispatch_email_intl;
} else {
$recpts = $dispatch_email;
// If a local contact is given, try to find their email address
// First try LDAP, if unsuccessful look at the ISPyB person record for a matching staff user
$local_contact = $this->has_arg('LOCALCONTACT') ? $this->args['LOCALCONTACT'] : '';
if ($local_contact) {
$this->args['LCEMAIL'] = $this->_get_email_fn($local_contact);
if (!$this->args['LCEMAIL']) {
$this->args['LCEMAIL'] = $this->_get_ispyb_email_fn($local_contact);
}
}

$recpts .= ', ' . $this->arg('EMAILADDRESS');
$local_contact_email = $this->has_arg('LCEMAIL') ? $this->args['LCEMAIL'] : '';
if ($local_contact_email) $recpts .= ', ' . $local_contact_email;

$email->send($recpts);

// Also update the dewar status and storage location to keep it in sync with history...
$this->db->pq(
"UPDATE dewar
set dewarstatus='dispatch-requested', storagelocation=lower(:2)
WHERE dewarid=:1",
array($dew['DEWARID'], $dewar_location)
);
if (!array_key_exists('FACILITYCODE', $data))
$data['FACILITYCODE'] = '';
if (!array_key_exists('AWBNUMBER', $data))
$data['AWBNUMBER'] = '';
if (!array_key_exists('DELIVERYAGENT_AGENTNAME', $data))
$data['DELIVERYAGENT_AGENTNAME'] = '';
if (!array_key_exists('DELIVERYAGENT_AGENTCODE', $data))
$data['DELIVERYAGENT_AGENTCODE'] = '';
if (!array_key_exists('LOCATION', $data))
$data['LOCATION'] = $dewar_location;
if (!array_key_exists('LOCALCONTACT', $data))
$data['LOCALCONTACT'] = $local_contact;
if (!array_key_exists('LCEMAIL', $data))
$data['LCEMAIL'] = '';
$data['ADDRESS'] = $data['ADDRESS'] . PHP_EOL . $country;
$email->data = $data;

$this->_output(1);
if ($country != $facility_country && !is_null($dispatch_email_intl)) {
$recpts = $dispatch_email_intl;
} else {
$recpts = $dispatch_email;
}

$recpts .= ', ' . $this->arg('EMAILADDRESS');
$local_contact_email = $this->has_arg('LCEMAIL') ? $this->args['LCEMAIL'] : '';
if ($local_contact_email) $recpts .= ', ' . $local_contact_email;

$email->send($recpts);

// Also update the dewar status and storage location to keep it in sync with history...
$this->db->pq(
"UPDATE dewar
set dewarstatus='dispatch-requested', storagelocation=lower(:2)
WHERE dewarid=:1",
array($dew['DEWARID'], $dewar_location)
);

$this->_output(1);
}

Expand Down

0 comments on commit 08138f1

Please sign in to comment.