From f3e32ec43aa3b54a111383bdfdb80c8a5b3d011e Mon Sep 17 00:00:00 2001 From: Adam Daley Date: Sat, 21 Mar 2026 08:24:41 +0000 Subject: [PATCH] Move and update paths for Invoice PDF templates (#3355) * Move invoice PDF templates and update paths * Migrate Invoice PDF templates to new location * Bump `last_patch` to 51 in install SQL --- src/install/sql/content.sql | 2 +- src/library/FOSSBilling/UpdatePatcher.php | 25 ++++++++++++++++--- src/modules/Invoice/Service.php | 14 +++++------ .../pdf/default-invoice.css} | 2 +- .../pdf/default-invoice.twig} | 0 5 files changed, 31 insertions(+), 12 deletions(-) rename src/modules/Invoice/{pdf_template/default-pdf.css => templates/pdf/default-invoice.css} (94%) rename src/modules/Invoice/{pdf_template/default-pdf.twig => templates/pdf/default-invoice.twig} (100%) diff --git a/src/install/sql/content.sql b/src/install/sql/content.sql index 432e94e3e..302e2ca5b 100644 --- a/src/install/sql/content.sql +++ b/src/install/sql/content.sql @@ -310,7 +310,7 @@ LOCK TABLES `setting` WRITE; INSERT INTO `setting` (`id`, `param`, `value`, `public`, `category`, `hash`, `created_at`, `updated_at`) VALUES - (1,'last_patch','50',0,NULL,NULL,'2024-12-30 12:00:00','2024-12-30 12:00:00'), + (1,'last_patch','51',0,NULL,NULL,'2024-12-30 12:00:00','2024-12-30 12:00:00'), (2,'company_name','Company Name',0,NULL,NULL,'2022-12-01 12:00:00','2022-12-01 12:00:00'), (3,'company_email','support@yourcompany.com',0,NULL,NULL,'2022-12-01 12:00:00','2022-12-01 12:00:00'), (4,'company_signature','FOSSBilling.org - Client Management, Invoicing and Support Software',0,NULL,NULL,'2022-12-01 12:00:00','2022-12-01 12:00:00'), diff --git a/src/library/FOSSBilling/UpdatePatcher.php b/src/library/FOSSBilling/UpdatePatcher.php index a6687940c..ab54999c8 100644 --- a/src/library/FOSSBilling/UpdatePatcher.php +++ b/src/library/FOSSBilling/UpdatePatcher.php @@ -14,6 +14,7 @@ namespace FOSSBilling; use Symfony\Component\Filesystem\Exception\IOException; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Path; +use Symfony\Component\Finder\Finder; use Symfony\Component\Uid\Uuid; class UpdatePatcher implements InjectionAwareInterface @@ -654,9 +655,6 @@ class UpdatePatcher implements InjectionAwareInterface } }, 49 => function (): void { - // Patch to update logo and favicon paths from assets/ to assets/build/ for huraga theme - // This is needed because the esbuild migration moved assets to a build directory - // @see https://github.com/FOSSBilling/FOSSBilling/pull/XXXX $q = "UPDATE setting SET value = 'themes/huraga/assets/build/img/logo.svg' WHERE param = 'company_logo' AND value = 'themes/huraga/assets/img/logo.svg';"; $this->executeSql($q); @@ -672,6 +670,27 @@ class UpdatePatcher implements InjectionAwareInterface 'meta_key' => 'config', ]); }, + 51 => function (): void { + $oldDir = Path::join(PATH_MODS, 'Invoice', 'pdf_template'); + $newDir = Path::join(PATH_MODS, 'Invoice', 'templates', 'pdf'); + + if (!$this->filesystem->exists($oldDir)) { + return; + } + + $fileActions = [ + Path::join($oldDir, 'custom-pdf.twig') => Path::join($newDir, 'custom-invoice.twig'), + Path::join($oldDir, 'custom-pdf.css') => Path::join($newDir, 'custom-invoice.css'), + Path::join($oldDir, 'default-pdf.twig') => 'unlink', + Path::join($oldDir, 'default-pdf.css') => 'unlink', + ]; + $this->executeFileActions($fileActions); + + $finder = new Finder(); + if (!$finder->in($oldDir)->depth('== 0')->hasResults()) { + $this->filesystem->remove($oldDir); + } + }, ]; ksort($patches, SORT_NATURAL); diff --git a/src/modules/Invoice/Service.php b/src/modules/Invoice/Service.php index 258f8666d..04670e3e6 100644 --- a/src/modules/Invoice/Service.php +++ b/src/modules/Invoice/Service.php @@ -1351,7 +1351,7 @@ class Service implements InjectionAwareInterface 'invoice' => $invoice, ]; - $loader = new FilesystemLoader(Path::join(__DIR__, 'pdf_template')); + $loader = new FilesystemLoader(Path::join(__DIR__, 'templates', 'pdf')); $twig = $this->di['twig']; $twig->setLoader($loader); $html = $twig->render($this->getPdfTemplate(), $vars); @@ -1592,9 +1592,9 @@ class Service implements InjectionAwareInterface // Start of PDF related functions private function getPdfCss(): string { - $basePath = Path::join(__DIR__, 'pdf_template'); - $customCssPath = Path::join($basePath, 'custom-pdf.css'); - $defaultCssPath = Path::join($basePath, 'default-pdf.css'); + $basePath = Path::join(__DIR__, 'templates', 'pdf'); + $customCssPath = Path::join($basePath, 'custom-invoice.css'); + $defaultCssPath = Path::join($basePath, 'default-invoice.css'); if ($this->filesystem->exists($customCssPath)) { $CSS = $this->filesystem->readFile($customCssPath); @@ -1611,11 +1611,11 @@ class Service implements InjectionAwareInterface private function getPdfTemplate(): string { - if ($this->filesystem->exists(Path::join(__DIR__, 'pdf_template', 'custom-pdf.twig'))) { - return 'custom-pdf.twig'; + if ($this->filesystem->exists(Path::join(__DIR__, 'templates', 'pdf', 'custom-invoice.twig'))) { + return 'custom-invoice.twig'; } - return 'default-pdf.twig'; + return 'default-invoice.twig'; } private function getPdfLogoSource(string $originalUrl): array diff --git a/src/modules/Invoice/pdf_template/default-pdf.css b/src/modules/Invoice/templates/pdf/default-invoice.css similarity index 94% rename from src/modules/Invoice/pdf_template/default-pdf.css rename to src/modules/Invoice/templates/pdf/default-invoice.css index a9182526d..97fdfeff4 100644 --- a/src/modules/Invoice/pdf_template/default-pdf.css +++ b/src/modules/Invoice/templates/pdf/default-invoice.css @@ -1,6 +1,6 @@ /** * This file contains the default CSS used for the PDF generator. - * You can copy and rename this file to 'custom-pdf.css' and customize the CSS as you wish. + * You can copy and rename this file to 'custom-invoice.css' and customize the CSS as you wish. * The file will be loaded and inserted into the