Skip to content

Commit

Permalink
Compatibility with 5.2 (#120)
Browse files Browse the repository at this point in the history
* update test workflow

* use setEntity, update readme

* Update src/Form/Register.php

Co-authored-by: Michael Voříšek <[email protected]>

---------

Co-authored-by: Michael Voříšek <[email protected]>
  • Loading branch information
DarkSide666 and mvorisek authored Jan 16, 2025
1 parent 343de02 commit 51884e9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 25 deletions.
35 changes: 17 additions & 18 deletions .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
if: matrix.type == 'StaticAnalysis'
run: |
echo "memory_limit = 2G" > /usr/local/etc/php/conf.d/custom-memory-limit.ini
vendor/bin/phpstan analyse
vendor/bin/phpstan analyse -v
unit-test:
name: Unit
Expand Down Expand Up @@ -154,8 +154,8 @@ jobs:
php -d opcache.enable_cli=1 vendor/bin/phpunit --exclude-group none $(if [ -n "$LOG_COVERAGE" ]; then echo --coverage-text; else echo --no-coverage; fi) --fail-on-warning --fail-on-risky $(if vendor/bin/phpunit --version | grep -q '^PHPUnit 9\.'; then echo -v; else echo --fail-on-notice --fail-on-deprecation --display-notices --display-deprecations --display-warnings --display-errors --display-incomplete --display-skipped; fi)
if [ -n "$LOG_COVERAGE" ]; then mv coverage/phpunit.cov coverage/phpunit-sqlite.cov; fi
- name: "Run tests: MySQL"
if: success() || failure()
- name: "Run tests: MySQL (only for cron)"
if: (success() || failure()) && github.event_name == 'schedule'
env:
DB_DSN: "mysql:host=mysql;dbname=atk4_test"
DB_USER: atk4_test_user
Expand All @@ -174,8 +174,8 @@ jobs:
php -d opcache.enable_cli=1 vendor/bin/phpunit --exclude-group none $(if [ -n "$LOG_COVERAGE" ]; then echo --coverage-text; else echo --no-coverage; fi) --fail-on-warning --fail-on-risky $(if vendor/bin/phpunit --version | grep -q '^PHPUnit 9\.'; then echo -v; else echo --fail-on-notice --fail-on-deprecation --display-notices --display-deprecations --display-warnings --display-errors --display-incomplete --display-skipped; fi)
if [ -n "$LOG_COVERAGE" ]; then mv coverage/phpunit.cov coverage/phpunit-mariadb.cov; fi
- name: "Run tests: PostgreSQL"
if: success() || failure()
- name: "Run tests: PostgreSQL (only for cron)"
if: (success() || failure()) && github.event_name == 'schedule'
env:
DB_DSN: "pgsql:host=postgres;dbname=atk4_test"
DB_USER: atk4_test_user
Expand All @@ -184,8 +184,8 @@ jobs:
php -d opcache.enable_cli=1 vendor/bin/phpunit --exclude-group none $(if [ -n "$LOG_COVERAGE" ]; then echo --coverage-text; else echo --no-coverage; fi) --fail-on-warning --fail-on-risky $(if vendor/bin/phpunit --version | grep -q '^PHPUnit 9\.'; then echo -v; else echo --fail-on-notice --fail-on-deprecation --display-notices --display-deprecations --display-warnings --display-errors --display-incomplete --display-skipped; fi)
if [ -n "$LOG_COVERAGE" ]; then mv coverage/phpunit.cov coverage/phpunit-postgres.cov; fi
- name: "Run tests: MSSQL"
if: success() || failure()
- name: "Run tests: MSSQL (only for cron)"
if: (success() || failure()) && github.event_name == 'schedule'
env:
DB_DSN: "sqlsrv:host=mssql;dbname=master;driverOptions[TrustServerCertificate]=1"
DB_USER: sa
Expand Down Expand Up @@ -213,7 +213,7 @@ jobs:
- name: Upload coverage logs 2/2 (only for latest Phpunit)
if: env.LOG_COVERAGE
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
Expand Down Expand Up @@ -284,12 +284,12 @@ jobs:
restore-keys: |
${{ runner.os }}-composer-
- name: Install JS dependencies (only for Slow)
- name: Install JS dependencies (only for Chrome Slow)
if: matrix.type == 'Chrome Slow'
run: |
npm install --loglevel=error -g pug-cli
- name: Build/diff HTML files (only for Slow)
- name: Diff compiled files (only for Chrome Slow)
if: matrix.type == 'Chrome Slow'
run: |
cp -r template template.orig
Expand Down Expand Up @@ -328,7 +328,7 @@ jobs:
- name: "Run tests: SQLite"
run: |
php demos/_demo-data/create-db.php
vendor/bin/behat -vv --config behat.yml.dist
vendor/bin/behat --strict -vv --config behat.yml.dist
- name: "Run tests: MySQL (only for cron)"
if: (success() || failure()) && github.event_name == 'schedule'
Expand All @@ -339,7 +339,7 @@ jobs:
run: |
sed -E "s~(\\\$db = new.+Persistence\\\\Sql)\(.+\);~\\1('$DB_DSN', '$DB_USER', '$DB_PASSWORD');~g" -i demos/db.default.php
php demos/_demo-data/create-db.php
vendor/bin/behat -vv --config behat.yml.dist
vendor/bin/behat --strict -vv --config behat.yml.dist
- name: "Run tests: MariaDB (only for coverage or cron)"
if: (success() || failure()) && (env.LOG_COVERAGE || github.event_name == 'schedule')
Expand All @@ -350,7 +350,7 @@ jobs:
run: |
sed -E "s~(\\\$db = new.+Persistence\\\\Sql)\(.+\);~\\1('$DB_DSN', '$DB_USER', '$DB_PASSWORD');~g" -i demos/db.default.php
php demos/_demo-data/create-db.php
vendor/bin/behat -vv --config behat.yml.dist
vendor/bin/behat --strict -vv --config behat.yml.dist
- name: "Run tests: PostgreSQL (only for cron)"
if: (success() || failure()) && github.event_name == 'schedule'
Expand All @@ -361,7 +361,7 @@ jobs:
run: |
sed -E "s~(\\\$db = new.+Persistence\\\\Sql)\(.+\);~\\1('$DB_DSN', '$DB_USER', '$DB_PASSWORD');~g" -i demos/db.default.php
php demos/_demo-data/create-db.php
vendor/bin/behat -vv --config behat.yml.dist
vendor/bin/behat --strict -vv --config behat.yml.dist
- name: "Run tests: MSSQL (only for cron)"
if: (success() || failure()) && github.event_name == 'schedule'
Expand All @@ -372,7 +372,7 @@ jobs:
run: |
sed -E "s~(\\\$db = new.+Persistence\\\\Sql)\(.+\);~\\1('$DB_DSN', '$DB_USER', '$DB_PASSWORD');~g" -i demos/db.default.php
php demos/_demo-data/create-db.php
vendor/bin/behat -vv --config behat.yml.dist
vendor/bin/behat --strict -vv --config behat.yml.dist
- name: "Run tests: Oracle (only for cron)"
if: (success() || failure()) && github.event_name == 'schedule'
Expand All @@ -384,7 +384,7 @@ jobs:
run: |
sed -E "s~(\\\$db = new.+Persistence\\\\Sql)\(.+\);~\\1('$DB_DSN', '$DB_USER', '$DB_PASSWORD');~g" -i demos/db.default.php
php demos/_demo-data/create-db.php
vendor/bin/behat -vv --config behat.yml.dist
vendor/bin/behat --strict -vv --config behat.yml.dist
- name: Upload coverage logs 1/2 (only for coverage)
if: env.LOG_COVERAGE
Expand All @@ -394,9 +394,8 @@ jobs:
- name: Upload coverage logs 2/2 (only for coverage)
if: env.LOG_COVERAGE
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
files: coverage/merged.xml,coverage/js/clover.xml

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ if (!$app->auth->user->isLoaded()) {

``` php
\Atk4\Login\RegisterForm::addTo($app)
->setModel(new \Atk4\Login\Model\User($app->db));
->setEntity(new \Atk4\Login\Model\User($app->db));
```

Displays email and 2 password fields (for confirmation). If filled successfully will create new record for `\Atk4\Login\Model\User`. Will cast email to lowercase before adding. Things to try:
Expand Down Expand Up @@ -141,15 +141,15 @@ You may also access user data like this: `$app->auth->model['name']`; Things to
This form would allow user to change user data (including password) but only if user is authenticated. To implement profile form use:

``` php
Form::addTo($app)->setModel($app->auth->user);
Form::addTo($app)->setEntity($app->auth->user);
```

Demos open profile form in a pop-up window, if you wish to do it, you can use this code:

``` php
Button::addTo($app, ['Profile', 'class.primary' => true])
->on('click', Modal::addTo($app)->set(function (View $p) {
Form::addTo($p)->setModel($p->getApp()->auth->user);
Form::addTo($p)->setEntity($p->getApp()->auth->user);
})->jsShow());
```

Expand Down
2 changes: 1 addition & 1 deletion src/Form/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function setEntity(Model $user, ?array $fields = null): void
// Look if user already exist?
$model = $this->entity->getModel();
$entity = $model->tryLoadBy($this->auth->fieldLogin, $form->entity->get($this->auth->fieldLogin));
if ($entity->loaded()) {
if ($entity !== null) {
return $form->jsError($this->auth->fieldLogin, 'User with this email already exist');
}

Expand Down
5 changes: 2 additions & 3 deletions src/UserAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
use Atk4\Ui\Modal;
use Atk4\Ui\Table\Column;
use Atk4\Ui\View;
//use Atk4\Ui\View\ModelTrait;
use Atk4\Ui\View\ModelTrait;

/**
* View for User administration. Includes User association with Role.
*/
class UserAdmin extends View
{
use DebugTrait;
//use ModelTrait;
use ModelTrait;

/** @var Crud */
public $crud;
Expand All @@ -38,7 +38,6 @@ protected function init(): void
/**
* Initialize User Admin and add all the UI pieces.
*/
#[\Override]
public function setModel(Model $user): void
{
// $user->getUserAction('registerNewUser')->system = true;
Expand Down

0 comments on commit 51884e9

Please sign in to comment.