Skip to content
This repository has been archived by the owner on Oct 14, 2023. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
fbraem committed Dec 23, 2021
2 parents 63254b8 + 675fcfc commit 049d3a1
Show file tree
Hide file tree
Showing 835 changed files with 29,348 additions and 20,186 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
*.key
/docs/
/.phpunit.result.cache
kwai.development.yaml
/.vagrant
/.*.cache
/vendor/
/config/config.acc.php
/config/config.php
/config/config.production.php
/hosts.*.yml
184 changes: 181 additions & 3 deletions .idea/inspectionProfiles/Project_Default.xml

Large diffs are not rendered by default.

264 changes: 131 additions & 133 deletions .idea/kwai-api.iml

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions .idea/markdown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 2 additions & 9 deletions .idea/php-test-framework.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

405 changes: 276 additions & 129 deletions .idea/php.xml

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions .idea/phpunit.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/webResources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014 tribbie
Copyright (c) 2021 Franky Braem

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
162 changes: 97 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
Kwai-api
========

Kwai-api is a part of the kwai system. The ultimate goal of Kwai is to manage a (sports)club. The focus is currently on judo sport (Kwai means club in Japanese), but in the future it may be possible to support
other sports.
Kwai-api is part of the kwai system. The ultimate goal of Kwai is to manage a
(sports)club. The focus is currently on judo sport (Kwai means club in
Japanese), but in the future it may be possible to support other sports.

The frontend of kwai can be found in the [kwai-ui](https://github.com/fbraem/kwai-ui) repository.
The frontend of kwai can be found in the
[kwai-vite](https://github.com/fbraem/kwai-vite) repository.

> Kwai is a greenfield project. As long as there is no official release,
> everything can change. Although there is still a lot to do, kwai is already used in production for
> our club but that is no guarantee that it will work for you...
> everything can change. Although there is still a lot to do, kwai is already
> used in production for our club but that is no guarantee that it will work
> for you...
[Jetbrains](https://www.jetbrains.com/?from=kwai-api) allows Kwai-api to use phpstorm for development!
[Jetbrains](https://www.jetbrains.com/?from=kwai-api) allows Kwai-api to use
phpstorm for development!

<img alt="jetbrains" src="jetbrains.png" width="200px" />
<img alt="jetbrains" src="jetbrains.png" width="150px" />

API
===
Kwai-api is the REST api for Kwai. It's written in PHP and it tries to follow the [JSONAPI](http://jsonapi.org) standard.
Kwai-api is the REST api for Kwai. It's written in PHP.
The [JSONAPI](http://jsonapi.org) standard is followed as best as
possible. A separate PHP module [kwai/jsonapi](https://github.com/fbraem/kwai-jsonapi)
is written for this.

Currently the following api's are already available:

- news
- pages
- members
- teams
- trainings

TODO
Expand All @@ -32,73 +37,100 @@ TODO
There is still a lot to do:

- tournament management
- teams
- member follow-up system
- events
- ...

Kwai is currently more CRUD then domain oriented. This api must evolve from an anemic model to real DDD.

Installation
============
Clone this repository. There are two ways of installing kwai-api: using
Deployer or do a manual install.

Deployer
--------

> To be able to deploy on a (shared) host SSH must be setup. The article
> ["Deploying a Symfony application with Deployer"](https://dev.to/andersbjorkland/deploying-a-symfony-application-with-deployer-afe)
> can help.
Install [deployer](https://deployer.org/) (version 6.x)
and create a deployer configuration file. The `hosts.yml` file can be used as an
example. This file can look like this:

````yaml
kwai:
stage: production
user:
deploy_path: ~/{{application}}_pro
public_path: /www
http_user:
````

`application` contains the value 'kwai_api'.

Run deployer from the folder where hosts.yml is located:

````shell
dep deploy production
````

When the deploy is successful, the deploy_path will contain a `shared` and a
`releases` folder and a symbolic link `current`. The symbolic link will point
to the latest deployed application code. The shared folder contains folders
and files that will be shared between different releases. In this folder the
config folder is used to store `config.php`. Use `config.dist.php` to create
a config.php for this installation.

In the public_path, the api php entry files will be copied into the api folder.
These files will be overwritten on each deploy. In the public path an autoload
PHP script will be created. This autoload script will load the
vendor/autoload.php file.

The database migration is currently not executed after a deploy. When a
migration is needed, go to the src folder in the current folder of the
deploy_path on the (shared) host and run it manually:

````shell
../vendor/bin/phinx migrate -c ./phinx.php
````

Manual
------
The recommended way of installing kwai-api is using deployer, but it is also
possible to install it manually.

Run `composer install` in the folder where the repository is cloned. Copy all
folders api, src, config and vendor to the host. Rename the config.dist.php
file in the config folder into config.php and change the configuration.

To run a migration of the database, you need access to your host and run it
manually from the src folder on the host:

````shell
../vendor/bin/phinx migrate -c ./phinx.php
````

Development
============

Clone this repository in a folder. The easiest way to setup a development
environment is to use [vagrant](https://www.vagrantup.com/).

Clone this repository and run `composer install` in the `src` as current directory. When all goes well, create a `config.php` in the `api` directory. This PHP file must return an array with some configuration:

return [
'database' => [
'development' => [
'adapter' => 'mysql',
'host' => '',
'user' => '',
'pass' => '',
'name' => '',
'charset' => 'utf8',
'prefix' => ''
]
],
'default_database' => 'development',
'files' => '',
'oauth2' => [
'private_key' => 'file:///',
'public_key' => 'file:///',
'encryption_key' => '',
'client' => [
'name' => '',
'identifier' => '',
'secret' => '',
'redirect' => ''
]
],
'mail' => [
'host' => '',
'user' => '',
'pass' => '',
'port' => 2525,
'from' => [ ],
'subject' => ''
],
'website' => [
'url' => '',
'email' => ''
]
];

Create a public and private key as explained on [league/oauth2-server](https://oauth2.thephpleague.com/installation/).

When the configuration is finished, run the database migrations from the `src` directory:

./vendor/bin/phinx migrate -c phinx.php

On shared hosting:

php ./vendor/robmorgan/phinx/phinx.php migrate -c phinx.php
Copy `kwai.dist.yaml` to `kwai.development.yaml` and fill in the properties.
Run `vagrant up` from the repository folder and everything will be
installed automatically.

Running Tests
=============

A testing environment is easily set up with [vagrant](https://www.vagrantup.com).
Kwai uses [pest](https://pestphp.com/) to run tests:

vagrant up
vagrant ssh KWAI_API
cd /vagrant/src
./vendor/bin/pest
cd /vagrant
./vendor/bin/pest -c ./tests/phpunit.xml

Credits
=======
+ [PHPStorm](https://www.jetbrains.com/phpstorm/?from=kwai-api)
65 changes: 50 additions & 15 deletions Vagrant.provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,50 +36,85 @@ VIRTUAL_HOST=$(cat <<EOF
</VirtualHost>
EOF
)
echo "${VIRTUAL_HOST}" > /etc/apache2/sites-enabled/000-default.conf
echo "${VIRTUAL_HOST}" > /etc/apache2/sites-available/kwai.conf

# MySQL
debconf-set-selections <<< "mysql-server mysql-server/root_password password $KWAI_DATABASE_PASSWORD"
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $KWAI_DATABASE_PASSWORD"
apt-get install -y mysql-server
mysql -uroot -p$KWAI_DATABASE_PASSWORD -e "CREATE DATABASE $KWAI_DATABASE_NAME"
mysql -uroot -p$KWAI_DATABASE_PASSWORD -e "grant all privileges on $KWAI_DATABASE_NAME.* to '$KWAI_DATABASE_USER'@'%' identified by '$KWAI_DATABASE_PASSWORD'"
mysql -uroot -p"$KWAI_DATABASE_PASSWORD" -e "CREATE DATABASE $KWAI_DATABASE_NAME"
mysql -uroot -p"$KWAI_DATABASE_PASSWORD" -e "grant all privileges on $KWAI_DATABASE_NAME.* to '$KWAI_DATABASE_USER'@'%' identified by '$KWAI_DATABASE_PASSWORD'"

# update mysql conf file to allow remote access to the db
sed -i "s/.*bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/mysql.conf.d/mysqld.cnf
service mysql restart

# Install PHP
apt-get install -y php7.4 php-mysql libapache2-mod-php php-intl
PHP_VERSION=8.1
apt-get install -y php${PHP_VERSION}-common php${PHP_VERSION}-cli php${PHP_VERSION}-mysql libapache2-mod-php${PHP_VERSION} php${PHP_VERSION}-intl php${PHP_VERSION}-dom php${PHP_VERSION}-gd php${PHP_VERSION}-mbstring php${PHP_VERSION}-zip php${PHP_VERSION}-sqlite php${PHP_VERSION}-xml php${PHP_VERSION}-curl

php -v
a2enmod php7.4
a2enmod php${PHP_VERSION}

phpenmod intl
phpenmod curl

# Install unzip for Composer
apt-get install -y unzip

# Composer
EXPECTED_CHECKSUM="$(wget -q -O - https://composer.github.io/installer.sig)"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'c31c1e292ad7be5f49291169c0ac8f683499edddcfd4e42232982d0fd193004208a58ff6f353fde0012d35fdd72bc394') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"
if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]
then
>&2 echo 'ERROR: Invalid installer checksum'
rm composer-setup.php
exit 1
fi
php composer-setup.php --quiet
php -r "unlink('composer-setup.php');"
mv composer.phar /usr/local/bin/composer

# PHPMyAdmin
add-apt-repository -y ppa:phpmyadmin/ppa
apt-get update
apt-get upgrade
debconf-set-selections <<< "phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2"
debconf-set-selections <<< "phpmyadmin phpmyadmin/dbconfig-install no"
apt-get -yq install phpmyadmin
PHPMYADMIN_VERSION=5.1.1
wget https://files.phpmyadmin.net/phpMyAdmin/${PHPMYADMIN_VERSION}/phpMyAdmin-${PHPMYADMIN_VERSION}-all-languages.zip -nv -O /var/tmp/phpmyadmin.zip
unzip -q /var/tmp/phpmyadmin.zip -d /var/tmp/phpmyadmin
rm -Rf /var/www/phpmyadmin
mv /var/tmp/phpmyadmin/phpMyAdmin-${PHPMYADMIN_VERSION}-all-languages /var/www/phpmyadmin
mv /var/www/phpmyadmin/config.sample.inc.php /var/www/phpmyadmin/config.inc.php
chown -R www-data:www-data /var/www/phpmyadmin
rm /var/tmp/phpmyadmin.zip
rm -r /var/tmp/phpmyadmin

PHPMYADMIN_CONF=$(cat <<EOF
<Directory /var/www/phpmyadmin>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<VirtualHost *:81>
ServerName api.kwai.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/phpmyadmin
ErrorLog ${APACHE_LOG_DIR}/phpmyadmin_error.log
CustomLog ${APACHE_LOG_DIR}/phpmyadmin_access.log combined
</VirtualHost>
EOF
)
echo "${PHPMYADMIN_CONF}" > /etc/apache2/sites-available/phpmyadmin.conf

# Document root is a symlink to /vagrant
if ! [ -L /var/www/kwai_api ]; then
rm -rf /var/www/kwai_api
ln -fs /vagrant/ /var/www/kwai_api
fi

# Everything installed, restart apache
# Everything installed, enable sites, restart apache
sudo a2dissite 000-default
sudo a2ensite kwai
sudo a2ensite phpmyadmin
service apache2 restart

# Run the database migration
/vagrant/src/vendor/bin/phinx migrate -c /vagrant/src/phinx.php
/vagrant/vendor/bin/phinx migrate -c /vagrant/src/phinx.php
3 changes: 0 additions & 3 deletions api/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
/vendor/
/config.php
*.lock
13 changes: 0 additions & 13 deletions api/admin.php

This file was deleted.

Loading

0 comments on commit 049d3a1

Please sign in to comment.