Return with error code if precompile_smarty fails

The Smarty API for compiling templates don't return any meaningful error
status if a template fails, so we buffer the output and scan it for
error messages instead. If we find one, we return a non-zero error code
to signal the error to the shell or calling process.

Also added more detailed copyright headers.
This commit is contained in:
Harald Eilertsen
2025-10-10 22:22:39 +02:00
parent 3cdfa94c29
commit ea0229dcfc

View File

@@ -1,8 +1,13 @@
<?php <?php
/* Utility script to compile all smarty templates
/** *
* @package util * SPDX-FileCopyrightText: 2013, 2025 The Hubzilla Community
*/ * SPDX-FileContributor: fabrixxm <fabrix.xm@gmail.com>
* SPDX-FileContributor: Mario <mario@mariovavti.com>
* SPDX-FileContributor: Harald Eilertsen <haraldei@anduin.net>
*
* SPDX-License-Identifier: MIT
*/
require_once dirname(__DIR__) . '/boot.php'; require_once dirname(__DIR__) . '/boot.php';
@@ -16,7 +21,16 @@ $s->setCompileDir(TEMPLATE_BUILD_PATH . '/compiled/');
$s->setConfigDir(TEMPLATE_BUILD_PATH . '/config/'); $s->setConfigDir(TEMPLATE_BUILD_PATH . '/config/');
$s->setCacheDir(TEMPLATE_BUILD_PATH . '/cache/'); $s->setCacheDir(TEMPLATE_BUILD_PATH . '/cache/');
$s->left_delimiter = '{{'; $s->setLeftDelimiter('{{');
$s->right_delimiter = '}}'; $s->setRightDelimiter('}}');
// Capture the output...
ob_start();
$s->compileAllTemplates('.tpl', true); $s->compileAllTemplates('.tpl', true);
$buf = ob_get_flush();
// ...so that we can check if there was any errors
if (strpos($buf, '------>Error: ') !== false) {
// Signal to the shell if there was
exit(-1);
}