Add support for direct certificate download via justDownload
Introduced functionality to handle `justDownload` parameter, allowing direct retrieval of certificate download URLs for a given booking ID. Updated comments and made minor adjustments to file cleanup logic by disabling certificate deletion.
This commit is contained in:
@@ -4,14 +4,16 @@
|
||||
* The reason behind this being outside the WordPress plugin is that the PHPExcel library is not compatible with the WordPress plugin, and it is easier to maintain the generator here.
|
||||
*/
|
||||
|
||||
use classes\wash_certificate_store;
|
||||
|
||||
// Load the config file
|
||||
require_once '../../config.php';
|
||||
require_once '../../vendor/autoload.php';
|
||||
/** Load the relevant classes */
|
||||
require_once '../../interfaces/minio_wash_certificates_i.php';
|
||||
require_once '../../traits/minio_t.php';
|
||||
require_once '../../classes/wash_certificate_store.php';
|
||||
|
||||
use classes\wash_certificate_store;
|
||||
|
||||
global $WORDPRESS_STATIC_TOKEN;
|
||||
// Validate the token was loaded from the config file
|
||||
if (!isset($WORDPRESS_STATIC_TOKEN) || $WORDPRESS_STATIC_TOKEN === '') {
|
||||
@@ -61,6 +63,21 @@ if ($_GET['secret_token'] !== $WORDPRESS_STATIC_TOKEN) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Check if the $_GET variable justDownload is set
|
||||
if (isset($_GET['justDownload'])) {
|
||||
// Require the $_GET variable bookingId to be set
|
||||
if (!isset($_GET['bookingId'])) {
|
||||
echo 'Missing required fields';
|
||||
exit;
|
||||
}
|
||||
// Usage example
|
||||
$wash_certificate_store = new wash_certificate_store();
|
||||
// Return the certificate download URL
|
||||
echo $wash_certificate_store->getWashCertificateDownload($_GET['bookingId']);
|
||||
// Exit the script
|
||||
exit;
|
||||
}
|
||||
|
||||
// Require the $_GET variables sealOrPlumber, safetySeal, performedBy, and bookingId, regNumber, and regNumberTrailer to be set
|
||||
if (!isset($_GET['sealOrPlumber']) || !isset($_GET['performedBy']) || !isset($_GET['bookingId']) || !isset($_GET['regNumber']) || !isset($_GET['regNumberTrailer']) || !isset($_GET['department'])) {
|
||||
// We are missing some required fields in the query string
|
||||
@@ -82,7 +99,7 @@ if ($wash_certificate_store->washCertificateExists($_GET['bookingId'])) {
|
||||
$success = $wash_certificate_store->uploadFile("wash_certificate_" . $_GET['bookingId'] . ".pdf", dirname(__FILE__) . "/output/certificates/wash_certificate_" . $_GET['bookingId'] . ".pdf");
|
||||
// If the certificate was uploaded successfully, delete the local copy
|
||||
if ($success) {
|
||||
unlink(dirname(__FILE__) . "/output/certificates/wash_certificate_" . $_GET['bookingId'] . ".pdf");
|
||||
//unlink(dirname(__FILE__) . "/output/certificates/wash_certificate_" . $_GET['bookingId'] . ".pdf");
|
||||
// Return the certificate url
|
||||
echo $wash_certificate_store->getWashCertificateDownload($_GET['bookingId']);
|
||||
exit;
|
||||
@@ -109,7 +126,7 @@ $generatedCertificatePath = "output/certificates/wash_certificate_" . $_GET['boo
|
||||
$wash_certificate_store->uploadFile($generatedCertificateName, dirname(__FILE__) . '/' . $generatedCertificatePath);
|
||||
|
||||
// Delete the local copy of the certificate
|
||||
unlink(dirname(__FILE__) . '/' . $generatedCertificatePath);
|
||||
//unlink(dirname(__FILE__) . '/' . $generatedCertificatePath);
|
||||
|
||||
// Return the generated certificate object download URL
|
||||
$wash_certificate_store->getWashCertificateDownload($_GET['bookingId']);
|
||||
|
||||
Reference in New Issue
Block a user