Skip to content

Commit

Permalink
Update to connect to Trove instead of ToolsDB
Browse files Browse the repository at this point in the history
This means we need to temporarily pull from a dev branch of
ToolforgeBundle, until the relevant PR is merged.

Update README since the Docker instructions will no longer work,
and add instructions about building assets.

Also update .editorconfig to use tabs in JSON files
  • Loading branch information
MusikAnimal committed Feb 13, 2024
1 parent d273b89 commit 2a77275
Show file tree
Hide file tree
Showing 8 changed files with 544 additions and 579 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ insert_final_newline = true
trim_trailing_whitespace = true

# tab indentation
[*.{php,js,less,twig}]
[*.{php,js,less,twig,json}]
indent_style = tab
indent_size = 4
4 changes: 4 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ TOOLSDB_HOST=127.0.0.1
TOOLSDB_PORT=4720
TOOLSDB_USERNAME=
TOOLSDB_PASSWORD=
TROVE_HOST=127.0.0.1
TROVE_PORT=4721
TROVE_USERNAME=
TROVE_PASSWORD=
COPYPATROL_DB_NAME=s52615__copypatrol_migrate_test_02_p

# OAuth credentials
Expand Down
84 changes: 15 additions & 69 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,78 +46,24 @@ integration, and instead connect to the existing user database on Toolforge (mor
symfony console toolforge:ssh --toolsdb
```
4. Start the Symfony web server with `symfony serve`
5. Visit the URL provided by the Symfony CLI to access the application.

### Asset changes

Assets are compiled using Webpack Encore. The compiled assets **must** be committed to the repository.

* Run `npm run dev` to compile assets for development and watch for changes.
* Run `npm run build` to compile assets for production.

### Running tests

* Run `composer test` to run the unit tests and PHP CodeSniffer.
* Run `npm test` to run the linting tests for JavaScript and CSS.

## Installing using Docker
Development through Docker is suggested if you have a different version of PHP locally
installed, or if you wish to keep an isolated installation of PHP 7.4 for CopyPatrol.
The base Docker image used is the `toolforge-php74-sssd-base` image from the Toolforge
Docker image registry, to ensure an environment as close to Toolforge as possible.

1. Copy [.env](.env) to [.env.local](.env.local) and fill in the appropriate details.
1. Set `REPLICAS_HOST_*` and `TOOLSDB_HOST` to `127.0.0.1`
2. Use the credentials in your `replica.my.cnf` file in the home directory of your
Toolforge account for `REPLICAS_USERNAME`, `REPLICAS_PASSWORD`, as well as
`TOOLSDB_USERNAME` and `TOOLSDB_PASSWORD`.
3. If you need to test (un)reviewing CopyPatrol cases, `TOOLSDB_USERNAME` and `TOOLSDB_PASSWORD`
need to be set to a user with an installation of the CopyPatrol database (`COPYPATROL_DB_NAME`).
4. If you need to test OAuth, obtain tokens by registering a new consumer on Meta at
[Special:OAuthConsumerRegistration](https://meta.wikimedia.org/wiki/Special:OAuthConsumerRegistration).
Alternatively, you can set `LOGGED_IN_USER` to any value to simulate being that user
after clicking on 'Login'.
5. `ITHENTICATE_USERNAME` and `ITHENTICATE_PASSWORD` are not necessary unless you need
to test the "iThenticate report" functionality.
2. Build the development image once and install Composer dependencies with the following
```bash
# (optional) Prevent double-downloading when the build occurs.
docker image pull docker-registry.tools.wmflabs.org/toolforge-php74-sssd-base:latest
docker compose build
# On Windows, use `%CD%` instead of `$(pwd)`.
docker run --rm -ti -v $(pwd):/app wikimedia/copypatrol:development composer install
```
3. (*Windows only*) Set the `HOME` environment variable to your user profile directory.
```cmd
setx HOME "%UserProfile%"
set HOME "%UserProfile%"
```
The first command sets `HOME` for future shells. The second command sets `HOME` for the current shell.
4. Open a new terminal and start the development container with
```bash
docker compose up
```
Starting the local development server will be delayed until the next
step is finished.
5. Open up an SSH tunnel to access the databases on Toolforge.
```bash
# Your SSH config at $HOME/.ssh will be used.
# Your passphrase will be requested if your private key is protected.
# If your Toolforge shell name is different from the default, append
# your shell name after "ssh". (e.g. `... start ssh exampleuser`)
docker compose exec copypatrol start ssh
```
This terminal will stay open as long as SSH is connected. No successful
connection message is shown, but Symfony will start immediately once the
ports are open.

Changes to this folder will automatically be applied to the running Docker container. This includes
changes to `src` files, `.env.local`, etc. XDebug is set up to connect to the host machine
(the computer running the Docker container) on port 9003 upon request ([more info](https://xdebug.org/docs/step_debug)).

If you wish to use testing databases instead of the Plagiabot databases live on Toolforge, change
`COPYPATROL_DB_NAME`, and all related connection options. You will still need to connect to
the Replica DBs for revision information, so leave `REPLICAS_HOST_*` untouched and keep
tunneling the port for the Replica DB in step 5.

To make a **production-level** (Toolforge-like) build, run the following. XDebug and
other related components will be disabled.
```bash
docker build -f docker/Dockerfile . --target production -t wikimedia/copypatrol:latest
```
When using this image, bind an `.env.local` file to `/app/.env.local` for configuration.
This configuration file must also point to proper hosts. When using local ports, use
`host.docker.internal` for Windows, or `172.17.0.1` for other platforms.
```bash
docker run -ti -p 80:80 -v $(pwd)/.env.local:/app/.env.local wikimedia/copypatrol:latest
```
_A new Docker image needs to be created following the move to Wikimedia VPS._
_You can use the manual installation instructions above in the meantime._

## Adding new languages

Expand Down
183 changes: 94 additions & 89 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,91 +1,96 @@
{
"name": "wikimedia/copypatrol",
"type": "project",
"description": "A tool that allows you to see recent Wikipedia edits that are flagged as possible copyright violations",
"license": "GPL-3.0-or-later",
"require": {
"php": ">=7.4",
"ext-ctype": "*",
"ext-iconv": "*",
"ext-json": "*",
"ext-intl": "*",
"ext-apcu": "*",
"doctrine/annotations": "^2.0",
"doctrine/doctrine-bundle": "^2.2",
"phpxmlrpc/phpxmlrpc": "^4.10",
"symfony/dotenv": "^5.4",
"symfony/expression-language": "^5.4",
"symfony/flex": "^1.3.1",
"symfony/framework-bundle": "^5.4",
"symfony/monolog-bundle": "^3.7",
"symfony/twig-bundle": "^5.4",
"symfony/webpack-encore-bundle": "^1.16",
"symfony/yaml": "^5.4",
"wikimedia/toolforge-bundle": "^1.5"
},
"require-dev": {
"mediawiki/mediawiki-codesniffer": "^38.0",
"mediawiki/minus-x": "^1.0",
"phpunit/phpunit": "^9.5",
"symfony/browser-kit": "5.4.*",
"symfony/css-selector": "5.4.*",
"symfony/maker-bundle": "^1.25",
"symfony/phpunit-bridge": "^5.4",
"symfony/web-profiler-bundle": "^5.4"
},
"config": {
"platform": {
"php": "7.4"
},
"optimize-autoloader": true,
"preferred-install": {
"*": "dist"
},
"sort-packages": true,
"allow-plugins": {
"symfony/flex": true
}
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
],
"test": [
"composer validate",
"phpcs -s .",
"./bin/console lint:twig ./templates",
"./bin/console lint:yaml ./config",
"minus-x check .",
"./bin/phpunit"
],
"fix": [
"phpcbf"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": false,
"require": "5.4.*"
}
}
"name": "wikimedia/copypatrol",
"type": "project",
"description": "A tool that allows you to see recent Wikipedia edits that are flagged as possible copyright violations",
"license": "GPL-3.0-or-later",
"repositories": [
{
"type": "git",
"url": "https://github.com/wikimedia/ToolforgeBundle"
}
],
"require": {
"php": ">=7.4",
"ext-ctype": "*",
"ext-iconv": "*",
"ext-json": "*",
"ext-intl": "*",
"ext-apcu": "*",
"doctrine/annotations": "^2.0",
"doctrine/doctrine-bundle": "^2.2",
"phpxmlrpc/phpxmlrpc": "^4.10",
"symfony/dotenv": "^5.4",
"symfony/expression-language": "^5.4",
"symfony/flex": "^1.3.1",
"symfony/framework-bundle": "^5.4",
"symfony/monolog-bundle": "^3.7",
"symfony/twig-bundle": "^5.4",
"symfony/webpack-encore-bundle": "^1.16",
"symfony/yaml": "^5.4",
"wikimedia/toolforge-bundle": "dev-trove"
},
"require-dev": {
"mediawiki/mediawiki-codesniffer": "^38.0",
"mediawiki/minus-x": "^1.0",
"phpunit/phpunit": "^9.5",
"symfony/browser-kit": "5.4.*",
"symfony/css-selector": "5.4.*",
"symfony/maker-bundle": "^1.25",
"symfony/phpunit-bridge": "^5.4",
"symfony/web-profiler-bundle": "^5.4"
},
"config": {
"platform": {
"php": "7.4"
},
"optimize-autoloader": true,
"preferred-install": {
"*": "dist"
},
"sort-packages": true,
"allow-plugins": {
"symfony/flex": true
}
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd"
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
],
"test": [
"composer validate",
"phpcs -s .",
"./bin/console lint:twig ./templates",
"./bin/console lint:yaml ./config",
"minus-x check .",
"./bin/phpunit"
],
"fix": [
"phpcbf"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": false,
"require": "5.4.*"
}
}
}
Loading

0 comments on commit 2a77275

Please sign in to comment.