Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to CakePHP 5 #1015

Merged
merged 46 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
4a39b77
Upgrade to CakePHP 5 with `bin/cake upgrade files /path/users `
rochamarcelo Jan 8, 2023
9ce689f
Upgrade to CakePHP 5 - Update dependencies
rochamarcelo Jan 8, 2023
f8d2463
Upgrade to CakePHP 5 - Fixing types and old deprecations with phpstan
rochamarcelo Jan 8, 2023
c827746
Upgrade to CakePHP 5 - Fixing types and unit tests
rochamarcelo Jan 9, 2023
3277e8d
Upgrade to CakePHP 5 - Fixing types and unit tests
rochamarcelo Jan 9, 2023
006fadc
Upgrade to CakePHP 5 - Fixing types and unit tests
rochamarcelo Jan 9, 2023
e22eb4e
Upgrade to CakePHP 5 - Migrate shell class to commands
rochamarcelo Jan 10, 2023
b06d1be
Upgrade to CakePHP 5 - Migrate shell class to commands
rochamarcelo Jan 10, 2023
c9d7230
Upgrade to CakePHP 5 - Fixed locale files naming.
rochamarcelo Jan 10, 2023
42cc3ef
Upgrade to CakePHP 5 - PHPStan Fixes
rochamarcelo Jan 10, 2023
cb2a3e8
Upgrade to CakePHP 5 - Improving migration guide
rochamarcelo Jan 11, 2023
4c6f75d
Upgrade to CakePHP 5 - Configure PHPCS
rochamarcelo Jan 12, 2023
d2939ba
Upgrade to CakePHP 5 - phpcs fixes
rochamarcelo Jan 12, 2023
59d49eb
Upgrade to CakePHP 5 - phpcs fixes
rochamarcelo Jan 12, 2023
bd12136
Upgrade to CakePHP 5 - phpcs fixes
rochamarcelo Jan 12, 2023
e1d56e6
Upgrade to CakePHP 5 - use correct phpcs standard
rochamarcelo Jan 12, 2023
3c656aa
Upgrade to CakePHP 5 - phpstan fix
rochamarcelo Jan 12, 2023
51405e8
Upgrade to CakePHP 5 - Migrating Webauthn 4.4 (3.x is not compatible)
rochamarcelo Jan 17, 2023
a26a909
Upgrade to CakePHP 5 - Migrating Webauthn 4.4 (3.x is not compatible)…
rochamarcelo Jan 17, 2023
60014e2
Upgrade to CakePHP 5 - Migrating Webauthn 4.4 (3.x is not compatible)…
rochamarcelo Jan 18, 2023
3cd598d
Upgrade to CakePHP 5 - Migrating Webauthn 4.4 (3.x is not compatible)…
rochamarcelo Jan 18, 2023
033eabb
Upgrade to CakePHP 5 - Added utilility for base64 compatibility with …
rochamarcelo Jan 19, 2023
e7611a9
Upgrade to CakePHP 5 - phpcs fixes
rochamarcelo Jan 19, 2023
f4b6609
Upgrade to CakePHP 5 - phpcs fix
rochamarcelo Jan 19, 2023
00c5275
Upgrade to CakePHP 5 - Use correct class for basic base65 enccoding|d…
rochamarcelo Jan 19, 2023
9d27bb0
Upgrade to CakePHP 5 - Fixed and improved unit tests
rochamarcelo Jan 19, 2023
a28088c
Upgrade to CakePHP 5 - Use cakedc/auth":"8.next-cake5-dev" from main …
rochamarcelo Jan 19, 2023
9e8be72
Upgrade to CakePHP 5 - Migrating Webauthn 4.4 (3.x is not compatible)…
rochamarcelo Jan 20, 2023
c2dc100
Upgrade to CakePHP 5 - Migrating Webauthn 4.4 (3.x is not compatible)…
rochamarcelo Jan 20, 2023
c403b42
Upgrade to CakePHP 5 - phpstan fix
rochamarcelo Jan 20, 2023
8729bc3
Upgrade to CakePHP 5 - Migrating Webauthn 4.4 (3.x is not compatible)…
rochamarcelo Jan 20, 2023
f3fb3d1
Upgrade to CakePHP 5 - Migrating Webauthn 4.4 (3.x is not compatible)…
rochamarcelo Jan 21, 2023
14e5176
Upgrade to CakePHP 5 - cleanup
rochamarcelo Jan 21, 2023
b06cb42
Upgrade to CakePHP 5 - Fixing unit tests
rochamarcelo Jan 21, 2023
e1eed27
Upgrade to CakePHP 5 - fixing unit tests
rochamarcelo Jan 21, 2023
4ac4946
Upgrade to CakePHP 5 - phpcs fixes
rochamarcelo Jan 21, 2023
ad9aa01
Upgrade to CakePHP 5 - phpstan fixes
rochamarcelo Jan 21, 2023
529e82f
Upgrade to CakePHP 5 - fixed annotations
rochamarcelo Jan 21, 2023
1c6fd55
Merge remote-tracking branch '11.next-cake4' into cake5
rochamarcelo Jan 21, 2023
a440c83
Upgrade to CakePHP 5 - fix test
rochamarcelo Jan 21, 2023
0543313
Upgrade to CakePHP 5 - cleanup
rochamarcelo Jan 21, 2023
9114a44
Upgrade to CakePHP 5 - Re-added file
rochamarcelo Jan 21, 2023
4a54ddd
Upgrade to CakePHP 5 - cleanup
rochamarcelo Jan 30, 2023
20d1243
Upgrade to CakePHP 5 - cleanup
rochamarcelo Jan 30, 2023
bebd019
Upgrade to CakePHP 5 - cleanup
rochamarcelo Jan 30, 2023
ecef100
Upgrade to CakePHP 5 - Updated doc with info about FormProtection and…
rochamarcelo Jan 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ['7.3', '7.4', '8.0', '8.1']
php-version: ['8.1', '8.2']
db-type: [sqlite, mysql, pgsql]
prefer-lowest: ['']

Expand Down Expand Up @@ -59,22 +59,22 @@ jobs:
fi

- name: Setup problem matchers for PHPUnit
if: matrix.php-version == '7.4' && matrix.db-type == 'mysql'
if: matrix.php-version == '8.1' && matrix.db-type == 'mysql'
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Run PHPUnit
run: |
if [[ ${{ matrix.db-type }} == 'sqlite' ]]; then export DB_URL='sqlite:///:memory:'; fi
if [[ ${{ matrix.db-type }} == 'mysql' ]]; then export DB_URL='mysql://root:[email protected]/cakephp?encoding=utf8'; fi
if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then export DB_URL='postgres://postgres:[email protected]/postgres'; fi
if [[ ${{ matrix.php-version }} == '7.4' ]]; then
if [[ ${{ matrix.php-version }} == '8.1' ]]; then
export CODECOVERAGE=1 && vendor/bin/phpunit --verbose --coverage-clover=coverage.xml
else
vendor/bin/phpunit
fi

- name: Submit code coverage
if: matrix.php-version == '7.4'
if: matrix.php-version == '8.1'
uses: codecov/codecov-action@v1

cs-stan:
Expand All @@ -87,7 +87,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.3'
php-version: '8.1'
extensions: mbstring, intl, apcu
coverage: none

Expand Down
16 changes: 16 additions & 0 deletions Docs/Documentation/Migration/11.x-12.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Migration 11.x to 12.0
======================

12.0 is compatible with CakePHP ^5.0

Requirements
------------
- php >=8.1
- CakePHP 5
- cakephp/authentication 3
- cakephp/authorization 3

Overview
--------
- Removed the deprecated config key `'Auth.authenticate.all.contain'` you should use `'Auth.Profile.contain'` instead.
- UsersShell logic was migrated into commands classes.
23 changes: 11 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=7.2.0",
"cakephp/cakephp": "^4.0",
"cakedc/auth": "^7.0",
"cakephp/authorization": "^2.0.0",
"cakephp/authentication": "^2.0.0"
"php": ">=8.1",
"cakephp/cakephp": "5.x-dev",
"cakedc/auth": "8.next-cake5-dev",
"cakephp/authorization": "3.x-dev",
"cakephp/authentication": "3.x-dev"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"phpunit/phpunit": "^9.5.16",
"league/oauth2-facebook": "@stable",
"league/oauth2-instagram": "@stable",
"league/oauth2-google": "@stable",
Expand All @@ -45,10 +45,9 @@
"google/recaptcha": "@stable",
"robthree/twofactorauth": "^1.6",
"yubico/u2flib-server": "^1.0",
"php-coveralls/php-coveralls": "^2.1",
"league/oauth1-client": "^1.7",
"cakephp/cakephp-codesniffer": "^4.0",
"web-auth/webauthn-lib": "^3.3",
"cakephp/cakephp-codesniffer": "^5.0",
"web-auth/webauthn-lib": "^4.4",
"thenetworg/oauth2-azure": "^2.1"
},
"suggest": {
Expand Down Expand Up @@ -85,12 +84,12 @@
"@test",
"@analyse"
],
"cs-check": "phpcs -n -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests",
"cs-fix": "phpcbf --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests",
"cs-check": "phpcs -n -p ./src ./tests",
"cs-fix": "phpcbf ./src ./tests",
"test": "phpunit --stderr",
"stan": "phpstan analyse src/",
"psalm": "php vendor/psalm/phar/psalm.phar --show-info=false src/ ",
"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:0.12.94 psalm/phar:~4.9.2 && mv composer.backup composer.json",
"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:~1.9.0 psalm/phar:~5.1.0 && mv composer.backup composer.json",
"stan-rebuild-baseline": "phpstan analyse --configuration phpstan.neon --error-format baselineNeon src/ > phpstan-baseline.neon",
"psalm-rebuild-baseline": "php vendor/psalm/phar/psalm.phar --show-info=false --set-baseline=psalm-baseline.xml src/",
"rector": "rector process src/",
Expand Down
2 changes: 1 addition & 1 deletion config/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
'enabled' => false,
'appName' => null,//App must set a valid name here
'id' => null,//default value is the current domain
'checker' => \CakeDC\Auth\Authentication\DefaultWebauthn2fAuthenticationChecker::class,
'checker' => \CakeDC\Auth\Authentication\DefaultWebauthn2FAuthenticationChecker::class,
],
// default configuration used to auto-load the Auth Component, override to change the way Auth works
'Auth' => [
Expand Down
11 changes: 11 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<ruleset name="App">
<config name="installed_paths" value="../../cakephp/cakephp-codesniffer"/>

<rule ref="CakePHP">
<exclude name="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName"/>
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint"/>
</rule>
</ruleset>
45 changes: 0 additions & 45 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,6 @@ parameters:
count: 1
path: src/Controller/UsersController.php

-
message: "#^Parameter \\#1 \\$message of method Cake\\\\Controller\\\\Controller\\:\\:log\\(\\) expects string, Exception given\\.$#"
count: 1
path: src/Controller/UsersController.php

-
message: "#^Parameter \\#1 \\$object of method Cake\\\\Controller\\\\Controller\\:\\:paginate\\(\\) expects Cake\\\\ORM\\\\Query\\|Cake\\\\ORM\\\\Table\\|string\\|null, Cake\\\\Datasource\\\\RepositoryInterface given\\.$#"
count: 1
path: src/Controller/UsersController.php

-
message: "#^Parameter \\#2 \\$options of method Cake\\\\Controller\\\\Component\\\\FlashComponent\\:\\:error\\(\\) expects array, string given\\.$#"
count: 1
Expand Down Expand Up @@ -190,31 +180,11 @@ parameters:
count: 1
path: src/Model/Behavior/RegisterBehavior.php

-
message: "#^Cannot call method tokenExpired\\(\\) on array\\|Cake\\\\Datasource\\\\EntityInterface\\.$#"
count: 1
path: src/Model/Behavior/RegisterBehavior.php

-
message: "#^Access to an undefined property CakeDC\\\\Users\\\\Model\\\\Entity\\\\SocialAccount\\:\\:\\$active\\.$#"
count: 1
path: src/Model/Behavior/SocialAccountBehavior.php

-
message: "#^Cannot access property \\$active on array\\|Cake\\\\Datasource\\\\EntityInterface\\.$#"
count: 2
path: src/Model/Behavior/SocialAccountBehavior.php

-
message: "#^Cannot access property \\$token on array\\|Cake\\\\Datasource\\\\EntityInterface\\.$#"
count: 1
path: src/Model/Behavior/SocialAccountBehavior.php

-
message: "#^Cannot access property \\$user on array\\|Cake\\\\Datasource\\\\EntityInterface\\.$#"
count: 1
path: src/Model/Behavior/SocialAccountBehavior.php

-
message: "#^Method CakeDC\\\\Users\\\\Model\\\\Behavior\\\\SocialAccountBehavior\\:\\:resendValidation\\(\\) should return CakeDC\\\\Users\\\\Model\\\\Entity\\\\User but returns array\\.$#"
count: 1
Expand All @@ -225,11 +195,6 @@ parameters:
count: 1
path: src/Model/Behavior/SocialAccountBehavior.php

-
message: "#^Parameter \\#1 \\$socialAccount of method CakeDC\\\\Users\\\\Model\\\\Behavior\\\\SocialAccountBehavior\\:\\:_activateAccount\\(\\) expects CakeDC\\\\Users\\\\Model\\\\Entity\\\\SocialAccount, array\\|Cake\\\\Datasource\\\\EntityInterface given\\.$#"
count: 1
path: src/Model/Behavior/SocialAccountBehavior.php

-
message: "#^Access to an undefined property Cake\\\\ORM\\\\Table\\:\\:\\$SocialAccounts\\.$#"
count: 4
Expand All @@ -250,16 +215,6 @@ parameters:
count: 1
path: src/Model/Entity/User.php

-
message: "#^Cannot access property \\$username on bool\\.$#"
count: 2
path: src/Shell/UsersShell.php

-
message: "#^Property CakeDC\\\\Users\\\\Shell\\\\UsersShell\\:\\:\\$Users \\(CakeDC\\\\Users\\\\Model\\\\Table\\\\UsersTable\\) does not accept Cake\\\\Datasource\\\\RepositoryInterface\\.$#"
count: 1
path: src/Shell/UsersShell.php

-
message: "#^Parameter \\#2 \\$usersTable of class CakeDC\\\\Users\\\\Webauthn\\\\Repository\\\\UserCredentialSourceRepository constructor expects CakeDC\\\\Users\\\\Model\\\\Table\\\\UsersTable\\|null, Cake\\\\ORM\\\\Table given\\.$#"
count: 1
Expand Down
1 change: 0 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<issueHandlers>
<LessSpecificReturnType errorLevel="info" />
<RedundantConditionGivenDocblockType errorLevel="info" />
<TypeCoercion errorLevel="info" />
<DocblockTypeContradiction errorLevel="info" />
</issueHandlers>
</psalm>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/Authenticator/SocialAuthTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ trait SocialAuthTrait
* @param array $rawData social user raw data
* @return \Authentication\Authenticator\Result
*/
protected function identify($rawData)
protected function identify($rawData): Result
{
try {
$user = $this->getIdentifier()->identify([SocialIdentifier::CREDENTIAL_KEY => $rawData]);
Expand Down
2 changes: 1 addition & 1 deletion src/Authenticator/SocialPendingEmailAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class SocialPendingEmailAuthenticator extends AbstractAuthenticator
*
* @var array
*/
protected $_defaultConfig = [
protected array $_defaultConfig = [
'loginUrl' => [
'plugin' => 'CakeDC/Users',
'controller' => 'Users',
Expand Down
33 changes: 33 additions & 0 deletions src/Command/Logic/ChangeUserActiveTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);

namespace CakeDC\Users\Command\Logic;

use Cake\Console\Arguments;
use Cake\Console\ConsoleIo;

trait ChangeUserActiveTrait
{
use UpdateUserTrait;

/**
* Change user active field
*
* @param \Cake\Console\Arguments $args The command arguments.
* @param \Cake\Console\ConsoleIo $io The console io
* @param bool $active active value
* @return \CakeDC\Users\Model\Entity\User
*/
protected function _changeUserActive(Arguments $args, ConsoleIo $io, $active)
{
$username = $args->getArgumentAt(0);
if (empty($username)) {
$io->abort(__d('cake_d_c/users', 'Please enter a username.'));
}
$data = [
'active' => $active,
];

return $this->_updateUser($io, $username, $data);
}
}
126 changes: 126 additions & 0 deletions src/Command/Logic/CreateUserTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?php
declare(strict_types=1);

namespace CakeDC\Users\Command\Logic;

use Cake\Console\Arguments;
use Cake\Console\ConsoleIo;
use Cake\Console\ConsoleOptionParser;
use Cake\ORM\Locator\LocatorAwareTrait;
use Cake\Utility\Text;

trait CreateUserTrait
{
use LocatorAwareTrait;

/**
* Work as a seed for username generator
*
* @var array
*/
protected array $_usernameSeed = [
'aayla', 'admiral', 'anakin', 'chewbacca',
'darthvader', 'hansolo', 'luke', 'obiwan', 'leia', 'r2d2',
];

/**
* Hook method for defining this command's option parser.
*
* @see https://book.cakephp.org/4/en/console-commands/commands.html#defining-arguments-and-options
* @param \Cake\Console\ConsoleOptionParser $parser The parser to be defined
* @return \Cake\Console\ConsoleOptionParser The built parser.
*/
public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
{
$parser = parent::buildOptionParser($parser);

return $parser
->addOptions([
'username' => ['short' => 'u', 'help' => 'The username for the new user'],
'password' => ['short' => 'p', 'help' => 'The password for the new user'],
'email' => ['short' => 'e', 'help' => 'The email for the new user'],
'role' => ['short' => 'r', 'help' => 'The role for the new user'],
]);
}

/**
* Create a new user or superuser
*
* @param \Cake\Console\Arguments $args The command arguments.
* @param \Cake\Console\ConsoleIo $io The console io
* @param array $template template with deafault user values
* @return void
*/
protected function _createUser(Arguments $args, ConsoleIo $io, $template)
{
/**
* @var \CakeDC\Users\Model\Table\UsersTable $UsersTable
*/
$UsersTable = $this->getTableLocator()->get('Users');
$username = $args->getOption('username');
$password = $args->getOption('password');
$email = $args->getOption('email');
$role = $args->getOption('role');
if (empty($username)) {
$username = empty($template['username'])
? $this->_generateRandomUsername()
: $template['username'];
}

$password = $password ?: $this->_generateRandomPassword();
$email = $email ?: $username . '@example.com';
$role = $role ?: $template['role'];

$user = [
'username' => $UsersTable->generateUniqueUsername($username),
'email' => $email,
'password' => $password,
'active' => 1,
];

$userEntity = $UsersTable->newEntity($user);
$userEntity->is_superuser = empty($template['is_superuser']) ?
false : $template['is_superuser'];
$userEntity->role = $role;
$savedUser = $UsersTable->save($userEntity);

if (is_object($savedUser)) {
if ($savedUser->is_superuser) {
$io->out(__d('cake_d_c/users', 'Superuser added:'));
} else {
$io->out(__d('cake_d_c/users', 'User added:'));
}
$io->out(__d('cake_d_c/users', 'Id: {0}', $savedUser->id));
$io->out(__d('cake_d_c/users', 'Username: {0}', $savedUser->username));
$io->out(__d('cake_d_c/users', 'Email: {0}', $savedUser->email));
$io->out(__d('cake_d_c/users', 'Role: {0}', $savedUser->role));
$io->out(__d('cake_d_c/users', 'Password: {0}', $password));
} else {
$io->out(__d('cake_d_c/users', 'User could not be added:'));

collection($userEntity->getErrors())->each(function ($error, $field) use ($io) {
$io->out(__d('cake_d_c/users', 'Field: {0} Error: {1}', $field, implode(',', $error)));
});
}
}

/**
* Generates a random password.
*
* @return string
*/
protected function _generateRandomPassword()
{
return str_replace('-', '', Text::uuid());
}

/**
* Generates a random username based on a list of preexisting ones.
*
* @return string
*/
protected function _generateRandomUsername()
{
return $this->_usernameSeed[array_rand($this->_usernameSeed)];
}
}
Loading