-
Notifications
You must be signed in to change notification settings - Fork 120
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
[NEW UI] add middleware system and first middleware on update options page #1136
Merged
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6bf5771
feat: add first middleware for update version choice page
ga-devfront 99b39b9
fix: cs fixer
ga-devfront 8544bae
feat: add middleware tests
ga-devfront 665ada3
fix: review from feedbacks
ga-devfront 049fc74
fix: cs fixer
ga-devfront ff6ccf1
Update mock of upgrade container
Quetzacoalt91 3f9d2ea
fix: rename Middleware to MiddlewareHandler
ga-devfront b5f4fd6
fix: remove useless var string comment
ga-devfront 1250c4f
fix: change route condition regarding review comment
ga-devfront 545d304
feat: cancel usage of middleware after redirection
ga-devfront 1cfc35d
fix: cs fixer
ga-devfront File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace PrestaShop\Module\AutoUpgrade\Router; | ||
|
||
use PrestaShop\Module\AutoUpgrade\UpgradeContainer; | ||
|
||
class Middleware | ||
{ | ||
/** | ||
* @var UpgradeContainer | ||
*/ | ||
protected $upgradeContainer; | ||
|
||
public function __construct(UpgradeContainer $upgradeContainer) | ||
{ | ||
$this->upgradeContainer = $upgradeContainer; | ||
} | ||
|
||
/** | ||
* @param Routes::* $routeName | ||
* | ||
* @return Routes::* | ||
*/ | ||
public function process(string $routeName): string | ||
{ | ||
$route = RoutesConfig::ROUTES[$routeName]; | ||
$routeMiddlewares = $route['middleware'] ?? []; | ||
|
||
$nextRoute = $routeName; | ||
|
||
foreach ($routeMiddlewares as $middleware) { | ||
$processedRoute = (new $middleware($this->upgradeContainer))->process(); | ||
|
||
if ($processedRoute !== null) { | ||
$nextRoute = $processedRoute; | ||
break; | ||
} | ||
} | ||
|
||
return $nextRoute; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace PrestaShop\Module\AutoUpgrade\Router\Middlewares; | ||
|
||
use PrestaShop\Module\AutoUpgrade\UpgradeContainer; | ||
|
||
abstract class AbstractMiddleware | ||
{ | ||
/** | ||
* @var UpgradeContainer | ||
*/ | ||
protected $upgradeContainer; | ||
|
||
public function __construct(UpgradeContainer $upgradeContainer) | ||
{ | ||
$this->upgradeContainer = $upgradeContainer; | ||
} | ||
|
||
abstract public function process(): ?string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace PrestaShop\Module\AutoUpgrade\Router\Middlewares; | ||
|
||
use PrestaShop\Module\AutoUpgrade\Router\Routes; | ||
|
||
class LocalChannelXmlAndZipExist extends AbstractMiddleware | ||
{ | ||
/** | ||
* @return Routes::*|null | ||
* | ||
* @throws \Exception | ||
*/ | ||
public function process(): ?string | ||
{ | ||
$updateConfiguration = $this->upgradeContainer->getUpdateConfiguration(); | ||
|
||
if ($updateConfiguration->isChannelLocal()) { | ||
$errors = $this->upgradeContainer->getLocalChannelConfigurationValidator()->validate($updateConfiguration->toArray()); | ||
|
||
if (!empty($errors)) { | ||
return Routes::UPDATE_PAGE_VERSION_CHOICE; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,14 @@ | ||||||||||||
<?php | ||||||||||||
|
||||||||||||
namespace PrestaShop\Module\AutoUpgrade\Router\Middlewares; | ||||||||||||
|
||||||||||||
use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeFileNames; | ||||||||||||
use PrestaShop\Module\AutoUpgrade\Router\Routes; | ||||||||||||
|
||||||||||||
class UpdateIsConfigured extends AbstractMiddleware | ||||||||||||
{ | ||||||||||||
public function process(): ?string | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
{ | ||||||||||||
return $this->upgradeContainer->getFileStorage()->exists(UpgradeFileNames::UPDATE_CONFIG_FILENAME) ? null : Routes::UPDATE_PAGE_VERSION_CHOICE; | ||||||||||||
} | ||||||||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The validation function does more than just check the presence of the zip/xml pair, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes and no, it check validty only if we are on channel local.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for me in addition to validating the presence of files, it also validates the presence of versions and the match of this one. So the middleware doesn't really reflect what is being done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You think
LocalChannelXmlAndZipAreValid
is better ?