Skip to content

Commit

Permalink
Merge pull request #4596 from LibreSign/hotfix/prevent-call-other-aut…
Browse files Browse the repository at this point in the history
…oload-before-libresign

hotfix: prevent call other autoload before libresign
  • Loading branch information
vitormattos authored Feb 3, 2025
2 parents feb2c50 + 30ad99c commit f8f91c6
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/Handler/FooterHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function getFooter(File $file, FileEntity $fileEntity): string {

$htmlFooter = $this->getRenderedHtmlFooter();
$metadata = $this->getMetadata();
$this->loadLibreSignFirst();
foreach ($metadata['d'] as $dimension) {
if (!isset($pdf)) {
$pdf = new Mpdf([
Expand Down Expand Up @@ -85,6 +86,30 @@ public function getFooter(File $file, FileEntity $fileEntity): string {
return $pdf->Output('', 'S');
}

private function loadLibreSignFirst(): void {
$loaders = \Composer\Autoload\ClassLoader::getRegisteredLoaders();
$systemConfig = \OC::$server->getSystemConfig();
$appsPaths = $systemConfig->getValue('apps_paths');
if (empty($appsPaths)) {
return;
}
foreach ($appsPaths as $path) {
$paths[] = $path['path'];
}
foreach ($loaders as $loader) {
$reflection = new \ReflectionClass($loader);
$propriedade = $reflection->getProperty('vendorDir');
$propriedade->setAccessible(true);
$vendorDir = $propriedade->getValue($loader);
foreach ($paths as $path) {
if (str_starts_with($vendorDir, $path) && !str_contains($vendorDir, 'libresign')) {
$loader->unregister();
$loader->register();
}
}
}
}

private function getMetadata(): array {
$metadata = $this->fileEntity->getMetadata();
if (!is_array($metadata) || !isset($metadata['d'])) {
Expand Down

0 comments on commit f8f91c6

Please sign in to comment.