Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: deprecations in repair.php & Qual: Improve ... phpunit/setup_conf.sh #30825

Merged
merged 4 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 65 additions & 38 deletions dev/setup/phpunit/setup_conf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ PHP_OPT="-d error_reporting=32767"

DB=${DB:=mariadb}
DB_ROOT=${DB_ROOT:=root}
DB_PASS=${DB_PASS:=}
DB_PASSROOT=${DB_PASSROOT:=}
DB_USER=${DB_USER:=travis}
DB_PASS=${DB_PASS:=password}
DB_CACHE_FILE="${TRAVIS_BUILD_DIR}/db_init.sql"
DB_PREFIX="llx21_"

TRAVIS_DOC_ROOT_PHP="${TRAVIS_DOC_ROOT_PHP:=$TRAVIS_BUILD_DIR/htdocs}"
TRAVIS_DATA_ROOT_PHP="${TRAVIS_DATA_ROOT_PHP:=$TRAVIS_BUILD_DIR/documents}"
Expand All @@ -25,20 +28,24 @@ if [[ "$(uname -a)" =~ "MINGW"* ]] || [[ "$(uname -a)" =~ "CYGWIN"* ]] ; then
else
SUDO="sudo"
fi

CONF_FILE=${CONF_FILE:=${TRAVIS_BUILD_DIR}/htdocs/conf/conf.php}

function save_db_cache() (
set -x
rm "${DB_CACHE_FILE}".md5 2>/dev/null
echo "Saving DB to cache file '${DB_CACHE_FILE}'"
${SUDO} "${MYSQLDUMP}" -u "$DB_ROOT" -h 127.0.0.1 $PASS_OPT travis \
eval ${SUDO} "${MYSQLDUMP}" ${USERPASS_OPT} -h 127.0.0.1 travis \
--hex-blob --lock-tables=false --skip-add-locks \
| sed -e 's/DEFINER=[^ ]* / /' > ${DB_CACHE_FILE}
echo "${sum}" > "${DB_CACHE_FILE}".md5
set +x
)


if [ "${DB_USER}" = travis ] && [ -r "${CONF_FILE}" ] ; then
# Cleanup configuration file in ci
mv "${CONF_FILE}" "${CONF_FILE}.$(date +"%Y%m%d%H%M%S").bak"
fi

if [ -r "${CONF_FILE}" ] ; then
echo "'${CONF_FILE} exists, not overwriting!"

Expand All @@ -56,21 +63,29 @@ else
if [ "$DB" = 'mysql' ] || [ "$DB" = 'mariadb' ]; then
echo '$'dolibarr_main_db_type=\'mysqli\'';'
echo '$'dolibarr_main_db_port=3306';'
echo '$'dolibarr_main_db_user=\'travis\'';'
echo '$'dolibarr_main_db_pass=\'password\'';'
echo '$'"dolibarr_main_db_user='${DB_USER}'"';'
echo '$'"dolibarr_main_db_pass='${DB_PASS}'"';'
fi
if [ "$DB" = 'postgresql' ]; then
echo '$'dolibarr_main_db_type=\'pgsql\'';'
echo '$'dolibarr_main_db_port=5432';'
echo '$'dolibarr_main_db_user=\'postgres\'';'
echo '$'dolibarr_main_db_pass=\'postgres\'';'
fi
if [ "${DB_PREFIX}" != '' ]; then
echo '$'"dolibarr_main_db_prefix='${DB_PREFIX}'"';'
fi
echo '$'dolibarr_main_authentication=\'dolibarr\'';'
echo '$'force_install_createuser=true';'
echo '$'"dolibarr_main_db_collation='utf8_unicode_ci'"';'
} > "$CONF_FILE"
cat $CONF_FILE
echo
fi

# From here on, the DB_PREFIX can not be empty, set default value if empty
DB_PREFIX="${DB_PREFIX:=llx_}"

load_cache=0
echo "Setting up database '$DB'"
if [ "$DB" = 'mysql' ] || [ "$DB" = 'mariadb' ] || [ "$DB" = 'postgresql' ]; then
Expand All @@ -81,62 +96,62 @@ if [ "$DB" = 'mysql' ] || [ "$DB" = 'mariadb' ] || [ "$DB" = 'postgresql' ]; the
${SUDO} mysqld_safe --skip-grant-tables --socket=/tmp/aaa &
sleep 3
${SUDO} ps fauxww
if [ "${DB_PASS}" = "" ] ; then
PASS_OPT="-password="
PASS_OPT=""
if [ "${DB_PASSROOT}" = "" ] ; then
ROOTPASS_OPT="-u ${DB_ROOT}"
else
PASS_OPT="'-password=${DB_PASS}'"
ROOTPASS_OPT="-u ${DB_ROOT} --password='${DB_PASSROOT}'"
fi
USERPASS_OPT="-u ${DB_USER} --password=\"${DB_PASS}\""

echo "MySQL set root password"

if [ 1 = 1 ] ; then
CMDS=( \
""
"FLUSH PRIVILEGES; DROP DATABASE travis; CREATE DATABASE IF NOT EXISTS travis CHARACTER SET = 'utf8';"
"CREATE USER 'root'@'localhost' IDENTIFIED BY '$DB_PASS';"
"CREATE USER 'root'@'127.0.0.1' IDENTIFIED BY '$DB_PASS';"
"CREATE USER 'travis'@'localhost' IDENTIFIED BY 'password';"
"CREATE USER 'travis'@'127.0.0.1' IDENTIFIED BY 'password';"
"GRANT ALL PRIVILEGES ON travis.* TO root@localhost;"
"GRANT ALL PRIVILEGES ON travis.* TO root@127.0.0.1;"
"GRANT ALL PRIVILEGES ON travis.* TO travis@127.0.0.1;"
"GRANT ALL PRIVILEGES ON travis.* TO travis@localhost;"
"CREATE USER '${DB_ROOT}'@'localhost' IDENTIFIED BY '${DB_PASSROOT}';"
"CREATE USER '${DB_ROOT}'@'127.0.0.1' IDENTIFIED BY '${DB_PASSROOT}';"
"CREATE USER '${DB_USER}'@'localhost' IDENTIFIED BY '${DB_PASS}';"
"CREATE USER '${DB_USER}'@'127.0.0.1' IDENTIFIED BY '${DB_PASS}';"
"GRANT ALL PRIVILEGES ON travis.* TO ${DB_ROOT}@localhost;"
"GRANT ALL PRIVILEGES ON travis.* TO ${DB_ROOT}@127.0.0.1;"
"GRANT ALL PRIVILEGES ON travis.* TO ${DB_USER}@127.0.0.1;"
"GRANT ALL PRIVILEGES ON travis.* TO ${DB_USER}@localhost;"
"FLUSH PRIVILEGES;"
)
# Local, not changing root
for CMD in "${CMDS[@]}" ; do
${SUDO} "${MYSQL}" -u "$DB_ROOT" ${PASS_OPT} -h 127.0.0.1 -e "$CMD"
${SUDO} "${MYSQL}" ${ROOTPASS_OPT} -h 127.0.0.1 -e "$CMD"
done
else
DB_ROOT='root'
DB_PASS='password'
${SUDO} "${MYSQL}" -u "$DB_ROOT" -h 127.0.0.1 -e "FLUSH PRIVILEGES; CREATE DATABASE IF NOT EXISTS travis CHARACTER SET = 'utf8'; ALTER USER 'root'@'localhost' IDENTIFIED BY '$DB_PASS'; CREATE USER 'root'@'127.0.0.1' IDENTIFIED BY '$DB_PASS'; CREATE USER 'travis'@'127.0.0.1' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON travis.* TO [email protected]; GRANT ALL PRIVILEGES ON travis.* TO [email protected]; FLUSH PRIVILEGES;"
DB_PASSROOT='password'
ROOTPASS_OPT="-u ${DB_ROOT} '--password=${DB_PASSROOT}'"
${SUDO} "${MYSQL}" -u "${ROOTPASS_OPT}" -h 127.0.0.1 -e "FLUSH PRIVILEGES; CREATE DATABASE IF NOT EXISTS travis CHARACTER SET = 'utf8'; ALTER USER '${DB_ROOT}'@'localhost' IDENTIFIED BY '${DB_PASSROOT}'; CREATE USER '${DB_ROOT}'@'127.0.0.1' IDENTIFIED BY '${DB_PASSROOT}'; CREATE USER '${DB_USER}'@'127.0.0.1' IDENTIFIED BY '${DB_PASS}'; GRANT ALL PRIVILEGES ON travis.* TO '${DB_ROOT}@127.0.0.1; GRANT ALL PRIVILEGES ON travis.* TO '${DB_USER}'@127.0.0.1; FLUSH PRIVILEGES;"
fi
echo "MySQL grant"
${SUDO} "${MYSQL}" -u "$DB_ROOT" -h 127.0.0.1 $PASS_OPT -e 'FLUSH PRIVILEGES; GRANT ALL PRIVILEGES ON travis.* TO travis@127.0.0.1; FLUSH PRIVILEGES;'
${SUDO} "${MYSQL}" -u "$DB_ROOT" -h 127.0.0.1 $PASS_OPT -e 'FLUSH PRIVILEGES; GRANT ALL PRIVILEGES ON travis.* TO travis@localhost; FLUSH PRIVILEGES;'
${SUDO} "${MYSQL}" ${ROOTPASS_OPT} -h 127.0.0.1 -e "FLUSH PRIVILEGES; GRANT ALL PRIVILEGES ON travis.* TO ${DB_USER}@127.0.0.1; FLUSH PRIVILEGES;"
${SUDO} "${MYSQL}" ${ROOTPASS_OPT} -h 127.0.0.1 -e "FLUSH PRIVILEGES; GRANT ALL PRIVILEGES ON travis.* TO ${DB_USER}@localhost; FLUSH PRIVILEGES;"
echo "MySQL list current users"
${SUDO} "${MYSQL}" -u "$DB_ROOT" -h 127.0.0.1 $PASS_OPT -e 'use mysql; select * from user;'
${SUDO} "${MYSQL}" ${ROOTPASS_OPT} -h 127.0.0.1 -e 'use mysql; select * from user;'
echo "List pid file"
${SUDO} "${MYSQL}" -u "$DB_ROOT" -h 127.0.0.1 $PASS_OPT -e "show variables like '%pid%';"
${SUDO} "${MYSQL}" ${ROOTPASS_OPT} -h 127.0.0.1 -e "show variables like '%pid%';"

#sudo kill `cat /var/lib/mysqld/mysqld.pid`
#sudo systemctl start mariadb

echo "MySQL grant"
${SUDO} "${MYSQL}" -u "$DB_ROOT" -h 127.0.0.1 $PASS_OPT -e 'GRANT ALL PRIVILEGES ON travis.* TO travis@127.0.0.1;'
${SUDO} "${MYSQL}" ${ROOTPASS_OPT} -h 127.0.0.1 -e "GRANT ALL PRIVILEGES ON travis.* TO ${DB_USER}@127.0.0.1;"
echo "MySQL flush"
${SUDO} "${MYSQL}" -u "$DB_ROOT" -h 127.0.0.1 $PASS_OPT -e 'FLUSH PRIVILEGES;'
${SUDO} "${MYSQL}" ${ROOTPASS_OPT} -h 127.0.0.1 -e 'FLUSH PRIVILEGES;'

sum=$(find "${TRAVIS_BUILD_DIR}/htdocs/install" -type f -exec md5sum {} + | LC_ALL=C sort | md5sum)
cnt=$(find "${TRAVIS_BUILD_DIR}/htdocs/install" -type f -exec md5sum {} + | wc)
echo "OLDSUM $sum COUNT:$cnt"

# Compute md5 based on install file contents, and on db prefix
# shellcheck disable=2046
sum=$(md5sum $(find "${TRAVIS_BUILD_DIR}/htdocs/install" -type f) | LC_ALL=C sort | md5sum)
sum=$(md5sum $(find "${TRAVIS_BUILD_DIR}/htdocs/install" -type f) | { LC_ALL=C sort ; echo "$DB_PREFIX" ;} | md5sum)
# shellcheck disable=2046
cnt=$(md5sum $(find "${TRAVIS_BUILD_DIR}/htdocs/install" -type f) | wc)
echo "NEWSUM $sum COUNT:$cnt"
echo "MD5SUM $sum COUNT:$cnt"
load_cache=0
if [ -r "$DB_CACHE_FILE".md5 ] && [ -r "$DB_CACHE_FILE" ] && [ -x "$(which "${MYSQLDUMP}")" ] ; then
cache_sum="$(<"$DB_CACHE_FILE".md5)"
Expand All @@ -145,10 +160,10 @@ if [ "$DB" = 'mysql' ] || [ "$DB" = 'mariadb' ] || [ "$DB" = 'postgresql' ]; the

if [ "$load_cache" = "1" ] ; then
echo "MySQL load cached sql"
${SUDO} "${MYSQL}" --force -u "$DB_ROOT" -h 127.0.0.1 $PASS_OPT -D travis < ${DB_CACHE_FILE} | tee $TRAVIS_BUILD_DIR/db_from_cacheinit.log
eval ${SUDO} "${MYSQL}" --force ${USERPASS_OPT} -h 127.0.0.1 -D travis < ${DB_CACHE_FILE} | tee $TRAVIS_BUILD_DIR/db_from_cacheinit.log
else
echo "MySQL load initial sql"
${SUDO} "${MYSQL}" --force -u "$DB_ROOT" -h 127.0.0.1 $PASS_OPT -D travis < ${TRAVIS_BUILD_DIR}/dev/initdemo/mysqldump_dolibarr_3.5.0.sql | tee $TRAVIS_BUILD_DIR/initial_350.log
sed 's/\([ `]\)llx_/\1'"${DB_PREFIX}/g" < "${TRAVIS_BUILD_DIR}/dev/initdemo/mysqldump_dolibarr_3.5.0.sql" | eval ${SUDO} "${MYSQL}" --force ${USERPASS_OPT} -h 127.0.0.1 -D travis | tee $TRAVIS_BUILD_DIR/initial_350.log
fi
elif [ "$DB" = 'postgresql' ]; then
echo Install pgsql if run is for pgsql
Expand Down Expand Up @@ -191,9 +206,13 @@ set +e
fi
echo '$'force_install_dbserver=\'127.0.0.1\'';'
echo '$'force_install_database=\'travis\'';'
echo '$'force_install_databaselogin=\'travis\'';'
echo '$'force_install_databasepass=\'\'';'
echo '$'force_install_prefix=\'llx_\'';'
echo '$'"force_install_databaselogin='${DB_USER}'"';'
echo '$'"force_install_databasepass='${DB_PASS}'"';'
if [ "${DB_PREFIX}" != '' ] ; then
echo '$'"force_install_prefix='${DB_PREFIX}'"';'
fi
#echo '$'"force_install_dolibarrlogin='admin'"';'
#echo '$'force_install_createuser=true';'
} > "$INSTALL_FORCED_FILE"

if [ "$load_cache" != "1" ] ; then
Expand All @@ -215,8 +234,16 @@ if [ "$load_cache" != "1" ] ; then
pVer="$v"
done

${SUDO} "${MYSQL}" --force -u "$DB_ROOT" -h 127.0.0.1 $PASS_OPT -D travis < "${TRAVIS_BUILD_DIR}/htdocs/install/mysql/migration/repair.sql"
sed "s/ llx_/ ${DB_PREFIX}/g" <"${TRAVIS_BUILD_DIR}/htdocs/install/mysql/migration/repair.sql" | eval ${SUDO} "${MYSQL}" --force ${USERPASS_OPT} -h 127.0.0.1 -D travis

# Apply repair options:
# Excluded options: force_utf8_on_tables force_utf8mb4_on_tables rebuild_sequences ; do
PHP_REPAIR_OPT=""
for opt in force_disable_of_modules_not_found restore_thirdparties_logos restore_user_pictures rebuild_product_thumbs clean_linked_elements clean_menus clean_orphelin_dir clean_product_stock_batch clean_perm_table repair_link_d set_empty_time_spent_amount force_collation_from_conf_on_tables ; do
PHP_REPAIR_OPT="$PHP_REPAIR_OPT\$_POST['$opt'] = '1';"
done
LOGNAME="${TRAVIS_BUILD_DIR}/repair${pVer//./}${v//./}"
"${PHP}" $PHP_OPT -r "$PHP_REPAIR_OPT; include 'repair.php';" > ${LOGNAME}.log

{
"${PHP}" $PHP_OPT upgrade2.php 0.0.0 0.0.0 MAIN_MODULE_API,MAIN_MODULE_ProductBatch,MAIN_MODULE_SupplierProposal,MAIN_MODULE_STRIPE,MAIN_MODULE_ExpenseReport
Expand Down
4 changes: 2 additions & 2 deletions htdocs/install/repair.php
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@
$name=preg_replace('/\'/','',$name);
*/

$tmp = explode('.', $obj->logo);
$tmp = explode('.', (string) $obj->logo);
$name = $tmp[0];
if (isset($tmp[1])) {
$ext = '.'.$tmp[1];
Expand Down Expand Up @@ -593,7 +593,7 @@
$name=preg_replace('/\'/','',$name);
*/

$tmp = explode('.', $obj->photo);
$tmp = explode('.', (string) $obj->photo);
$name = $tmp[0];
if (isset($tmp[1])) {
$ext = '.'.$tmp[1];
Expand Down
Loading