mirror of
https://github.com/phpbb/phpbb.git
synced 2025-04-21 08:12:17 +02:00
[ticket/16543] Add script for automate it on builds
PHPBB3-16543
This commit is contained in:
parent
39b3db9e27
commit
bc869f8ec3
54
build/patch_stylesheet_cache_busters.php
Normal file
54
build/patch_stylesheet_cache_busters.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
if (php_sapi_name() !== 'cli')
|
||||
{
|
||||
die("This program must be run from the command line.\n");
|
||||
}
|
||||
|
||||
if (version_compare(PHP_VERSION, '7.1.3', '<'))
|
||||
{
|
||||
die('patch_stylesheet_cache_busters.php requires at least PHP 7.1.3');
|
||||
}
|
||||
|
||||
// Usage: "$ php build/patch_stylesheet_cache_busters.php"
|
||||
$targets = [dirname(dirname(__FILE__)) . '/phpBB/styles/prosilver/theme/stylesheet.css'];
|
||||
|
||||
array_map('patch_glob', $targets);
|
||||
|
||||
function patch_glob($glob): void
|
||||
{
|
||||
array_map('patch_file', glob($glob));
|
||||
}
|
||||
|
||||
function patch_file(string $filepath): void
|
||||
{
|
||||
$file = file_get_contents($filepath);
|
||||
$old = $file;
|
||||
$new = preg_replace_callback(
|
||||
'(^@import\\s+url\\([\'"](?<basename>\\w++\\.css)\\?\\K(?:hash|v)=[^\'"]++)m',
|
||||
function ($m) use ($filepath)
|
||||
{
|
||||
$path = dirname($filepath) . DIRECTORY_SEPARATOR . $m['basename'];
|
||||
$hash = sprintf('%08x', crc32(file_get_contents($path)));
|
||||
|
||||
return 'hash=' . $hash;
|
||||
},
|
||||
$old
|
||||
);
|
||||
|
||||
if ($new !== $old)
|
||||
{
|
||||
file_put_contents($filepath, $new);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user