diff --git a/.github/workflows/php-cs.yml b/.github/workflows/php-cs.yml index 3fc5f33..533c9b9 100644 --- a/.github/workflows/php-cs.yml +++ b/.github/workflows/php-cs.yml @@ -1,7 +1,6 @@ name: PHP Code Styles env: - COMPOSER_VER: "2.7.9" PHP_VER: "8.1" on: @@ -14,29 +13,17 @@ jobs: php-cs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Cache Composer dependencies - uses: actions/cache@v3 - with: - path: /tmp/composer-cache - key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }} + - uses: actions/checkout@v4 - - uses: php-actions/composer@v6 - with: - php_version: ${{ env.PHP_VER }} - version: ${{ env.COMPOSER_VER }} - - - name: Get PHPCS Cache - id: phpcs-cache + - name: Build CI image run: | - echo "file=.phpcs.cache" >> $GITHUB_OUTPUT - - - uses: actions/cache@v3 - with: - path: ${{ steps.phpcs-cache.outputs.file }} - key: ${{ runner.os }}-phpcs-${{ hashFiles('**/.phpcs.cache') }} - restore-keys: | - ${{ runner.os }}-phpcs- + docker build \ + --build-arg PHP_VERSION=${{ env.PHP_VER }} \ + -t wpconnections-ci:${{ env.PHP_VER }} \ + -f Dockerfile.phpunit . - name: Run PHPCS - run: composer run phpcs + run: | + docker run --rm -v "$PWD:/srv/web" \ + wpconnections-ci:${{ env.PHP_VER }} \ + cs:phpcs diff --git a/.github/workflows/wp-integration-tests.yml b/.github/workflows/wp-integration-tests.yml new file mode 100644 index 0000000..1824788 --- /dev/null +++ b/.github/workflows/wp-integration-tests.yml @@ -0,0 +1,38 @@ +name: WP Integration Tests + +on: + push: + branches: [ "master", "main", "dev" ] + pull_request: + types: [synchronize, opened, reopened] + +permissions: {} + +jobs: + wp-integration: + name: WP Integration Tests PHP ${{ matrix.php-version }} / Ramsey ${{ matrix.ramsey-version }} + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + php-version: [ 8.1, 8.2, 8.3, 8.4 ] + ramsey-version: [ "^1", "^2" ] + + steps: + - name: Check out the source code + uses: actions/checkout@v4 + + - name: Build CI image + run: | + docker build \ + --build-arg PHP_VERSION=${{ matrix.php-version }} \ + -t wpconnections-ci:${{ matrix.php-version }} \ + -f Dockerfile.phpunit . + + - name: Run WP integration tests + run: | + docker run --rm -v "$PWD:/srv/web" \ + -e RAMSEY_VERSION='${{ matrix.ramsey-version }}' \ + wpconnections-ci:${{ matrix.php-version }} \ + test:integration diff --git a/.github/workflows/wp-unit-tests-docker.yml b/.github/workflows/wp-unit-tests-docker.yml index 990db28..bda9bb9 100644 --- a/.github/workflows/wp-unit-tests-docker.yml +++ b/.github/workflows/wp-unit-tests-docker.yml @@ -1,4 +1,4 @@ -name: Unit Tests (Dockerfile) +name: Unit Tests on: push: @@ -10,7 +10,7 @@ permissions: {} jobs: phpunit: - name: PHP Unit ${{ matrix.php-version }} / Ramsey ${{ matrix.ramsey-version }} + name: Unit Tests PHP ${{ matrix.php-version }} / Ramsey ${{ matrix.ramsey-version }} runs-on: ubuntu-latest strategy: @@ -23,15 +23,16 @@ jobs: - name: Check out the source code uses: actions/checkout@v4 - - name: Build PHPUnit image + - name: Build CI image run: | docker build \ --build-arg PHP_VERSION=${{ matrix.php-version }} \ - -t wpconnections-phpunit:${{ matrix.php-version }} \ + -t wpconnections-ci:${{ matrix.php-version }} \ -f Dockerfile.phpunit . - - name: Run all tests + - name: Run unit tests run: | docker run --rm -v "$PWD:/srv/web" \ - wpconnections-phpunit:${{ matrix.php-version }} \ - sh -lc 'git config --global --add safe.directory "*" && composer update ramsey/collection --with "ramsey/collection:${{ matrix.ramsey-version }}" --prefer-dist --no-interaction && composer run phpunit && vendor/bin/phpunit -c php-wp-unit.xml' + -e RAMSEY_VERSION='${{ matrix.ramsey-version }}' \ + wpconnections-ci:${{ matrix.php-version }} \ + test:phpunit diff --git a/.github/workflows/wp-unit-tests.yml b/.github/workflows/wp-unit-tests.yml deleted file mode 100644 index 4781bf2..0000000 --- a/.github/workflows/wp-unit-tests.yml +++ /dev/null @@ -1,120 +0,0 @@ -name: Unit Tests - -env: - COMPOSER_VER: "2.7.9" - -on: - push: - branches: [ "master", "main", "dev" ] - pull_request: - types: [synchronize, opened, reopened] - -permissions: {} - -jobs: - phpunit: - name: PHP Unit ${{ matrix.php-version }} / Ramsey ${{ matrix.ramsey-version }} - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - php-version: [ 8.1, 8.2, 8.3, 8.4 ] - ramsey-version: [ "^1", "^2" ] - - services: - mysql: - image: mariadb:latest - ports: - - '3306:3306' - env: - MYSQL_ROOT_PASSWORD: wordpress - MARIADB_INITDB_SKIP_TZINFO: 1 - MYSQL_USER: wordpress - MYSQL_PASSWORD: wordpress - MYSQL_DATABASE: wordpress_test - - steps: - - name: Check out the source code - uses: actions/checkout@v3 - - - uses: shivammathur/setup-php@v2 - name: Set up PHP - with: - php-version: ${{ matrix.php-version }} - coverage: none - - - uses: php-actions/composer@v6 - with: - php_version: ${{ matrix.php-version }} - version: ${{ env.COMPOSER_VER }} - - - name: Select Ramsey Collection version - run: | - composer update ramsey/collection \ - --with "ramsey/collection:${{ matrix.ramsey-version }}" \ - --prefer-dist \ - --no-interaction - - - name: Run UnitTests - run: composer run phpunit - - wp-unit: - name: WP Unit ${{ matrix.php-version }} / Ramsey ${{ matrix.ramsey-version }} - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - php-version: [ 8.1, 8.2, 8.3, 8.4 ] - ramsey-version: [ "^1", "^2" ] - - services: - mysql: - image: mariadb:latest - ports: - - '3306:3306' - env: - MYSQL_ROOT_PASSWORD: wordpress - MARIADB_INITDB_SKIP_TZINFO: 1 - MYSQL_USER: wordpress - MYSQL_PASSWORD: wordpress - MYSQL_DATABASE: wordpress_test - - steps: - - name: Check out the source code - uses: actions/checkout@v3 - - - uses: shivammathur/setup-php@v2 - name: Set up PHP - with: - php-version: ${{ matrix.php-version }} - coverage: none - - - name: Install PHP Dependencies - uses: ramsey/composer-install@v2 - - - name: Select Ramsey Collection version - run: | - composer update ramsey/collection \ - --with "ramsey/collection:${{ matrix.ramsey-version }}" \ - --prefer-dist \ - --no-interaction - - - name: Install Subversion - run: sudo apt-get update && sudo apt-get install -y subversion - - - name: Set up WordPress and WordPress Test Library - uses: sjinks/setup-wordpress-test-library@master - with: - version: latest - - - name: Verify MariaDB connection - run: | - while ! mysqladmin ping -h 127.0.0.1 -P ${{ job.services.mysql.ports[3306] }} --silent; do - sleep 1 - done - timeout-minutes: 1 - - - name: Run - run: vendor/bin/phpunit -c php-wp-unit.xml diff --git a/Dockerfile.phpunit b/Dockerfile.phpunit index dda1e9a..5985634 100644 --- a/Dockerfile.phpunit +++ b/Dockerfile.phpunit @@ -18,8 +18,7 @@ ENV COMPOSER_ALLOW_SUPERUSER=1 \ MYSQL_SOCKET=/run/mysqld/mysqld.sock \ DB_HOST=127.0.0.1 \ DB_NAME=wordpress_test \ - DB_USER=wordpress \ - DB_PASSWORD=wordpress + DB_USER=wordpress RUN set -eux; \ apt-get update; \ @@ -41,21 +40,18 @@ RUN set -eux; \ # Provide composer inside the image COPY --from=composer:2 /usr/bin/composer /usr/bin/composer -# Pre-install WordPress core and the WordPress test library so the container -# is fully self-contained when executing the WordPress PHPUnit suite. +# Pre-install the WordPress test library so the container is self-contained +# when executing the WordPress PHPUnit suite. RUN set -eux; \ rm -rf "${WP_DEVELOP_DIR}"; \ mkdir -p "${WP_DEVELOP_DIR}"; \ if [ "${WP_VERSION}" = "latest" ]; then \ - WP_TARBALL_URL="https://wordpress.org/latest.tar.gz"; \ WP_TESTS_ARCHIVE="https://github.com/WordPress/wordpress-develop/archive/refs/heads/master.tar.gz"; \ WP_TESTS_REF="master"; \ else \ - WP_TARBALL_URL="https://wordpress.org/wordpress-${WP_VERSION}.tar.gz"; \ WP_TESTS_ARCHIVE="https://github.com/WordPress/wordpress-develop/archive/refs/tags/${WP_VERSION}.tar.gz"; \ WP_TESTS_REF="${WP_VERSION}"; \ fi; \ - curl -fsSL "$WP_TESTS_ARCHIVE" -o /tmp/wordpress-develop.tar.gz; \ tar -xzf /tmp/wordpress-develop.tar.gz -C "${WP_DEVELOP_DIR}" --strip-components=1; \ rm /tmp/wordpress-develop.tar.gz; \ diff --git a/README.md b/README.md index 1fe773f..2121a1b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # WP Connections: post-to-post connections for WordPress -[![PHP CS](https://github.com/hokoo/wpConnections/actions/workflows/php-cs.yml/badge.svg)](https://github.com/hokoo/wpConnections/actions/workflows/phpunit.yml) -[![PHP WordPress Unit Tests](https://github.com/hokoo/wpConnections/actions/workflows/wp-unit-tests.yml/badge.svg)](https://github.com/hokoo/wpConnections/actions/workflows/wp-unit-tests.yml) -[![Dockerfile Unit Tests](https://github.com/hokoo/wpConnections/actions/workflows/wp-unit-tests-docker.yml/badge.svg)](https://github.com/hokoo/wpConnections/actions/workflows/wp-unit-tests-docker.yml) +[![PHP CS](https://github.com/hokoo/wpConnections/actions/workflows/php-cs.yml/badge.svg)](https://github.com/hokoo/wpConnections/actions/workflows/php-cs.yml) +[![Unit Tests](https://github.com/hokoo/wpConnections/actions/workflows/wp-unit-tests-docker.yml/badge.svg)](https://github.com/hokoo/wpConnections/actions/workflows/wp-unit-tests-docker.yml) +[![WP Integration Tests](https://github.com/hokoo/wpConnections/actions/workflows/wp-integration-tests.yml/badge.svg)](https://github.com/hokoo/wpConnections/actions/workflows/wp-integration-tests.yml) * [Why wpConnection?](#why-wpconnection) @@ -93,9 +93,9 @@ Since you have initialized new client, its REST API endpoints are available. 2. Make sure you have `make` installed in your system. If not, run `sudo apt install make`. 3. Make sure you have installed Docker Desktop with configured WSL2 support if you are using Windows. 4. Add `127.0.0.1 wpconnections.local` to the hosts file (on the host machine). -5. Run folowing command in the root directory to install the project: +5. Run the following command in the root directory to install the project: ```bash -bash ./local-dev/init.sh && make tests.init && make docker.up && make dev.install +bash ./local-dev/init.sh && make docker.up && make dev.install ``` ### Running the test suites @@ -106,11 +106,16 @@ The project ships with a dedicated `Dockerfile.phpunit` image that bundles Compo make tests.run ``` -Behind the scenes this calls `docker compose` with the `phpunit` service defined in `local-dev/docker-compose.yml`. The service no longer depends on any other containers—the entrypoint spins up MariaDB and configures the WordPress test library on demand—so these commands can be executed anywhere Docker is available. You can also run the individual commands manually, for example: +Behind the scenes this calls the `phpunit` service defined in `local-dev/docker-compose.yml` and aggregates the same entrypoint checks that GitHub Actions runs separately. The service no longer depends on any other containers: the entrypoint installs Composer dependencies when needed, spins up MariaDB only for WP integration tests, and configures the WordPress test library on demand. + +You can also run individual checks from the project root: ```bash -docker compose -f local-dev/docker-compose.yml run --rm phpunit composer run phpunit -docker compose -f local-dev/docker-compose.yml run --rm phpunit vendor/bin/phpunit -c php-wp-unit.xml +make tests.phpunit +make tests.integration +make lint.phpcs ``` -The same Dockerfile is also used by the optional GitHub Actions workflow defined in `.github/workflows/wp-unit-tests-docker.yml`, allowing you to compare its output against the long-standing `wp-unit-tests.yml` pipeline before switching over entirely. You can pin WordPress to a specific release by passing `--build-arg WP_VERSION=6.5.2` (or any other version number) when building the image. +`make tests.init` is only needed for direct, non-Docker WordPress PHPUnit runs that rely on a local `wordpress-develop` checkout. The default local and CI paths use `Dockerfile.phpunit`. + +The same Dockerfile is used by GitHub Actions workflows for unit tests and PHP code style checks. You can pin WordPress to a specific release by passing `--build-arg WP_VERSION=6.5.2` (or any other version number) when building the image. diff --git a/docker/phpunit-entrypoint.sh b/docker/phpunit-entrypoint.sh index 4015cde..346694d 100755 --- a/docker/phpunit-entrypoint.sh +++ b/docker/phpunit-entrypoint.sh @@ -10,98 +10,118 @@ WP_DEVELOP_DIR="${WP_DEVELOP_DIR:-/opt/wordpress-develop}" WP_TESTS_DIR="${WP_TESTS_DIR:-/opt/wordpress-develop/tests/phpunit}" MYSQL_SOCKET="${MYSQL_SOCKET:-/run/mysqld/mysqld.sock}" MYSQL_DATA_DIR="${MYSQL_DATA_DIR:-/tmp/mysql-data}" +RAMSEY_VERSION="${RAMSEY_VERSION:-}" CONFIG_SAMPLE="${WP_DEVELOP_DIR}/wp-tests-config-sample.php" CONFIG_FILE="${WP_DEVELOP_DIR}/wp-tests-config.php" MYSQL_RUNTIME_USER="${MYSQL_RUNTIME_USER:-$(id -un 2>/dev/null || echo root)}" MYSQL_RUN_DIR="$(dirname "${MYSQL_SOCKET}")" +MYSQLD_PID="" +WP_ENV_READY=0 -mkdir -p "${MYSQL_RUN_DIR}" "${MYSQL_DATA_DIR}" - -if [ "$(id -u)" -eq 0 ]; then - chown -R "${MYSQL_RUNTIME_USER}" "${MYSQL_RUN_DIR}" "${MYSQL_DATA_DIR}" -fi - -if [ ! -d "${MYSQL_DATA_DIR}/mysql" ]; then - mariadb-install-db \ - --user="${MYSQL_RUNTIME_USER}" \ - --datadir="${MYSQL_DATA_DIR}" \ - --skip-test-db \ - --auth-root-authentication-method=normal >/dev/null -fi - -mariadbd \ - --user="${MYSQL_RUNTIME_USER}" \ - --datadir="${MYSQL_DATA_DIR}" \ - --socket="${MYSQL_SOCKET}" \ - --bind-address=127.0.0.1 \ - --skip-networking=0 & -MYSQLD_PID=$! +WORKDIR="/srv/web" cleanup() { - if kill -0 "${MYSQLD_PID}" >/dev/null 2>&1; then + if [ -n "${MYSQLD_PID}" ] && kill -0 "${MYSQLD_PID}" >/dev/null 2>&1; then mysqladmin --protocol=socket --socket="${MYSQL_SOCKET}" -uroot shutdown >/dev/null 2>&1 || true wait "${MYSQLD_PID}" >/dev/null 2>&1 || true fi } trap cleanup EXIT -MYSQL_READY=0 -for _ in $(seq 1 30); do - if mysqladmin --protocol=socket --socket="${MYSQL_SOCKET}" -uroot ping >/dev/null 2>&1; then - MYSQL_READY=1 - break +cd "$WORKDIR" +git config --global --add safe.directory "*" >/dev/null 2>&1 || true + +log_section() { + echo + echo "========================================" + echo ">>> $1" + echo "========================================" +} + +start_database() { + log_section "MariaDB" + + mkdir -p "${MYSQL_RUN_DIR}" "${MYSQL_DATA_DIR}" + + if [ "$(id -u)" -eq 0 ]; then + chown -R "${MYSQL_RUNTIME_USER}" "${MYSQL_RUN_DIR}" "${MYSQL_DATA_DIR}" fi - sleep 1 -done -if [ "${MYSQL_READY}" -ne 1 ]; then - echo "Timed out waiting for MariaDB to accept connections" >&2 - exit 1 -fi + if [ ! -d "${MYSQL_DATA_DIR}/mysql" ]; then + mariadb-install-db \ + --user="${MYSQL_RUNTIME_USER}" \ + --datadir="${MYSQL_DATA_DIR}" \ + --skip-test-db \ + --auth-root-authentication-method=normal >/dev/null + fi + + mariadbd \ + --user="${MYSQL_RUNTIME_USER}" \ + --datadir="${MYSQL_DATA_DIR}" \ + --socket="${MYSQL_SOCKET}" \ + --bind-address=127.0.0.1 \ + --skip-networking=0 & + MYSQLD_PID=$! + + local mysql_ready=0 + for _ in $(seq 1 30); do + if mysqladmin --protocol=socket --socket="${MYSQL_SOCKET}" -uroot ping >/dev/null 2>&1; then + mysql_ready=1 + break + fi + sleep 1 + done + + if [ "${mysql_ready}" -ne 1 ]; then + echo "Timed out waiting for MariaDB to accept connections" >&2 + exit 1 + fi -mysql --protocol=socket --socket="${MYSQL_SOCKET}" -uroot <&2 - if [ -f "${CONFIG_SAMPLE}" ]; then - cp "${CONFIG_SAMPLE}" "${CONFIG_FILE}" - else - echo "Sample config not found at ${CONFIG_SAMPLE}" >&2 - exit 1 +prepare_wp_tests() { + if [ "${WP_ENV_READY}" -eq 1 ]; then + return fi -fi - -sed -i "s/youremptytestdbnamehere/${DB_NAME}/" "${CONFIG_FILE}" -sed -i "s/yourusernamehere/${DB_USER}/" "${CONFIG_FILE}" -sed -i "s/yourpasswordhere/${DB_PASSWORD}/" "${CONFIG_FILE}" -sed -i "s|localhost|${DB_HOST}|1" "${CONFIG_FILE}" -sed -i "s|dirname( __FILE__ ) . '/../../'|'${WP_CORE_DIR}/'|" "${CONFIG_FILE}" -export WP_TESTS_DIR DB_HOST DB_NAME DB_USER DB_PASSWORD + start_database -# ==== Here and below is a universal "command dispatcher" ==== + if [ ! -f "${CONFIG_FILE}" ]; then + echo "wp-tests-config.php missing; recreating from sample" >&2 + if [ -f "${CONFIG_SAMPLE}" ]; then + cp "${CONFIG_SAMPLE}" "${CONFIG_FILE}" + else + echo "Sample config not found at ${CONFIG_SAMPLE}" >&2 + exit 1 + fi + fi -WORKDIR="/srv/web" -cd "$WORKDIR" + sed -i "s/youremptytestdbnamehere/${DB_NAME}/" "${CONFIG_FILE}" + sed -i "s/yourusernamehere/${DB_USER}/" "${CONFIG_FILE}" + sed -i "s/yourpasswordhere/${DB_PASSWORD}/" "${CONFIG_FILE}" + sed -i "s|localhost|${DB_HOST}|1" "${CONFIG_FILE}" + sed -i "s|dirname( __FILE__ ) . '/../../'|'${WP_CORE_DIR}/'|" "${CONFIG_FILE}" -log_section() { - echo - echo "========================================" - echo ">>> $1" - echo "========================================" + export WP_TESTS_DIR DB_HOST DB_NAME DB_USER DB_PASSWORD + WP_ENV_READY=1 } run_composer_install() { - log_section "Composer install" + log_section "Composer dependencies" if [ -f composer.json ]; then - # Skip if vendor/ already exists. - if [ -d vendor ]; then + if [ -n "${RAMSEY_VERSION}" ]; then + composer update ramsey/collection \ + --with "ramsey/collection:${RAMSEY_VERSION}" \ + --prefer-dist \ + --no-interaction + elif [ -d vendor ]; then echo "vendor/ already exists, skipping composer install" else composer install --no-interaction --prefer-dist @@ -116,12 +136,17 @@ run_phpunit() { vendor/bin/phpunit -c phpunit.xml "$@" } -run_wpunit() { - log_section "WordPress Unit tests (php-wp-unit.xml)" +run_wp_integration() { + log_section "WP Integration tests (php-wp-unit.xml)" + prepare_wp_tests vendor/bin/phpunit -c php-wp-unit.xml "$@" } -# Collect exit codes of both suites +run_phpcs() { + log_section "PHP CodeSniffer" + composer run phpcs +} + run_all_tests() { local phpunit_exit=0 local wpunit_exit=0 @@ -129,13 +154,13 @@ run_all_tests() { run_composer_install run_phpunit "$@" || phpunit_exit=$? - run_wpunit "$@" || wpunit_exit=$? + run_wp_integration "$@" || wpunit_exit=$? if [ "$phpunit_exit" -ne 0 ] || [ "$wpunit_exit" -ne 0 ]; then echo echo "One or more test suites failed:" echo " PHP Unit exit code: $phpunit_exit" - echo " WP Unit exit code: $wpunit_exit" + echo " WP Integration exit code: $wpunit_exit" # If needed to distinguish, we could return, for example, the first non-zero exit 1 fi @@ -155,10 +180,16 @@ case "$CMD" in run_phpunit "$@" ;; - test:wpunit) + test:integration|test:wp-integration|test:wpunit) + shift + run_composer_install + run_wp_integration "$@" + ;; + + cs:phpcs|phpcs) shift run_composer_install - run_wpunit "$@" + run_phpcs ;; composer-install) diff --git a/makefile b/makefile index c80e4c6..2bc238b 100644 --- a/makefile +++ b/makefile @@ -1,9 +1,21 @@ +.PHONY: tests.init tests.run tests.phpunit tests.integration tests.wpunit dev.install docker.up docker.down docker.build.php php.connect php.log lint.phpcs lint.phpcs.fix + tests.init: cd ./local-dev/ && bash ./tests-init.sh tests.run: cd ./local-dev/ && \ - docker-compose -p wpconnections run --rm phpunit sh -c 'vendor/bin/phpunit -c phpunit.xml && vendor/bin/phpunit -c php-wp-unit.xml' + docker-compose -p wpconnections run --rm phpunit test:all + +tests.phpunit: + cd ./local-dev/ && \ + docker-compose -p wpconnections run --rm phpunit test:phpunit + +tests.integration: + cd ./local-dev/ && \ + docker-compose -p wpconnections run --rm phpunit test:integration + +tests.wpunit: tests.integration dev.install: cd ./local-dev/ && \ @@ -31,7 +43,7 @@ php.log: lint.phpcs: cd ./local-dev/ && \ - docker-compose -p wpconnections exec php sh -c 'composer run phpcs' + docker-compose -p wpconnections run --rm phpunit cs:phpcs lint.phpcs.fix: cd ./local-dev/ && \ diff --git a/src/WPStorage.php b/src/WPStorage.php index 149f3b0..b6c14e3 100644 --- a/src/WPStorage.php +++ b/src/WPStorage.php @@ -51,38 +51,38 @@ private function init() $this->install(); } - private function install() - { - Database::install_table( - $this->get_connections_table(), - " - `ID` bigint(20) unsigned NOT NULL auto_increment, - `relation` varchar(255) NOT NULL, - `from` bigint(20) unsigned NOT NULL, - `to` bigint(20) unsigned NOT NULL, - `order` bigint(20) unsigned NULL default '0', - `title` varchar(63) NULL default '', - PRIMARY KEY (`ID`), - KEY `from` (`from`), - KEY `to` (`to`), - KEY `order` (`order`), - KEY `relation` (`relation`) - " - ); - - Database::install_table( - $this->get_meta_table(), - " - `meta_id` bigint(20) unsigned NOT NULL auto_increment, - `connection_id` bigint(20) unsigned NOT NULL default '0', - `meta_key` varchar(255) NOT NULL, - `meta_value` longtext NOT NULL, - PRIMARY KEY (`meta_id`), - KEY `connection_id` (`connection_id`), - KEY `meta_key` (`meta_key`) - " - ); - } + private function install() + { + Database::install_table( + $this->get_connections_table(), + " + `ID` bigint(20) unsigned NOT NULL auto_increment, + `relation` varchar(255) NOT NULL, + `from` bigint(20) unsigned NOT NULL, + `to` bigint(20) unsigned NOT NULL, + `order` bigint(20) unsigned NULL default '0', + `title` varchar(63) NULL default '', + PRIMARY KEY (`ID`), + KEY `from` (`from`), + KEY `to` (`to`), + KEY `order` (`order`), + KEY `relation` (`relation`) + " + ); + + Database::install_table( + $this->get_meta_table(), + " + `meta_id` bigint(20) unsigned NOT NULL auto_increment, + `connection_id` bigint(20) unsigned NOT NULL default '0', + `meta_key` varchar(255) NOT NULL, + `meta_value` longtext NOT NULL, + PRIMARY KEY (`meta_id`), + KEY `connection_id` (`connection_id`), + KEY `meta_key` (`meta_key`) + " + ); + } /**