-
Notifications
You must be signed in to change notification settings - Fork 111
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
Add feature to disable modules #340
Conversation
…ble custom modules
…, add originalVersion in the state
classes/Module/ModuleRepository.php
Outdated
public function getCustomModulesOnDisk($versions) | ||
{ | ||
$modulesOnDisk = $this->getModulesOnDisk(); | ||
$nativeModules = array(); |
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.
Don't mix short array and array
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.
Right! I'm used to short array now, but in this module I think use the array()
notation since we're not sure of the PHP version? wdyt?
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.
Short array came with 5.4 and this module require 5.6+.
classes/Module/AddonsCurlClient.php
Outdated
/** | ||
* Class AddonsCurlClient is a simple Addons client that uses Curl to perform its request. | ||
*/ | ||
class AddonsCurlClient implements AddonsClientInterface |
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.
Is this class a copy from the Core?
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.
Not an exact copy, but the code comes from the core yes, but I prefer to have a dedicated class to manage this call inside the module. Since we don't know on which version the module is installed we can't rely on the core classes because they are modified from a version to another.
I think that's why the Tools
class was copied in Tools14
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.
By the way I think I copied this code from the Tools
class but I can't remember which version (since I was working on different versions at the moment). I also removed a few switch cases because the API simply didn't work with these parameters.
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.
I was only asking because of snake case and some parts about services
and hosted_module
😅
classes/Module/ModuleRepository.php
Outdated
$disabledModulesDir, | ||
AddonsClientInterface $addonsClient | ||
) { | ||
$this->modulesDir = rtrim($modulesDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; |
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.
Better to not use DIRECTORY_SEPARATOR
constant in PHP.
If you use DIRECTORY_SEPARATOR, which resolves to \ on windows, things tend to break. For example:\ gets converted to %5C in urls.
classes/State.php
Outdated
*/ | ||
public function setOriginVersion($originVersion) | ||
{ | ||
$this->originVersion = $originVersion; |
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.
$this->originVersion = $originVersion; | |
$this->originVersion = (string) $originVersion; |
deactivate_custom_modules(); | ||
$customModules = $this->moduleRepository->getCustomModulesOnDisk([$this->originVersion, $this->upgradeVersion]); | ||
foreach ($customModules as $moduleName) { | ||
$this->moduleDisabler->disableModuleFromDatabase($moduleName); |
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.
Since this class is not final, always prefer getter function
$this->moduleDisabler->disableModuleFromDatabase($moduleName); | |
$this->getModuleDisabler()->disableModuleFromDatabase($moduleName); |
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.
In case it's overridden?
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, even for us we we have another Disabler based on this class. If we have setter / getter, always prefer them.
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.
Hi @PierreRambaud
Thanks for the review, I have a few answers/questions for you ;)
classes/Module/AddonsCurlClient.php
Outdated
/** | ||
* Class AddonsCurlClient is a simple Addons client that uses Curl to perform its request. | ||
*/ | ||
class AddonsCurlClient implements AddonsClientInterface |
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.
Not an exact copy, but the code comes from the core yes, but I prefer to have a dedicated class to manage this call inside the module. Since we don't know on which version the module is installed we can't rely on the core classes because they are modified from a version to another.
I think that's why the Tools
class was copied in Tools14
classes/Module/AddonsCurlClient.php
Outdated
/** | ||
* Class AddonsCurlClient is a simple Addons client that uses Curl to perform its request. | ||
*/ | ||
class AddonsCurlClient implements AddonsClientInterface |
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.
By the way I think I copied this code from the Tools
class but I can't remember which version (since I was working on different versions at the moment). I also removed a few switch cases because the API simply didn't work with these parameters.
deactivate_custom_modules(); | ||
$customModules = $this->moduleRepository->getCustomModulesOnDisk([$this->originVersion, $this->upgradeVersion]); | ||
foreach ($customModules as $moduleName) { | ||
$this->moduleDisabler->disableModuleFromDatabase($moduleName); |
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.
In case it's overridden?
ping @Quetzacoalt91 Can you also have a check on it? |
break; | ||
|
||
break; |
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.
Why 2 break ?
private function parseRequest($requestContent) | ||
{ | ||
if (empty($requestContent)) { | ||
false; |
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.
false; | |
return false; |
@@ -0,0 +1,33 @@ | |||
<?php | |||
/** | |||
* 2007-2019 PrestaShop SA and Contributors |
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.
Please update headers
* | ||
* @return self | ||
*/ | ||
public function setOriginVersion($originVersion) |
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.
public function setOriginVersion($originVersion) | |
public function setOriginVersion(string $originVersion) |
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.
We can't do this kind of changes in the autoupgrade module, it must be compatible with older PS versions :)
Ping @jolelievre |
<a target="_blank" href="{{ link.getAdminLink('AutoupgradeModule') }}&version=1.6.1">List modules 1.6.1</a> | ||
<a target="_blank" href="{{ link.getAdminLink('AutoupgradeModule') }}&version=1.7.6">List modules 1.7.6</a> |
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.
<a target="_blank" href="{{ link.getAdminLink('AutoupgradeModule') }}&version=1.6.1">List modules 1.6.1</a> | |
<a target="_blank" href="{{ link.getAdminLink('AutoupgradeModule') }}&version=1.7.6">List modules 1.7.6</a> | |
<a target="_blank" href="{{ link.getAdminLink('AutoupgradeModule') }}&version=1.6.1">List modules 1.6.1</a> | |
<a target="_blank" href="{{ link.getAdminLink('AutoupgradeModule') }}&version=1.7.6">List modules 1.7.6</a> |
{ | ||
parent::setUp(); | ||
$this->fileSystem = new Filesystem(); | ||
$this->tempDir = sys_get_temp_dir() . '/module_disabler'; |
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.
Just notice you should use a test directory, instead of the system directory, some container doesn't have /tmp 😅
Hi @jolelievre Since we had no news from you for more than 30 days (and some more), I will follow our guidelines and I'll close this pull request as it seems stale. Feel free to reopen or open another one if you think it's still relevant 😉 Thanks! |
This PR fixes the issue PrestaShop/PrestaShop#14779
The module can now disable custom modules by moving them into another folder
This feature was added inside the CoreUpgrader (bound to an option "Disable non native modules"
And a new controller was aded so that this new feature can be used via an API