dolibarr/dev/build/generate_filelist_xml.php

273 lines
10 KiB
PHP
Raw Normal View History

Better Travis CI NEW: Cleaned up routines for better readability of both declaration and results. PHP versions now really covered. The old code forced install of PHP and didn't use Travis provided versions. This resulted in the process not being executed with the declared PHP version. Dropped MySQL in favor of MariaDB. This is now the FLOSS community standard. This should help avoid problems with buggy MySQL releases. Fast finish enabled to show results faster. Optimized tools installation with composer. The right version of the tool is installed for the PHP version under test. New PHP linter to check for syntax errors. Parallelized for better speed. Apache + PHP FPM for testing webservices. The previous mod_php configuration was not supported on Travis. New global DEBUG environment variable to show verbose output with configuration files content. IRC notification on #dolibarr@freenode for community awareness. FIXES: Bug in scripts preventing execution with environmentalized PHP. Wrong detection of MAIN_URL_ROOT under specific circumstances. $_SERVER["DOCUMENT_ROOT"] empty and $_SERVER["SCRIPT_NAME"] populated. Relative ignore directive in coding style ruleset to avoid bypassing test. Unit test errors without an exit status. This prevented the CI from properly detecting and reporting the error. TODOS: PostgreSQL support. This one is tricky since we only have a MySQL dump and the syntax is not directly compatible. SQLite support. Disabled in core at the moment. Nginx + PHP FPM support. Test webservices on the second most popular webserver. Run dev/* checks. We have a nice collection of scripts we could leverage. Check Javascript. Check CSS. Check SQL.
2015-12-11 05:08:32 +01:00
#!/usr/bin/env php
2015-02-21 09:44:03 +01:00
<?php
/* Copyright (C) 2015-2017 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
2015-02-24 12:44:12 +01:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-06-23 15:27:11 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2015-02-24 12:44:12 +01:00
*/
/**
* \file dev/build/generate_filelist_xml.php
2015-02-24 12:44:12 +01:00
* \ingroup dev
* \brief This script create a xml checksum file
*/
2023-12-04 10:16:54 +01:00
if (!defined('NOREQUIREDB')) {
2021-03-01 00:48:36 +01:00
define('NOREQUIREDB', '1'); // Do not create database handler $db
}
2018-06-05 18:21:56 +02:00
2015-02-24 12:44:12 +01:00
$sapi_type = php_sapi_name();
$script_file = basename(__FILE__);
2023-12-04 10:16:54 +01:00
$path = dirname(__FILE__).'/';
2015-02-24 12:44:12 +01:00
// Test if batch mode
if (substr($sapi_type, 0, 3) == 'cgi') {
2021-03-01 00:48:36 +01:00
echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
2024-07-06 17:53:24 +02:00
exit(1);
2015-02-24 12:44:12 +01:00
}
2018-07-26 11:57:25 +02:00
require_once $path."../htdocs/master.inc.php";
require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
2015-02-24 12:44:12 +01:00
/*
* Main
*/
2023-12-04 10:16:54 +01:00
$includecustom = 0;
$includeconstants = array();
$buildzip = 0;
2019-01-27 13:23:32 +01:00
if (empty($argv[1])) {
print "Usage: ".$script_file." release=autostable|auto[-mybuild]|x.y.z[-mybuild] [includecustom=1] [includeconstant=CC:MY_CONF_NAME:value] [buildzip=1]\n";
2021-03-01 00:48:36 +01:00
print "Example: ".$script_file." release=6.0.0 includecustom=1 includeconstant=FR:INVOICE_CAN_ALWAYS_BE_REMOVED:0 includeconstant=all:MAILING_NO_USING_PHPMAIL:1\n";
2024-07-06 17:44:20 +02:00
exit(1);
}
2021-03-02 00:48:02 +01:00
2023-12-04 10:16:54 +01:00
$i = 0;
2023-03-24 19:33:51 +01:00
$result = array();
2019-01-27 13:23:32 +01:00
while ($i < $argc) {
2022-08-31 22:14:20 +02:00
if (!empty($argv[$i])) {
2022-11-25 23:53:16 +01:00
parse_str($argv[$i], $result); // set all params $release, $includecustom, $includeconstant, $buildzip ...
2021-03-01 00:48:36 +01:00
}
2022-11-25 23:53:16 +01:00
if (!empty($result["release"])) {
$release = $result["release"];
}
if (!empty($result["includecustom"])) {
$includecustom = $result["includecustom"];
}
if (!empty($result["includeconstant"])) {
$includeconstants[$i] = $result["includeconstant"];
}
2023-02-28 17:55:09 +01:00
if (!empty($result["buildzip"])) {
2023-12-04 10:16:54 +01:00
$buildzip = 1;
2023-02-28 17:55:09 +01:00
}
2022-11-25 23:53:16 +01:00
if (preg_match('/includeconstant=/', strval($argv[$i]))) {
2023-12-04 10:16:54 +01:00
$tmp = explode(':', $result['includeconstant'], 3); // $includeconstant has been set with previous parse_str()
2021-03-01 00:48:36 +01:00
if (count($tmp) != 3) {
2022-11-25 23:53:16 +01:00
print "Error: Bad parameter includeconstant=".$result['includeconstant'] ."\n";
2021-03-01 00:48:36 +01:00
exit -1;
}
$includeconstants[$tmp[0]][$tmp[1]] = $tmp[2];
}
$i++;
}
2019-01-27 13:23:32 +01:00
if (empty($release)) {
2022-11-25 23:53:16 +01:00
print "Error: Missing release parameter\n";
2021-03-01 00:48:36 +01:00
print "Usage: ".$script_file." release=autostable|auto[-mybuild]|x.y.z[-mybuild] [includecustom=1] [includeconstant=CC:MY_CONF_NAME:value]\n";
2024-07-06 17:44:20 +02:00
exit(2);
}
$savrelease = $release;
2018-03-22 13:22:33 +01:00
// If release is auto, we take current version
2023-12-04 10:16:54 +01:00
$tmpver = explode('-', $release, 2);
2019-01-27 13:23:32 +01:00
if ($tmpver[0] == 'auto' || $tmpver[0] == 'autostable') {
2023-12-04 10:16:54 +01:00
$release = DOL_VERSION;
2021-03-01 00:48:36 +01:00
if ($tmpver[1] && $tmpver[0] == 'auto') {
2023-12-04 10:16:54 +01:00
$release .= '-'.$tmpver[1];
2021-03-01 00:48:36 +01:00
}
2018-03-22 13:22:33 +01:00
}
2019-01-27 13:23:32 +01:00
if (empty($includecustom)) {
2023-12-04 10:16:54 +01:00
$tmpverbis = explode('-', $release, 2);
2021-03-01 00:48:36 +01:00
if (empty($tmpverbis[1]) || $tmpver[0] == 'autostable') {
if (DOL_VERSION != $tmpverbis[0] && $savrelease != 'auto') {
print 'Error: When parameter "includecustom" is not set and there is no suffix in release parameter, version declared into filefunc.in.php ('.DOL_VERSION.') must be exact same value than "release" parameter ('.$tmpverbis[0].')'."\n";
print "Usage: ".$script_file." release=autostable|auto[-mybuild]|x.y.z[-mybuild] [includecustom=1] [includeconstant=CC:MY_CONF_NAME:value]\n";
2024-07-06 17:44:20 +02:00
exit(3);
2021-03-01 00:48:36 +01:00
}
} else {
2023-12-04 10:16:54 +01:00
$tmpverter = explode('-', DOL_VERSION, 2);
2021-03-01 00:48:36 +01:00
if ($tmpverter[0] != $tmpverbis[0]) {
print 'Error: When parameter "includecustom" is not set, version declared into filefunc.in.php ('.DOL_VERSION.') must have value without prefix ('.$tmpverter[0].') that is exact same value than "release" parameter ('.$tmpverbis[0].')'."\n";
print "Usage: ".$script_file." release=autostable|auto[-mybuild]|x.y.z[-mybuild] [includecustom=1] [includeconstant=CC:MY_CONF_NAME:value]\n";
2024-07-06 17:44:20 +02:00
exit(4);
2021-03-01 00:48:36 +01:00
}
}
2019-01-27 13:23:32 +01:00
} else {
2023-12-04 10:16:54 +01:00
if (!preg_match('/'.preg_quote(DOL_VERSION, '/').'-/', $release)) {
2021-03-01 00:48:36 +01:00
print 'Error: When parameter "includecustom" is set, version declared into filefunc.inc.php ('.DOL_VERSION.') must be used with a suffix into "release" parameter (ex: '.DOL_VERSION.'-mydistrib).'."\n";
print "Usage: ".$script_file." release=autostable|auto[-mybuild]|x.y.z[-mybuild] [includecustom=1] [includeconstant=CC:MY_CONF_NAME:value]\n";
2024-07-06 17:44:20 +02:00
exit(5);
2021-03-01 00:48:36 +01:00
}
}
2019-06-25 23:11:49 +02:00
print "Working on files into : ".DOL_DOCUMENT_ROOT."\n";
2021-02-02 13:44:54 +01:00
print "Release : ".$release."\n";
2017-06-10 01:17:48 +02:00
print "Include custom in signature : ".$includecustom."\n";
print "Include constants in signature : ";
2019-01-27 13:23:32 +01:00
foreach ($includeconstants as $countrycode => $tmp) {
2021-03-01 00:48:36 +01:00
foreach ($tmp as $constname => $constvalue) {
print $constname.'='.$constvalue." ";
}
}
print "\n";
2015-02-24 16:17:52 +01:00
//$outputfile=dirname(__FILE__).'/../htdocs/install/filelist-'.$release.'.xml';
2023-12-04 10:16:54 +01:00
$outputdir = dirname(dirname(__FILE__)).'/htdocs/install';
2021-08-19 02:51:24 +02:00
print 'Delete current files '.$outputdir.'/filelist*.xml*'."\n";
dol_delete_file($outputdir.'/filelist*.xml*', 0, 1, 1);
2023-12-04 10:16:54 +01:00
$checksumconcat = array();
2023-12-04 10:16:54 +01:00
$outputfile = $outputdir.'/filelist-'.$release.'.xml';
2019-01-27 13:23:32 +01:00
$fp = fopen($outputfile, 'w');
if (empty($fp)) {
print 'Failed to open file '.$outputfile."\n";
2024-07-06 17:44:20 +02:00
exit(6);
}
2015-02-21 09:44:03 +01:00
fputs($fp, '<?xml version="1.0" encoding="UTF-8" ?>'."\n");
2017-02-13 10:59:33 +01:00
fputs($fp, '<checksum_list version="'.$release.'" date="'.dol_print_date(dol_now(), 'dayhourrfc').'" generator="'.$script_file.'">'."\n");
2015-09-13 20:25:33 +02:00
2019-01-27 13:23:32 +01:00
foreach ($includeconstants as $countrycode => $tmp) {
2021-03-01 00:48:36 +01:00
fputs($fp, '<dolibarr_constants country="'.$countrycode.'">'."\n");
foreach ($tmp as $constname => $constvalue) {
2023-12-04 10:16:54 +01:00
$valueforchecksum = (empty($constvalue) ? '0' : $constvalue);
$checksumconcat[] = $valueforchecksum;
2021-03-01 00:48:36 +01:00
fputs($fp, ' <constant name="'.$constname.'">'.$valueforchecksum.'</constant>'."\n");
}
fputs($fp, '</dolibarr_constants>'."\n");
}
2015-09-13 20:25:33 +02:00
fputs($fp, '<dolibarr_htdocs_dir includecustom="'.$includecustom.'">'."\n");
2017-03-26 01:45:09 +01:00
/*$dir_iterator1 = new RecursiveDirectoryIterator(dirname(__FILE__).'/../htdocs/');
2015-09-13 20:25:33 +02:00
$iterator1 = new RecursiveIteratorIterator($dir_iterator1);
// Need to ignore document custom etc. Note: this also ignore natively symbolic links.
$files = new RegexIterator($iterator1, '#^(?:[A-Z]:)?(?:/(?!(?:'.($includecustom?'':'custom\/|').'documents\/|conf\/|install\/))[^/]+)+/[^/]+\.(?:php|css|html|js|json|tpl|jpg|png|gif|sql|lang)$#i');
2017-03-26 01:45:09 +01:00
*/
2021-05-10 14:33:26 +02:00
// Define qualified files (must be same than into generate_filelist_xml.php and in api_setup.class.php)
$regextoinclude = '\.(php|php3|php4|php5|phtml|phps|phar|inc|css|scss|html|xml|js|json|tpl|jpg|jpeg|png|gif|ico|sql|lang|txt|yml|bak|md|mp3|mp4|wav|mkv|z|gz|zip|rar|tar|less|svg|eot|woff|woff2|ttf|manifest)$';
2023-12-04 10:16:54 +01:00
$regextoexclude = '('.($includecustom ? '' : 'custom|').'documents|conf|install|dejavu-fonts-ttf-.*|public\/test|sabre\/sabre\/.*\/tests|Shared\/PCLZip|nusoap\/lib\/Mail|php\/example|php\/test|geoip\/sample.*\.php|ckeditor\/samples|ckeditor\/adapters)$'; // Exclude dirs
2017-03-26 01:45:09 +01:00
$files = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, $regextoinclude, $regextoexclude, 'fullname');
2021-02-20 11:09:23 +01:00
2023-12-04 10:16:54 +01:00
$dir = '';
$needtoclose = 0;
2017-03-26 01:45:09 +01:00
foreach ($files as $filetmp) {
2021-03-01 00:48:36 +01:00
$file = $filetmp['fullname'];
//$newdir = str_replace(dirname(__FILE__).'/../htdocs', '', dirname($file));
$newdir = str_replace(DOL_DOCUMENT_ROOT, '', dirname($file));
2023-12-04 10:16:54 +01:00
if ($newdir != $dir) {
2021-03-01 00:48:36 +01:00
if ($needtoclose) {
fputs($fp, ' </dir>'."\n");
}
fputs($fp, ' <dir name="'.$newdir.'">'."\n");
$dir = $newdir;
2023-12-04 10:16:54 +01:00
$needtoclose = 1;
2021-03-01 00:48:36 +01:00
}
2023-12-04 10:16:54 +01:00
if (filetype($file) == "file") {
$md5 = md5_file($file);
$checksumconcat[] = $md5;
2021-03-01 00:48:36 +01:00
fputs($fp, ' <md5file name="'.basename($file).'" size="'.filesize($file).'">'.$md5.'</md5file>'."\n");
}
2015-02-21 09:44:03 +01:00
}
fputs($fp, ' </dir>'."\n");
2015-09-13 20:25:33 +02:00
fputs($fp, '</dolibarr_htdocs_dir>'."\n");
asort($checksumconcat); // Sort list of checksum
fputs($fp, '<dolibarr_htdocs_dir_checksum>'."\n");
2019-01-27 13:23:32 +01:00
fputs($fp, md5(join(',', $checksumconcat))."\n");
fputs($fp, '</dolibarr_htdocs_dir_checksum>'."\n");
2023-12-04 10:16:54 +01:00
$checksumconcat = array();
2015-09-13 20:25:33 +02:00
fputs($fp, '<dolibarr_script_dir version="'.$release.'">'."\n");
// TODO Replace RecursiveDirectoryIterator with dol_dir_list
2017-03-26 01:45:09 +01:00
/*$dir_iterator2 = new RecursiveDirectoryIterator(dirname(__FILE__).'/../scripts/');
2015-09-13 20:25:33 +02:00
$iterator2 = new RecursiveIteratorIterator($dir_iterator2);
// Need to ignore document custom etc. Note: this also ignore natively symbolic links.
$files = new RegexIterator($iterator2, '#^(?:[A-Z]:)?(?:/(?!(?:custom|documents|conf|install))[^/]+)+/[^/]+\.(?:php|css|html|js|json|tpl|jpg|png|gif|sql|lang)$#i');
2017-03-26 01:45:09 +01:00
*/
2023-12-04 10:16:54 +01:00
$regextoinclude = '\.(php|css|html|js|json|tpl|jpg|png|gif|sql|lang)$';
$regextoexclude = '(custom|documents|conf|install)$'; // Exclude dirs
2017-03-26 01:45:09 +01:00
$files = dol_dir_list(dirname(__FILE__).'/../scripts/', 'files', 1, $regextoinclude, $regextoexclude, 'fullname');
2023-12-04 10:16:54 +01:00
$dir = '';
$needtoclose = 0;
2017-03-26 01:45:09 +01:00
foreach ($files as $filetmp) {
2021-03-01 00:48:36 +01:00
$file = $filetmp['fullname'];
//$newdir = str_replace(dirname(__FILE__).'/../scripts', '', dirname($file));
$newdir = str_replace(DOL_DOCUMENT_ROOT, '', dirname($file));
$newdir = str_replace(dirname(__FILE__).'/../scripts', '', dirname($file));
2023-12-04 10:16:54 +01:00
if ($newdir != $dir) {
2021-03-01 00:48:36 +01:00
if ($needtoclose) {
fputs($fp, ' </dir>'."\n");
}
fputs($fp, ' <dir name="'.$newdir.'" >'."\n");
$dir = $newdir;
2023-12-04 10:16:54 +01:00
$needtoclose = 1;
2021-03-01 00:48:36 +01:00
}
2023-12-04 10:16:54 +01:00
if (filetype($file) == "file") {
$md5 = md5_file($file);
$checksumconcat[] = $md5;
2021-03-01 00:48:36 +01:00
fputs($fp, ' <md5file name="'.basename($file).'" size="'.filesize($file).'">'.$md5.'</md5file>'."\n");
}
2015-09-13 20:25:33 +02:00
}
fputs($fp, ' </dir>'."\n");
2015-09-13 20:25:33 +02:00
fputs($fp, '</dolibarr_script_dir>'."\n");
asort($checksumconcat); // Sort list of checksum
fputs($fp, '<dolibarr_script_dir_checksum>'."\n");
2019-01-27 13:23:32 +01:00
fputs($fp, md5(join(',', $checksumconcat))."\n");
fputs($fp, '</dolibarr_script_dir_checksum>'."\n");
2015-09-13 20:25:33 +02:00
2015-02-21 09:44:03 +01:00
fputs($fp, '</checksum_list>'."\n");
fclose($fp);
2015-02-24 12:44:12 +01:00
if (empty($buildzip)) {
print "File ".$outputfile." generated\n";
} else {
2021-09-13 02:47:27 +02:00
if ($buildzip == '1' || $buildzip == 'zip') {
$result = dol_compress_file($outputfile, $outputfile.'.zip', 'zip');
if ($result > 0) {
dol_delete_file($outputfile);
print "File ".$outputfile.".zip generated\n";
}
} elseif ($buildzip == '2' || $buildzip == 'gz') {
$result = dol_compress_file($outputfile, $outputfile.'.gz', 'gz');
if ($result > 0) {
dol_delete_file($outputfile);
print "File ".$outputfile.".gz generated\n";
}
2021-08-19 02:54:58 +02:00
}
}
2015-02-24 12:44:12 +01:00
exit(0);