Skip to content

Commit

Permalink
Merge pull request #327 from OPUS4/4.7.2
Browse files Browse the repository at this point in the history
Release 4.8 (formerly planned as 4.7.2)
  • Loading branch information
j3nsch authored Apr 24, 2023
2 parents 9f65280 + 18c898b commit 5b55129
Show file tree
Hide file tree
Showing 128 changed files with 988 additions and 2,877 deletions.
28 changes: 20 additions & 8 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: PHP Composer
name: Testing

on:
push:
Expand All @@ -12,15 +12,24 @@ on:
jobs:
build:

runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

strategy:
matrix:
php-versions: ['7.1', '8.1']

name: PHP ${{ matrix.php-versions }} Test

steps:
- uses: actions/checkout@v3

- name: Setup PHP 7.1
- name: Setup PHP ${{ matrix.php-versions }}
uses: shivammathur/setup-php@v2
with:
php-version: '7.1'
php-version: ${{ matrix.php-versions }}

- name: Check PHP Version
run: php -v

- name: Update Ubuntu packages
run: sudo apt-get update
Expand All @@ -31,13 +40,16 @@ jobs:
- name: Start MySQL
run: sudo systemctl start mysql.service

- name: Prepare workspace
run: ant prepare-workspace

- name: Prepare database
run: bash bin/prepare-database.sh --admin_pwd root --user_pwd root
run: bash bin/opus4db --sqlpwd root --adminpwd root --userpwd root

- name: Setup OPUS 4
run: ant prepare-workspace prepare-config create-database lint -DdbUserPassword=root -DdbAdminPassword=root
- name: Check PHP files
run: ant lint

- name: Test
- name: Tests
run: php composer.phar test

- name: Coding-Style
Expand Down
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ db/config.sh
vendor

# Local test files
tests/build
tests/config.ini
tests/config.ini.backup
database.ini*
.phpunit.result.cache

# IntelliJ IDEA files
.idea
Expand Down
14 changes: 7 additions & 7 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,17 @@ $composer = <<SCRIPT
SCRIPT

$database = <<SCRIPT
/vagrant/bin/prepare-database.sh
/vagrant/bin/opus4db
SCRIPT

$init_schema = <<SCRIPT
php db/createdb.php
SCRIPT

$prepare_tests = <<SCRIPT
cd /vagrant
ant prepare-workspace
# TODO currently the admin account is always used for tests
if test ! -f tests/config.ini; then
ant prepare-config -DdbUserName=opus4admin -DdbUserPassword=opusadminpwd -DdbAdminName=opus4admin -DdbAdminPassword=opusadminpwd
fi
bin/composer update
php db/createdb.php
SCRIPT

$environment = <<SCRIPT
Expand All @@ -68,8 +67,9 @@ Vagrant.configure("2") do |config|

config.vm.provision "Install required software...", type: "shell", inline: $software
config.vm.provision "Install Composer...", type: "shell", privileged: false, inline: $composer
config.vm.provision "Setup database...", type: "shell", inline: $database
config.vm.provision "Prepare tests...", type: "shell", privileged: false, inline: $prepare_tests
config.vm.provision "Setup database...", type: "shell", inline: $database
config.vm.provision "Init database...", type: "shell", privileged: false, inline: $init_schema
config.vm.provision "Setup environment...", type: "shell", inline: $environment
config.vm.provision "Help", type: "shell", privileged: false, inline: $help
end
5 changes: 1 addition & 4 deletions bin/install-composer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# @author Thomas Urban <[email protected]>
# @author Jens Schwidder <[email protected]>
# @copyright Copyright (c) 2010-2016, OPUS 4 development team
# @copyright Copyright (c) 2010, OPUS 4 development team
# @license http://www.gnu.org/licenses/gpl.html General Public License

#
Expand All @@ -29,7 +27,6 @@

set -e

SCRIPT_NAME="$(basename "$0")"
SCRIPT_NAME_FULL="`readlink -f "$0"`"
SCRIPT_PATH="`dirname "$SCRIPT_NAME_FULL"`"

Expand Down
226 changes: 226 additions & 0 deletions bin/opus4db
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
#!/usr/bin/env bash

# This file is part of OPUS. The software OPUS has been originally developed
# at the University of Stuttgart with funding from the German Research Net,
# the Federal Department of Higher Education and Research and the Ministry
# of Science, Research and the Arts of the State of Baden-Wuerttemberg.
#
# OPUS 4 is a complete rewrite of the original OPUS software and was developed
# by the Stuttgart University Library, the Library Service Center
# Baden-Wuerttemberg, the Cooperative Library Network Berlin-Brandenburg,
# the Saarland University and State Library, the Saxon State Library -
# Dresden State and University Library, the Bielefeld University Library and
# the University Library of Hamburg University of Technology with funding from
# the German Research Foundation and the European Regional Development Fund.
#
# LICENCE
# OPUS 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 2 of the Licence, or any later version.
# OPUS 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
# along with OPUS; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# @copyright Copyright (c) 2022, OPUS 4 development team
# @license http://www.gnu.org/licenses/gpl.html General Public License

#
# Script to set up an OPUS 4 database and database users with optional
# parameters to provide custom database user names & passwords and/or a
# custom database name. If no optional parameters are given, default values
# will be used.
#
# IMPORTANT: This script is also used by other OPUS 4 packages that require
# a database for testing.
#
# TODO merge with setup.sh (get rid of setup.sh or remove redundancy)
#

script_home="$(dirname "$0")"
script_path="`readlink -f "$0"`"
script_name="$(basename "$0")"

if [[ "$script_home" == *"/vendor/"* ]]; then
# Framework used as dependency in other Composer project
application_path="$(dirname $(dirname $(dirname $(dirname "$script_home"))))"
framework_path="$(dirname "$script_home")"
else
# Script used in Framework project
application_path="$(dirname $(dirname "$script_path"))"
framework_path=$application_path
fi

# Full path to configuration file
config_file="$application_path/database.ini"

# Define variables and their default values
sqluser='root'
admin="${OPUS4_DEV_DB_ADMIN:-opus4admin}"
adminpwd="${OPUS4_DEV_DB_ADMIN_PWD:-opusadminpwd}"
user="${OPUS4_DEV_DB_USER:-opus4}"
userpwd="${OPUS4_DEV_DB_USER_PWD:-opususerpwd}"
dbname='opusdb'
host='localhost'
port='3306'
mysql='mysql'

initEnabled=0
createEnabled=0
configEnabled=0

# Print command line help to stderr
displayHelp() {
DEFAULT='\033[0;33m' # Purple color for default values
OPTION='\033[1;32m' # Green
NC='\033[0m' # No Color

echo "Usage: $script_name [OPTIONS]" >&2
echo
echo -e "The script will ask for the SQL root password interactively, unless it is"
echo -e "specified using option ${OPTION}--sqlpwd${NC}. Using this option will automatically enable"
echo -e "${OPTION}--init${NC}, ${OPTION}--config${NC} and ${OPTION}--database${NC}. This is used for testing on GitHub and for"
echo -e "setting up Vagrant-VMs."
echo
echo "Options:"
echo
echo -e " ${OPTION}--help${NC} (${OPTION}-h${NC}) Print out help"
echo -e " ${OPTION}--init${NC} (${OPTION}-i${NC}) Initialize database schema"
echo -e " ${OPTION}--config${NC} (${OPTION}-c${NC}) Write config (database.ini)"
echo -e " ${OPTION}--database${NC} (${OPTION}-d${NC}) Create database"
echo
echo -e " DEFAULT"
echo -e " ${OPTION}--sqluser${NC} SQL root user (${DEFAULT}$sqluser${NC})"
echo -e " ${OPTION}--sqlpwd${NC} SQL root password"
echo -e " ${OPTION}--admin${NC} Admin name (${DEFAULT}$admin${NC})"
echo -e " ${OPTION}--adminpwd${NC} Admin password (${DEFAULT}$adminpwd${NC})"
echo -e " ${OPTION}--user${NC} User name (${DEFAULT}$user${NC})"
echo -e " ${OPTION}--userpwd${NC} User password (${DEFAULT}$userpwd${NC})"
echo -e " ${OPTION}--dbname${NC} Database name (${DEFAULT}$dbname${NC})"
echo -e " ${OPTION}--host${NC} MySQL host (${DEFAULT}$host${NC})"
echo -e " ${OPTION}--port${NC} MySQL port (${DEFAULT}$port${NC})"
echo -e " ${OPTION}--mysql${NC} MySQL client (${DEFAULT}$mysql${NC})"
echo
echo "Examples:"
echo
echo -e " $script_name"
echo -e " $script_name ${OPTION}--help"${NC}
echo -e " $script_name ${OPTION}--adminpwd${NC} ${DEFAULT}ADMINPWD${NC} ${OPTION}--userpwd${NC} ${DEFAULT}USERPWD${NC}"
echo -e " $script_name ${OPTION}-i --dbname${NC} ${DEFAULT}opusdbtest${NC}"
echo
exit 1
}

# Display command line help if '-h' or '--help' is given as first option
if [ $# -gt 0 ]; then
if [[ $1 == "-h" || $1 == "--help" ]]; then
displayHelp
exit 0
fi
fi

# Parse any other command line options
while [ $# -gt 0 ]; do
if [[ $1 == "--"* ]]; then # only deal with long options
if [[ -n "$2" && $2 != "-"* ]]; then # ignore options without a value
# Create variable name from option name
v="${1/--/}" # uses parameter expansion removing '--'

# Read option value into variable
declare "$v"="$2"

# Process next option
shift
else
v="${1/--/}"
case $v in
"init") initEnabled=1;;
"config") configEnabled=1;;
"database") createEnabled=1;;
esac
fi
else
case $1 in
"-i") initEnabled=1;;
"-c") configEnabled=1;;
"-d") createEnabled=1;;
esac
fi
shift
done

# if SQL root password is set as parameter enable all steps TODO perhaps changes this later
if [[ $sqlpwd ]]; then
initEnabled=1
configEnabled=1
createEnabled=1
fi

createDatabase()
{
# Querying MySQL root password
[[ -z $sqlpwd ]] && read -p "MySQL root user password: " -s sqlpwd

sql=$(cat <<-ENDSTRING
CREATE DATABASE IF NOT EXISTS $dbname DEFAULT CHARACTER SET = UTF8 DEFAULT COLLATE = UTF8_GENERAL_CI;
CREATE USER IF NOT EXISTS '$admin'@'localhost' IDENTIFIED WITH mysql_native_password BY '${adminpwd}';
GRANT ALL PRIVILEGES ON $dbname.* TO '$admin'@'localhost';
CREATE USER IF NOT EXISTS '$user'@'localhost' IDENTIFIED WITH mysql_native_password BY '$userpwd';
GRANT SELECT,INSERT,UPDATE,DELETE ON $dbname.* TO '$user'@'localhost';
FLUSH PRIVILEGES;
ENDSTRING
)

export MYSQL_PWD=$sqlpwd && mysql --default-character-set=utf8 -h $host -P $port -u $sqluser -v -e "$sql"
}

createConfigFile()
{
cat <<EOF >$config_file
; Database connection parameters for running unit tests.
[production]
db.params.host = '$host'
db.params.port = '$port'
; TODO use regular OPUS user account for tests
db.params.username = '$admin'
db.params.password = '$adminpwd'
db.params.dbname = '$dbname'
; TODO resolve need to specify credentials twice (unless regular user is used above)
opusdb.params.admin.name = '$admin'
opusdb.params.admin.password = '$adminpwd'
[testing : production]
EOF
}

initSchema()
{
export APPLICATION_PATH=$application_path && php "$framework_path/db/createdb.php"
}

if [[ $createEnabled == 0 && $configEnabled == 0 && $initEnabled == 0 ]]; then
displayHelp
exit 0
fi

if [[ $createEnabled == "1" ]]; then
echo "Create database ..."
createDatabase
fi

if [[ $configEnabled == "1" ]]; then
echo "Create config file ..."
createConfigFile
fi

if [[ $initEnabled == "1" ]]; then
# requires database and config file
echo "Initialize database schema ..."
initSchema
fi

Loading

0 comments on commit 5b55129

Please sign in to comment.