├── .github
├── ISSUE_TEMPLATE
│ ├── bug_report.yml
│ ├── enhancement.yml
│ └── feature_request.yml
├── dependabot.yml
├── pre-commit
└── workflows
│ └── php.yml
├── .gitignore
├── COMMANDS.md
├── CONTRIBUTE.md
├── LICENCE.md
├── README.md
├── bin
├── phar
│ ├── box.phar
│ ├── consolePhar.php
│ └── current.version
└── prestashopConsole.phar
├── box.json
├── build.php
├── changelog.txt
├── composer.json
├── composer.lock
├── config.php
├── console.php
├── console.png
├── examples
└── configuration.mass.yml
├── index.php
├── phpstan.neon.dist
├── prestashopConsoleWrapper.php
└── src
└── Hhennes
└── PrestashopConsole
├── Command
├── Admin
│ └── User
│ │ ├── CreateCommand.php
│ │ ├── ListCommand.php
│ │ └── PasswordCommand.php
├── Analyze
│ ├── GlobalCommand.php
│ ├── ListCarriersCommand.php
│ ├── ListPaymentsCommand.php
│ ├── TablesSizeCommand.php
│ └── WebsiteCommand.php
├── Cache
│ ├── CleanCommand.php
│ ├── ClearAllCommand.php
│ ├── FlushCommand.php
│ ├── MediaCommand.php
│ └── Smarty
│ │ ├── ClearCommand.php
│ │ └── ConfigureCommand.php
├── Configuration
│ ├── DeleteCommand.php
│ ├── GetAllCommand.php
│ ├── GetCommand.php
│ ├── MassCommand.php
│ └── SetCommand.php
├── Console
│ ├── CreateCommand.php
│ └── SelfUpdateCommand.php
├── Db
│ ├── ExportCommand.php
│ ├── ImportCommand.php
│ └── QueryCommand.php
├── Dev
│ ├── AddIndexFilesCommand.php
│ ├── AnonymizeCustomerCommand.php
│ ├── ChangeShopDomainCommand.php
│ ├── Clean
│ │ ├── CleanCommand.php
│ │ └── CleanCommandAbstract.php
│ ├── Cron
│ │ ├── ListCronCommand.php
│ │ └── RunCronCommand.php
│ ├── DevModeCommand.php
│ ├── IdeClassNamesCommand.php
│ └── ListOverridesCommand.php
├── Hook
│ ├── ListCommand.php
│ └── ModuleCommand.php
├── Images
│ ├── ExportCommand.php
│ ├── GenerateAbstract.php
│ ├── GenerateCategoriesCommand.php
│ ├── GenerateManufacturersCommand.php
│ ├── GenerateProductsCommand.php
│ ├── GenerateStoresCommand.php
│ └── GenerateSuppliersCommand.php
├── Install
│ ├── InfoCommand.php
│ └── InstallCommand.php
├── Module
│ ├── DisableCommand.php
│ ├── EnableCommand.php
│ ├── Generate
│ │ ├── ControllerCommand.php
│ │ ├── ModuleCommand.php
│ │ ├── ModuleHeader.php
│ │ ├── ObjectModelCommand.php
│ │ └── UpgradeCommand.php
│ ├── Hook
│ │ ├── AddModuleHooksCommand.php
│ │ ├── ListModuleHooksCommand.php
│ │ └── RemoveModuleHooksCommand.php
│ ├── InstallCommand.php
│ ├── ListCommand.php
│ ├── ResetCommand.php
│ ├── Tab
│ │ ├── AddCommand.php
│ │ ├── ListCommand.php
│ │ └── RemoveCommand.php
│ └── UninstallCommand.php
├── Parameters
│ └── Generate
│ │ ├── HtaccessCommand.php
│ │ └── RobotsTxtCommand.php
├── Preferences
│ ├── CmsCategoryCommand.php
│ ├── CmsCommand.php
│ ├── MaintenanceCommand.php
│ ├── OverrideCommand.php
│ ├── Search
│ │ └── IndexCommand.php
│ └── UrlRewriteCommand.php
└── Webservice
│ ├── CreateKeyCommand.php
│ └── DeleteKeyCommand.php
└── PrestashopConsoleApplication.php
/.github/ISSUE_TEMPLATE/bug_report.yml:
--------------------------------------------------------------------------------
1 | name: Bug report
2 | description: You've got a problem with this module, open a new issue
3 | assignees: nenes25
4 | labels: ['bug']
5 | body:
6 | - type: markdown
7 | attributes:
8 | value: |
9 | Thank you for using the module and reporting an issue
10 | In order to allow us to help you, please fill the following fields
11 | - type: dropdown
12 | id: psconsoleversion
13 | attributes:
14 | label: PrestashopConsole
15 | description: Your prestashopConsole version
16 | multiple: false
17 | options:
18 | - 1.6.x
19 | - 2.0.x
20 | validations:
21 | required: true
22 | - type: dropdown
23 | id: prestashop_version
24 | attributes:
25 | label: Your prestashop version
26 | description: Wich version of prestashop are you using ( Only currently supported versions are listed )
27 | multiple: false
28 | options:
29 | - < 1.7
30 | - 1.7.2.x
31 | - 1.7.3.x
32 | - 1.7.4.x
33 | - 1.7.5.x
34 | - 1.7.6.x
35 | - 1.7.7.x
36 | - 1.7.8.x
37 | validations:
38 | required: true
39 | - type: dropdown
40 | id: php_version
41 | attributes:
42 | label: Php Version
43 | description: Your server php version ( Only currently supported versions are listed )
44 | multiple: false
45 | options:
46 | - 5.6
47 | - 7.0
48 | - 7.1
49 | - 7.2
50 | - 7.3
51 | - 7.4
52 | validations:
53 | required: true
54 | - type: textarea
55 | attributes:
56 | label: Describe the bug
57 | placeholder: A clear and concise description of what the bug is.
58 | validations:
59 | required: true
60 | - type: textarea
61 | attributes:
62 | label: Additional context
63 | placeholder: Add any other context about the problem here.
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/enhancement.yml:
--------------------------------------------------------------------------------
1 | name: Enhancement
2 | description: Ask for an enhancement on a command or to the project
3 | assignees: nenes25
4 | labels: ['enhancement']
5 | body:
6 | - type: markdown
7 | attributes:
8 | value: |
9 | Thank you for using the module and reporting an issue
10 | In order to allow us to help you, please fill the following fields
11 | - type: dropdown
12 | id: psconsoleversion
13 | attributes:
14 | label: PrestashopConsole
15 | description: Your prestashopConsole version
16 | multiple: false
17 | options:
18 | - 1.6.x
19 | - 2.0.x
20 | validations:
21 | required: true
22 | - type: dropdown
23 | id: command_or_global
24 | attributes:
25 | label: Related to command or global ?
26 | description: describe if your enhancement is related to a specific command or global
27 | multiple: false
28 | options:
29 | - command
30 | - global
31 | validations:
32 | required: true
33 | - type: textarea
34 | attributes:
35 | label: Enhancement description
36 | placeholder: Describe the enhancement suggestion
37 | validations:
38 | required: true
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.yml:
--------------------------------------------------------------------------------
1 | name: New Command request
2 | title: New Command CommandName
3 | description: Request the creation of a new command
4 | assignees: nenes25
5 | labels: ['enhancement']
6 | body:
7 | - type: markdown
8 | attributes:
9 | value: Ask for the creation of a new command in the tools.
10 | - type: dropdown
11 | id: psconsoleversion
12 | attributes:
13 | label: PrestashopConsole
14 | description: Targeted prestashopConsole version
15 | multiple: false
16 | options:
17 | - 1.6.x
18 | - 2.0.x
19 | validations:
20 | required: true
21 | - type: input
22 | attributes:
23 | label: Command name
24 | placeholder: sample:action
25 | validations:
26 | required: true
27 | - type: dropdown
28 | id: command_category
29 | attributes:
30 | label: Command category
31 | description: the command category
32 | multiple: false
33 | options:
34 | - admin
35 | - analyze
36 | - cache
37 | - configuration
38 | - console
39 | - db
40 | - dev
41 | - hook
42 | - images
43 | - module
44 | - other
45 | validations:
46 | required: true
47 | - type: textarea
48 | attributes:
49 | label: Command arguments
50 | placeholder: List the command arguments
51 | validations:
52 | required: true
53 | - type: textarea
54 | attributes:
55 | label: Command options
56 | placeholder: List the command options
--optionName _optionDescription_ (none / required / optional / is_array)
57 | - type: textarea
58 | attributes:
59 | label: Command return
60 | placeholder: "List what the command will return
success : _what command retrun in success_
error : _what command return in error_
void if nothing"
61 | - type: textarea
62 | attributes:
63 | label: Possible impacts?
64 | placeholder: Define possible impacts on current codebase.
65 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: composer
4 | directory: "/"
5 | schedule:
6 | interval: monthly
7 | time: "04:00"
8 | open-pull-requests-limit: 10
9 | versioning-strategy: increase-if-necessary
10 | ignore:
11 | - dependency-name: phpstan/phpstan
12 | versions:
13 | - 0.12.64
14 | - 0.12.70
15 | - dependency-name: prestashop/php-dev-tools
16 | versions:
17 | - "3.13"
18 | - dependency-name: symfony/lock
19 | versions:
20 | - 4.4.18
21 | - dependency-name: symfony/finder
22 | versions:
23 | - 4.4.18
24 | - dependency-name: symfony/yaml
25 | versions:
26 | - 4.4.18
27 | - dependency-name: symfony/filesystem
28 | versions:
29 | - 4.4.18
30 |
--------------------------------------------------------------------------------
/.github/pre-commit:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #Lint php files
4 | echo "Php 5.6 linter"
5 | PHP56VALID=$(find . -type f -name '*.php' ! -path "./src/vendor/*" ! -path "./tests/*" -exec php5.6 -l -n {} \; | (! grep -v "No syntax errors detected"))
6 | echo "Php 7.0 linter"
7 | PHP70VALID=$(find . -type f -name '*.php' ! -path "./src/vendor/*" ! -path "./tests/*" -exec php7.0 -l -n {} \; | (! grep -v "No syntax errors detected"))
8 | echo "Php 7.1 linter"
9 | PHP71VALID=$(find . -type f -name '*.php' ! -path "./src/vendor/*" ! -path "./tests/*" -exec php7.1 -l -n {} \; | (! grep -v "No syntax errors detected"))
10 | echo "Php 7.2 linter"
11 | PHP72VALID=$(find . -type f -name '*.php' ! -path "./src/vendor/*" ! -path "./tests/*" -exec php7.2 -l -n {} \; | (! grep -v "No syntax errors detected"))
12 | echo "Php 7.3 linter"
13 | PHP73VALID=$(find . -type f -name '*.php' ! -path "./src/vendor/*" ! -path "./tests/*" -exec php7.3 -l -n {} \; | (! grep -v "No syntax errors detected"))
14 |
15 | if [ ! -z "$PHP56VALID" ] || [ ! -z "$PHP70VALID" ] || [ ! -z "$PHP71VALID" ] || [ ! -z "$PHP72VALID" ] || [ ! -z "$PHP73VALID" ]
16 | then
17 | echo "Error in php syntax stop commit"
18 |
19 | if [ ! -z "$PHP56VALID" ]
20 | then
21 | echo "Php5.6 errors"
22 | echo $PHP56VALID
23 | fi
24 |
25 | if [ ! -z "$PHP70VALID" ]
26 | then
27 | echo "Php7.0 errors"
28 | echo $PHP70VALID
29 | fi
30 |
31 | if [ ! -z "$PHP71VALID" ]
32 | then
33 | echo "Php7.1 errors"
34 | echo $PHP71VALID
35 | fi
36 |
37 | if [ ! -z "$PHP72VALID" ]
38 | then
39 | echo "Php7.2 errors"
40 | echo $PHP72VALID
41 | fi
42 |
43 | if [ ! -z "$PHP73VALID" ]
44 | then
45 | echo "Php7.3 errors"
46 | echo $PHP73VALID
47 | fi
48 |
49 | #exit 0
50 | fi
51 |
52 | #Dev file not versionned
53 | devFile="console_dev.php"
54 | echo "Automatical actions before commit"
55 | echo "Creating phar file"
56 | php build.php
57 | git add bin/
58 |
59 | if [ -f "$devFile" ]; then
60 | echo "Generate documentation"
61 | php $devFile list --format=md > COMMANDS.md
62 | git add COMMANDS.md
63 | fi
64 |
65 |
--------------------------------------------------------------------------------
/.github/workflows/php.yml:
--------------------------------------------------------------------------------
1 | name: PHP tests
2 | on: [push, pull_request]
3 | jobs:
4 | php-linter:
5 | name: PHP Syntax check 5.6|7.2|7.3|7.4
6 | runs-on: ubuntu-latest
7 | steps:
8 | - name: PHP syntax checker 5.6
9 | uses: prestashop/github-action-php-lint/5.6@master
10 | - name: PHP syntax checker 7.2
11 | uses: prestashop/github-action-php-lint/7.2@master
12 | - name: PHP syntax checker 7.3
13 | uses: prestashop/github-action-php-lint/7.3@master
14 | - name: PHP syntax checker 7.4
15 | uses: prestashop/github-action-php-lint/7.4@master
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /config.xml
2 | /vendor/
3 | /src/vendor/
4 | /nbproject/
5 | /.github/config.php
6 | /console_dev.php
7 | /phpstan.neon
8 |
--------------------------------------------------------------------------------
/CONTRIBUTE.md:
--------------------------------------------------------------------------------
1 | If you want to add new functionnalities to the console it's quite simple :
2 |
3 | ## How to install it
4 | Go the root directory of your prestashop
5 |
6 | Clone the github repository in the directory console
7 | ```bash
8 | git clone https://github.com/nenes25/prestashop_console.git console
9 | ```
10 | Go into the directory and run composer install
11 | ```bash
12 | cd console
13 | composer install
14 | ```
15 | Then the tool is installed, and you can run the console with
16 | ```bash
17 | php console.php
18 | ```
19 |
20 | Create your new command in the path :
21 | src/Hhennes/Prestashop/Command/PSFUNCTIONNALITY/SampleCommand.php
22 | You can use the following code as an example:
23 |
24 |
25 | /**
26 | * 2007-2020 Hennes Hervé
27 | *
28 | * NOTICE OF LICENSE
29 | *
30 | * This source file is subject to the Open Software License (OSL 3.0)
31 | * that is bundled with this package in the file LICENSE.txt.
32 | * It is also available through the world-wide-web at this URL:
33 | * https://opensource.org/licenses/OSL-3.0
34 | * If you did not receive a copy of the license and are unable to
35 | * obtain it through the world-wide-web, please send an email
36 | * to contact@h-hennes.fr so we can send you a copy immediately.
37 | *
38 | * @author Yourname
39 | * @copyright 2007-2020 Yourname
40 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
41 | * https://github.com/nenes25/prestashop_console
42 | */
43 |
44 | namespace Hhennes\PrestashopConsole\Command\; //Complete the path here
45 |
46 | use Symfony\Component\Console\Command\Command;
47 | use Symfony\Component\Console\Input\InputArgument;
48 | use Symfony\Component\Console\Input\InputInterface;
49 | use Symfony\Component\Console\Input\InputOption;
50 | use Symfony\Component\Console\Output\OutputInterface;
51 |
52 | /**
53 | * Describe command action
54 | *
55 | * @author : Put your name here
56 | *
57 | */
58 | class ClearCommand extends Command
59 | {
60 |
61 | // Configure your command
62 | protected function configure()
63 | {
64 | }
65 |
66 | //Execute your command
67 | protected function execute(InputInterface $input, OutputInterface $output)
68 | {
69 | }
70 |
71 | }
72 |
73 |
74 | For example if your command deals with modules you can create it in :
75 | src/Hhennes/Prestashop/Command/Module/SampleCommand.php
76 |
77 | Your command then will be find automatically and then you can work on it.
78 |
79 | If you want to share your work please make a pull request on github :)
80 |
81 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PrestaShop Console
2 |
3 | [](https://github.com/nenes25/eicaptcha/stargazers)
4 | [](https://github.com/nenes25/eicaptcha/network)
5 | []()
6 |
7 | PrestaShop cli tools based on Symfony Console component
8 | You can read more about it : http://www.h-hennes.fr/blog/2016/05/19/console-prestashop/ (FR)
9 |
10 | 
11 |
12 | Releases
13 | ---
14 |
15 | You can download all the versions of the console (since 1.5) from the release page https://github.com/nenes25/prestashop_console/releases
16 |
17 | Compatibility
18 | ---
19 |
20 | | PrestaShop Version | Compatible |
21 | |--------------------| -----------|
22 | | 1.6.x and under | :x: |
23 | | 1.6.1.x | :heavy_check_mark: (some commands are not available)|
24 | | 1.7.0 to 1.7.8.x | :heavy_check_mark: |
25 | | 8+ | :heavy_check_mark: with php7.4 max |
26 |
27 | | Php Version | Compatible |
28 | |-------------|------------------------------|
29 | | 5.6 | :heavy_check_mark: |
30 | | 7.0 | :heavy_check_mark: |
31 | | 7.1 | :heavy_check_mark: |
32 | | 7.2 | :heavy_check_mark: |
33 | | 7.3 | :heavy_check_mark: |
34 | | 7.4 | :heavy_check_mark: |
35 | | 8.0 | :interrobang: Not yet tested |
36 | | 8.1 | :interrobang: Not yet tested |
37 |
38 | How to use it
39 | ---
40 |
41 | Download the file from github in your prestashop root directory (or from the release page):
42 |
43 | ```bash
44 | wget https://github.com/nenes25/prestashop_console/releases/latest/download/prestashopConsole.phar
45 | ```
46 |
47 | Add execution mode:
48 |
49 | ```bash
50 | chmod +x prestashopConsole.phar
51 | ```
52 |
53 | Run the console:
54 |
55 | ```bash
56 | ./prestashopConsole.phar
57 | ```
58 |
59 | You can also add the phar globaly by adding it in your /usr/local/bin directory:
60 |
61 | ```bash
62 | sudo mv prestashopConsole.phar /user/local/bin/prestashopConsole
63 | ```
64 |
65 | Then run it with (only work in PrestaShop root directories):
66 |
67 | ```bash
68 | prestashopConsole
69 | ```
70 |
71 | You can check the list of commands here: [commands](COMMANDS.md).
72 |
73 | If you want to contribute please see: [contribute](CONTRIBUTE.md).
74 |
75 | Browser version
76 | ---
77 |
78 | If no cli is available on your hosting, and if the php **exec** and **shell_exec** functions are enabled.
79 | You can use and download the file prestashopConsoleWrapper.php as a wrapper to run some commands directly from the browser.
80 | This wrapper is limited and cannot interact with the console.
81 | All parameters should be passed through the url
82 |
83 | Here are some examples :
84 | ```
85 | Show help of the command admin:user:list
86 | prestashopConsoleWrapper.php?command=admin:user:list&options[]=help
87 | List only active modules
88 | prestashopConsoleWrapper.php?command=module:list&options[]=active
89 | List only active modules not from prestashop
90 | prestashopConsoleWrapper.php?command=module:list&options[]=active&options[]=no-native
91 | ```
92 |
--------------------------------------------------------------------------------
/bin/phar/box.phar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nenes25/prestashop_console/9ded4eb83fc633e2b4d2ee23aef55b5becbbe5f5/bin/phar/box.phar
--------------------------------------------------------------------------------
/bin/phar/consolePhar.php:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 |
17 | * @copyright 2007-2020 Hennes Hervé
18 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
19 | * http://www.h-hennes.fr/blog/
20 | */
21 |
22 | //Autoload Composer
23 | require_once 'src/vendor/autoload.php';
24 |
25 | use Hhennes\PrestashopConsole\PrestashopConsoleApplication;
26 |
27 | //Console Application
28 | require_once 'config.php';
29 | $app = new PrestashopConsoleApplication($configuration['application']['name'], $configuration['application']['version']);
30 | // This script is contained in bin/phar directory so we need to get 2 level upper for the root directory
31 | $app->initializeForPharExecution(dirname(dirname(__DIR__)));
32 |
33 | //Autoload Prestashop
34 | if ( is_file('config/config.inc.php')) {
35 | include_once 'config/config.inc.php';
36 | $app->getDeclaredCommands();
37 | }
38 | //If no prestashop conf find, only allow to install Prestashop
39 | else {
40 | $app->registerInstallCommands();
41 | $app->setDefaultCommand('install:info');
42 | }
43 |
44 | //Application run
45 | $app->run();
--------------------------------------------------------------------------------
/bin/phar/current.version:
--------------------------------------------------------------------------------
1 | a9e86b70b889910c45184ef527b9550c5247cbed
--------------------------------------------------------------------------------
/bin/prestashopConsole.phar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nenes25/prestashop_console/9ded4eb83fc633e2b4d2ee23aef55b5becbbe5f5/bin/prestashopConsole.phar
--------------------------------------------------------------------------------
/box.json:
--------------------------------------------------------------------------------
1 | {
2 | "chmod": "0755",
3 | "directories": [
4 | "src/Hhennes"
5 | ],
6 | "finder": [
7 | {
8 | "name": "*.php",
9 | "exclude": ["Tests"],
10 | "in": "src/vendor"
11 | },
12 | {
13 | "name": "config.php",
14 | "in":"."
15 | }
16 | ],
17 | "main": "bin/phar/consolePhar.php",
18 | "output": "bin/prestashopConsole.phar",
19 | "stub": true
20 | }
21 |
--------------------------------------------------------------------------------
/build.php:
--------------------------------------------------------------------------------
1 |
21 | * @copyright 2013-2021 Hennes Hervé
22 | * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
23 | * http://www.h-hennes.fr/blog/
24 | */
25 | 2023-12-11 - V 1.6.6 : Fix compatibility with php < 7.1
26 | 2023-08-12 - V 1.6.5 : #245 New Command ChangeUrl
27 | #248 Harmonize Licence Headers
28 | 2022-03-22 - V 1.6.4 : #241 Unable to use db:export with custom mysql port
29 | #242 New Command analyze:tables:size
30 | #243 dev:add-index should not add index.php files in composer directory
31 | #244 Add configuration form when creating module
32 | 2021-12-10 - V 1.6.3 : #194 Check compatibility from php5.6 to php7.2
33 | #227 New Command analyze:carriers
34 | #228 New Command analyze:payments
35 | #232 Enhancement module:generate:controller
36 | #233 Provide verbose information when module controller is created
37 | #92 Improve module list ( add option to show id )
38 | #229 New Command analyse:website
39 | 2021-03-11 - V 1.6.2 : #142 Error when try to start by prestashopConsole command
40 | #170 Create Webservice key command
41 | #173 Change link in readme
42 | #175 New Command Webservice:key:delete
43 | #182 Fix PhpStan Errors
44 | #193 Anonymize command must also anonymize customer emails in sav
45 | Disable the install command which will be refactored in next version
46 | Branch 1.6 is the last branch which deals with Prestashop 1.6 and Php < 7.2
47 | Small improvements
48 | 2020-06-25 - V 1.6.1 : #106 Error in generate Images commands
49 | #107 Improve module:hook:list command
50 | #108 Update licence header for generated code
51 | #116 db:export allow to define file name
52 | 2020-04-07 - V 1.6.0 : Improve code quality
53 | New commands to generate htaccess and robots.txt files
54 | New commands to list hooks (global or with modules)
55 | New command to generate images thumbnails
56 | New command to generate console command
57 | New command to export images
58 | Allow to rename phar file
59 | 2019-12-01 - V 1.5.0 : New commands for db interactions
60 | New command to list admin users
61 | Add pre-commit hook to automatically build phar and update documentation
62 | New commands to manage module admin tabs
63 | 2019-05-10 - V 1.4.2 : Module generation improvement ( objectmodel )
64 | 2019-04-16 - V 1.4.1 : Module generation improvement
65 | 2019-03-11 - V 1.4.0 : New commands to generate module files ( declaration, controllers , upgrade )
66 | 2019-02-11 - V 1.3.0 : Automatically detect commands
67 | 2019-01-12 - V 1.2.4 : Fix wrong exception message in Module Commands
68 | 2018-12-03 - V 1.2.4 : Fix wrong exception message in Module/InstallCommand
69 | 2018-11-12 - V 1.2.3 : New command to anonymise customer datas
70 | 2018-11-03 - V 1.2.2 : New commands and some fixes
71 | 2018-05-04 - V 1.2.1 : New command to clear all caches ( PS > 1.7 Only )
72 | 2018-01-23 - V 1.2.0 : New commands to clean existing datas ( with native module pscleaner )
73 | 2017-12-29 - V 1.1.0 : New commands to deals with cron tasks ( with native module cronjobs )
74 | 2017-08-10 - V 1.0.0 : Auto Upgrade works correctly + add build file
75 | 2017-08-09 - V 1.0.0-beta1 : New auto-upgrade process
76 | 2017-08-01 - V 0.9.0 : New commands to deals with hooks
77 | 2017-06-21 - V 0.8.0 : Refactor modules commands to deals with multiples modules
78 | 2017-06-06 - V 0.7.2 : New Command to download Class Names for autocomplete
79 | 2017-05-06 - V 0.7.1 : Now works with prestashop 1.7
80 | 2016-03-27 - V 0.7.0 : New command for mass configuration object changes
81 | 2016-01-12 - V 0.6.0 : New command to add index.php files in directories
82 | 2016-01-11 - V 0.5.1 : Improvement for creating admin user
83 | 2016-12-23 - V 0.5.0 : New commands to create admin user and to change admin password
84 | 2016-11-03 - V 0.4.0 : New command to get all configurations
85 | 2016-10-10 - V 0.3.0 : New functionality : install prestashop from command line
86 | 2016-10-07 - V 0.2.3 : Fix media command
87 | 2016-09-23 - V 0.2.2 : Cache management improvements, add media cache
88 | 2016-09-22 - V 0.2.1 : Replace configuration file in yml by file in php to optimize phar generation
89 | 2016-09-17 - V 0.2.0 : New phar archive
90 | 2016-06- : New commands
91 | 2016-05-19 : Version initiale
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "hhennes/prestashop-console",
3 | "description": "Tools to manage your prestashop with CLI",
4 | "homepage": "https://github.com/nenes25/prestashop_console",
5 | "authors": [
6 | {
7 | "name": "hhennes",
8 | "email": "contact@h-hennes.fr",
9 | "homepage": "https://www.h-hennes.fr/blog/"
10 | }
11 | ],
12 | "license": "OSL-3.0",
13 | "require": {
14 | "php" : ">=5.6",
15 | "symfony/console": "^3.0",
16 | "psr/log": "^1.0",
17 | "symfony/yaml": "^3.0",
18 | "symfony/finder": "^3.1",
19 | "padraic/phar-updater": "^1.0",
20 | "symfony/lock": "^3.4",
21 | "symfony/filesystem": "^3.4"
22 | },
23 | "autoload": {
24 | "psr-0": {
25 | "Hhennes": "src"
26 | }
27 | },
28 | "config": {
29 | "vendor-dir": "src/vendor"
30 | },
31 | "require-dev": {
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/config.php:
--------------------------------------------------------------------------------
1 | 'PrestashopConsole',
14 | 'version' => '1.6.6',
15 | 'author' => 'hhennes ',
16 | 'contributors' => [
17 | 'okom3pom',
18 | 'lutek',
19 | 'SebSept',
20 | 'm3uusi'
21 | ]
22 | ];
23 |
24 |
--------------------------------------------------------------------------------
/console.php:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 |
17 | * @copyright 2007-2018 Hennes Hervé
18 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
19 | * http://www.h-hennes.fr/blog/
20 | */
21 |
22 | use Hhennes\PrestashopConsole\PrestashopConsoleApplication;
23 |
24 | //Autoload Composer
25 | require_once 'src/vendor/autoload.php';
26 |
27 | //Console Application
28 | require_once 'config.php';
29 |
30 | // Only allow execution from the console script directory (To have use of the current path to get to the prestashop instance)
31 | // We consider that the console directory must be located at the root of the prestashop instance so we can get to the root by
32 | // going one lever upper (../ <- Root of prestashop instance if exists)
33 | if (getcwd() !== __DIR__) {
34 | echo "Error :\n";
35 | echo "This script must be executed only from its directory to have correct behaviour in php mode.\n";
36 | echo "Please change directory to " . __DIR__ . " and execute the script again.\n";
37 | exit(1);
38 | }
39 |
40 | $app = new PrestashopConsoleApplication($configuration['application']['name'], $configuration['application']['version']);
41 |
42 | //Autoload Prestashop
43 | if ( is_file('../config/config.inc.php')) {
44 | include_once '../config/config.inc.php';
45 |
46 | //Get App declared commands
47 | $app->getDeclaredCommands();
48 | }
49 | //If no prestashop conf find, only allow to install Prestashop
50 | else {
51 | $app->registerInstallCommands();
52 | $app->setDefaultCommand('install:info');
53 | }
54 |
55 | //Application run
56 | $app->run();
57 |
--------------------------------------------------------------------------------
/console.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nenes25/prestashop_console/9ded4eb83fc633e2b4d2ee23aef55b5becbbe5f5/console.png
--------------------------------------------------------------------------------
/examples/configuration.mass.yml:
--------------------------------------------------------------------------------
1 | Configuration:
2 | updateValue: #params the same as in oryginal method: key, values, html = false, id_shop_group = null, id_shop = null
3 | - key: 'CONFIG_PARAM_NAME_WITH_LANG'
4 | value:
5 | 1: 'polish txt with proper id_lang as key dd'
6 | 2: 'english txt with proper id_lang as key dd'
7 | html: true
8 | - key: 'CONFIG_PARAM_NAME2'
9 | value: value for param
10 | - key: 'CONFIG_PARAM_NAME3'
11 | value: 'value for param CONFIG_PARAM_NAME3 with html'
12 | html: true
13 | deleteByName: #params the same as in oryginal method: key
14 | - key: 'CONFIG_PARAM_NAME_WITH_LANG'
15 | - key: 'CONFIG_PARAM_NAME2'
16 | - key: 'CONFIG_PARAM_NAME3'
17 |
--------------------------------------------------------------------------------
/index.php:
--------------------------------------------------------------------------------
1 |
16 | * @copyright 2007-2018 Hennes Hervé
17 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
18 | * http://www.h-hennes.fr/blog/
19 | */
20 |
21 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
22 | header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
23 | header('Cache-Control: no-store, no-cache, must-revalidate');
24 | header('Cache-Control: post-check=0, pre-check=0', false);
25 | header('Pragma: no-cache');
26 | header('Location: ../');
27 | exit;
28 |
--------------------------------------------------------------------------------
/phpstan.neon.dist:
--------------------------------------------------------------------------------
1 | parameters:
2 | paths:
3 | - ./src/
4 | excludes_analyse:
5 | - ./src/vendor/
6 | reportUnmatchedIgnoredErrors: false
7 | level: 0
8 | scanDirectories:
9 | - path/to/prestashop/root
10 | ignoreErrors:
11 | - '#Class PrestaShop\\PrestaShop\\Adapter\\Cache\\CacheClearer constructor invoked with 0 parameters, 4 required.#'
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Admin/User/CreateCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Admin\User;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputInterface;
25 | use Symfony\Component\Console\Input\InputOption;
26 | use Symfony\Component\Console\Output\OutputInterface;
27 | use Symfony\Component\Console\Question\Question;
28 | use Configuration;
29 | use Employee;
30 | use PrestaShopException;
31 | use Tools;
32 |
33 | /**
34 | * Create New Admin User
35 | * With a role of SuperAdmin
36 | */
37 | class CreateCommand extends Command
38 | {
39 | /**
40 | * @inheritDoc
41 | */
42 | protected function configure()
43 | {
44 | $this
45 | ->setName('admin:user:create')
46 | ->setDescription('Create new admin user')
47 | ->addOption('email', null, InputOption::VALUE_OPTIONAL, 'Admin email')
48 | ->addOption('password', null, InputOption::VALUE_OPTIONAL, 'Admin password')
49 | ->addOption('firstname', null, InputOption::VALUE_OPTIONAL, 'firstname')
50 | ->addOption('lastname', null, InputOption::VALUE_OPTIONAL, 'lastname');
51 | }
52 |
53 | /**
54 | * @inheritDoc
55 | */
56 | protected function execute(InputInterface $input, OutputInterface $output)
57 | {
58 | $helper = $this->getHelper('question');
59 |
60 | if (!$email = $input->getOption('email')) {
61 | $userQuestion = new Question('admin email :', false);
62 | $email = $helper->ask($input, $output, $userQuestion);
63 | }
64 |
65 | if (!$password = $input->getOption('password')) {
66 | $passwordQuestion = new Question('admin password :', 'admin123456');
67 | $passwordQuestion->setHidden(true);
68 | $password = $helper->ask($input, $output, $passwordQuestion);
69 | }
70 |
71 | if (!$firstname = $input->getOption('firstname')) {
72 | $firstnameQuestion = new Question('firstname :', 'admin');
73 | $firstname = $helper->ask($input, $output, $firstnameQuestion);
74 | }
75 |
76 | if (!$lastname = $input->getOption('lastname')) {
77 | $lastnameQuestion = new Question('lastname :', 'admin');
78 | $lastname = $helper->ask($input, $output, $lastnameQuestion);
79 | }
80 |
81 | //Error if employee with same email already exists
82 | if (Employee::employeeExists($email)) {
83 | $output->writeln("Employee with this email already exists");
84 | return 1;
85 | }
86 |
87 | $employee = new Employee();
88 | $employee->active = 1;
89 | $employee->email = $email;
90 | $employee->passwd = Tools::encrypt($password);
91 | $employee->firstname = $firstname;
92 | $employee->lastname = $lastname;
93 | $employee->id_lang = Configuration::get('PS_LANG_DEFAULT');
94 | $employee->id_profile = _PS_ADMIN_PROFILE_;
95 | $employee->default_tab = 1;
96 | $employee->bo_theme = 'default';
97 |
98 | try {
99 | $employee->save();
100 | } catch (PrestaShopException $e) {
101 | $output->writeln("".$e->getMessage()."");
102 | return 1;
103 | }
104 |
105 | $output->writeln("New user ".$email." created");
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Admin/User/ListCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Admin\User;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputInterface;
25 | use Symfony\Component\Console\Output\OutputInterface;
26 | use Symfony\Component\Console\Helper\Table;
27 | use Configuration;
28 | use Db;
29 |
30 | class ListCommand extends Command
31 | {
32 | protected function configure()
33 | {
34 | $this
35 | ->setName('admin:user:list')
36 | ->setDescription('List admin users')
37 | ->setHelp('List admin users registered in employee table');
38 | }
39 |
40 | protected function execute(InputInterface $input, OutputInterface $output)
41 | {
42 | //Function Employee::getEmployees() has not enough information , use db query instead
43 | $employeesQuery = "SELECT e.email,e.firstname,e.lastname,e.active,e.last_connection_date,p.name
44 | FROM " . _DB_PREFIX_ . "employee e
45 | LEFT JOIN " . _DB_PREFIX_ . "profile_lang p ON (
46 | e.id_profile = p.id_profile AND p.id_lang=" . Configuration::get('PS_LANG_DEFAULT')
47 | .")";
48 |
49 | $employees = Db::getInstance()->executeS($employeesQuery);
50 | if ($employees) {
51 | $table = new Table($output);
52 | $table->setHeaders(['email', 'firstname', 'lastname', 'profile', 'active', 'last_connection_date']);
53 | foreach ($employees as $employee) {
54 | $table->addRow(
55 | [
56 | $employee['email'],
57 | $employee['firstname'],
58 | $employee['lastname'],
59 | $employee['name'],
60 | $employee['active'],
61 | $employee['last_connection_date'],
62 | ]
63 | );
64 | }
65 | $table->render();
66 | } else {
67 | $output->writeln('No admin user on this shop');
68 | return 1;
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Admin/User/PasswordCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Admin\User;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputInterface;
25 | use Symfony\Component\Console\Output\OutputInterface;
26 | use Symfony\Component\Console\Question\Question;
27 | use Employee;
28 |
29 | /**
30 | * Change admin password
31 | */
32 | class PasswordCommand extends Command
33 | {
34 | protected function configure()
35 | {
36 | $this
37 | ->setName('admin:user:change-password')
38 | ->setDescription('Change admin user password');
39 | }
40 |
41 | protected function execute(InputInterface $input, OutputInterface $output)
42 | {
43 | $helper = $this->getHelper('question');
44 |
45 | $userQuestion = new Question('user email :', false);
46 | $email = $helper->ask($input, $output, $userQuestion);
47 |
48 | //Error if no employee exists with email
49 | if (! Employee::employeeExists($email)) {
50 | $output->writeln("Employee with this email not exists");
51 | return;
52 | }
53 |
54 | $passwordQuestion = new Question('admin password :', 'admin123456');
55 | $passwordQuestion->setHidden(true);
56 | $password = $helper->ask($input, $output, $passwordQuestion);
57 |
58 | $passwordConfirmQuestion = new Question('confirm admin password :', 'admin123456');
59 | $passwordConfirmQuestion->setHidden(true);
60 | $passwordConfirm = $helper->ask($input, $output, $passwordConfirmQuestion);
61 |
62 | if ($password !== $passwordConfirm) {
63 | $output->writeln("Password and password confirmation do not match");
64 | return 1;
65 | }
66 |
67 | $employee = new Employee();
68 | $employee->getByEmail($email);
69 | $employee->passwd = \Tools::encrypt($password);
70 |
71 | try {
72 | $employee->save();
73 | } catch (\Exception $e) {
74 | $output->writeln("".$e->getMessage()."");
75 | return 1;
76 | }
77 | $output->writeln("Password changed with success for user ".$email."");
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Analyze/GlobalCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Analyze;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputInterface;
25 | use Symfony\Component\Console\Output\OutputInterface;
26 | use Symfony\Component\Console\Input\ArrayInput;
27 |
28 | class GlobalCommand extends Command
29 | {
30 | /**
31 | * @inheritDoc
32 | */
33 | protected function configure()
34 | {
35 | $this
36 | ->setName('analyze:global')
37 | ->setDescription('Run a global analysis on the website')
38 | ->setHelp(
39 | 'This command is a "meta command" which run successively the following commands:'.PHP_EOL
40 | .'- analyze:website (website statistics)'.PHP_EOL
41 | .'- module:list --active (List all active modules)'.PHP_EOL
42 | .'- module:list --active --no-native (List all active and non prestashop modules)'.PHP_EOL
43 | .'- analyze:payments (List installed payments modules)'.PHP_EOL
44 | .'- analyze:carriers --active (List active carriers modules)'.PHP_EOL
45 | .'- dev:list-overrides (List overrides of the project)'.PHP_EOL
46 | );
47 | }
48 |
49 | /**
50 | * @inheritDoc
51 | */
52 | protected function execute(InputInterface $input, OutputInterface $output)
53 | {
54 | $commands = $this->getCommandList();
55 | foreach ($commands as $command) {
56 | try {
57 | $output->writeln('========================');
58 | $output->writeln('' . $command['description'] . '');
59 | $runCommand = $this->getApplication()->find($command['name']);
60 | if (array_key_exists('arguments', $command)) {
61 | $arguments = new ArrayInput($command['arguments']);
62 | $runCommand->run($arguments, $output);
63 | } else {
64 | $runCommand->run($input, $output);
65 | }
66 | } catch (\Exception $e) {
67 | $output->writeln(
68 | sprintf(
69 | 'Get exception during command run %s',
70 | $e->getMessage()
71 | )
72 | );
73 | return 1;
74 | }
75 | }
76 |
77 | return 0;
78 | }
79 |
80 | /**
81 | * Get the list of commands to execute
82 | * @return array
83 | */
84 | protected function getCommandList()
85 | {
86 | $commands = [
87 | [
88 | 'description' => 'Get website statistics',
89 | 'name' => 'analyze:website',
90 | ],
91 | [
92 | 'description' => 'List installed modules',
93 | 'name' => 'module:list',
94 | 'arguments' => [
95 | '--active' => true,
96 | ]
97 | ],
98 | [
99 | 'description' => 'List installed modules no natives',
100 | 'name' => 'module:list',
101 | 'arguments' => [
102 | '--active' => true,
103 | '--no-native' => true,
104 | ]
105 | ],
106 | [
107 | 'description' => 'List installed payments modules',
108 | 'name' => 'analyze:payments',
109 | ],
110 | [
111 | 'description' => 'List installed carriers',
112 | 'name' => 'analyze:carriers',
113 | 'arguments' => [
114 | '--active' => true,
115 | ]
116 | ],
117 | [
118 | 'description' => 'List overrides of the project',
119 | 'name' => 'dev:list-overrides',
120 | ],
121 | ];
122 |
123 | return $commands;
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Analyze/ListCarriersCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Analyze;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Helper\Table;
25 | use Symfony\Component\Console\Input\InputInterface;
26 | use Symfony\Component\Console\Input\InputOption;
27 | use Symfony\Component\Console\Output\OutputInterface;
28 | use Configuration;
29 | use Carrier;
30 |
31 | class ListCarriersCommand extends Command
32 | {
33 | /**
34 | * @inheritDoc
35 | */
36 | protected function configure()
37 | {
38 | $this
39 | ->setName('analyze:carriers')
40 | ->setDescription('List all payments module on the website')
41 | ->addOption('active', null, InputOption::VALUE_NONE, 'List only active carriers');
42 | //->addOption('format', null, InputOption::VALUE_OPTIONAL, 'outputFormat', null);
43 | }
44 |
45 | /**
46 | * @inheritDoc
47 | */
48 | protected function execute(InputInterface $input, OutputInterface $output)
49 | {
50 | $active = (bool)$input->getOption('active');
51 | //@todo Manage format when refacto with meta command
52 | //$format = $input->getOption('format');
53 |
54 | $carriers = Carrier::getCarriers(
55 | Configuration::get('PS_DEFAULT_LANG'),
56 | $active
57 | );
58 | if ($carriers && count($carriers)) {
59 | $table = new Table($output);
60 | $table->setHeaders(
61 | [
62 | 'name',
63 | 'module',
64 | 'active'
65 | ]
66 | );
67 |
68 | $nbCarriers = 0;
69 | foreach ($carriers as $carrier) {
70 | $table->addRow(
71 | [
72 | $carrier['name'],
73 | $carrier['is_module'] == 1 ? $carrier['external_module_name'] : 'none',
74 | $carrier['active']
75 | ]
76 | );
77 | $nbCarriers++;
78 | }
79 | $output->writeln(''.$nbCarriers.' carriers on the website');
80 | $table->render();
81 | } else {
82 | $output->writeln('No carriers founds');
83 | }
84 | return 0;
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Analyze/ListPaymentsCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Analyze;
22 |
23 | use PaymentModule;
24 | use Symfony\Component\Console\Command\Command;
25 | use Symfony\Component\Console\Helper\Table;
26 | use Symfony\Component\Console\Input\InputInterface;
27 | use Symfony\Component\Console\Output\OutputInterface;
28 |
29 | class ListPaymentsCommand extends Command
30 | {
31 | /**
32 | * @inheritDoc
33 | */
34 | protected function configure()
35 | {
36 | $this
37 | ->setName('analyze:payments')
38 | ->setDescription('List all payments modules on the website');
39 | //->addOption('format', null, InputOption::VALUE_OPTIONAL, 'outputFormat', null);
40 | }
41 |
42 | /**
43 | * @inheritDoc
44 | */
45 | protected function execute(InputInterface $input, OutputInterface $output)
46 | {
47 | $modules = PaymentModule::getInstalledPaymentModules();
48 | if ($modules && count($modules)) {
49 | $nbModules = 0;
50 | $table = new Table($output);
51 | $table->setHeaders(
52 | [
53 | 'name',
54 | ]
55 | );
56 | foreach ($modules as $module) {
57 | $table->addRow(
58 | [
59 | $module['name'],
60 | ]
61 | );
62 | $nbModules++;
63 | }
64 | $output->writeln('' . $nbModules . ' payments modules on the website');
65 | $table->render();
66 | } else {
67 | $output->writeln('No payments modules installed');
68 | }
69 |
70 | return 0;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Analyze/TablesSizeCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Analyze;
22 |
23 | use Db;
24 | use Symfony\Component\Console\Command\Command;
25 | use Symfony\Component\Console\Helper\Table;
26 | use Symfony\Component\Console\Input\InputInterface;
27 | use Symfony\Component\Console\Input\InputOption;
28 | use Symfony\Component\Console\Output\OutputInterface;
29 |
30 | class TablesSizeCommand extends Command
31 | {
32 |
33 | /**
34 | * @inheritDoc
35 | */
36 | protected function configure()
37 | {
38 | $this
39 | ->setName('analyze:tables:size')
40 | ->setDescription('Analyze the size of the database tables sorted by size')
41 | ->addOption('limit', null, InputOption::VALUE_OPTIONAL, 'Limit to the number of tables');
42 | }
43 |
44 | /**
45 | * @inheritDoc
46 | */
47 | protected function execute(InputInterface $input, OutputInterface $output)
48 | {
49 | $limit = $input->getOption('limit');
50 | if (null !== $limit) {
51 | $limit = intval($limit);
52 | }
53 | $tablesInformations = $this->getBiggestTablesSizes($limit);
54 | if (count($tablesInformations)) {
55 | null !== $limit ?
56 | $title = sprintf('%d biggest tables of current database', $limit) :
57 | $title = 'Tables of current database';
58 |
59 | $output->writeln(''.$title.'');
60 |
61 | $table = new Table($output);
62 | $table->setHeaders(
63 | [
64 | 'table_name',
65 | 'size',
66 | ]
67 | );
68 |
69 | foreach ($tablesInformations as $tablesInformation) {
70 | $table->addRow(
71 | [
72 | $tablesInformation['TABLE_NAME'],
73 | $tablesInformation['TABLE_SIZE']
74 | ]
75 | );
76 | }
77 | $table->render();
78 | }
79 |
80 | $output->writeln(sprintf('Global db size %s ', $this->getGlobalDbSize()));
81 |
82 | return 0;
83 | }
84 |
85 | /**
86 | * Get the biggest tables and their sizes
87 | * @param int|null $limit
88 | * @return array
89 | */
90 | protected function getBiggestTablesSizes($limit = null)
91 | {
92 | $tableQuery = "SELECT
93 | TABLE_NAME, TABLE_TYPE, TABLE_COMMENT, AUTO_INCREMENT, TABLE_ROWS,
94 | CONCAT ( round(((data_length + index_length) / 1024 / 1024), 2),' MB' ) 'TABLE_SIZE'
95 | FROM
96 | information_schema.TABLES
97 | WHERE
98 | table_schema = DATABASE()
99 | ORDER BY
100 | (data_length + index_length) DESC";
101 |
102 | if (null != $limit) {
103 | $tableQuery .= " LIMIT ".$limit;
104 | }
105 |
106 | try {
107 | $sizeInformation = Db::getInstance()->executeS($tableQuery);
108 | if ($sizeInformation) {
109 | return $sizeInformation;
110 | }
111 | } catch (\PrestaShopDatabaseException $e) {
112 | }
113 |
114 | return [];
115 | }
116 |
117 | /**
118 | * Get the global database size
119 | * @return string
120 | */
121 | protected function getGlobalDbSize()
122 | {
123 | $sizeInformations = Db::getInstance()->getRow(
124 | "SELECT
125 | SUM(table_rows) 'db_rows',
126 | CONCAT ( round(((SUM(data_length) + SUM(index_length)) / 1024 / 1024), 2),' MB' ) 'db_size'
127 | FROM
128 | information_schema.TABLES
129 | WHERE
130 | table_schema = DATABASE()
131 | GROUP BY
132 | table_schema"
133 | );
134 |
135 | if ($sizeInformations) {
136 | return $sizeInformations['db_size'];
137 | }
138 | return 'unknown';
139 | }
140 | }
141 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Analyze/WebsiteCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Analyze;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputInterface;
25 | use Symfony\Component\Console\Output\OutputInterface;
26 | use Symfony\Component\Console\Input\ArrayInput;
27 | use Symfony\Component\Console\Helper\Table;
28 | use Db;
29 | use DateTime;
30 |
31 | /**
32 | * @todo this command should deals with multistore in next version
33 | */
34 | class WebsiteCommand extends Command
35 | {
36 | /**
37 | * @inheritDoc
38 | */
39 | protected function configure()
40 | {
41 | $this
42 | ->setName('analyze:website')
43 | ->setDescription('Get website statistics')
44 | ->setHelp(
45 | 'This command show useful statistics about the website' . PHP_EOL
46 | . "- Prestashop Version " . PHP_EOL
47 | . "- Installation date " . PHP_EOL
48 | . "- Customer and orders count and average since installation " . PHP_EOL
49 | . "- Products and category count " . PHP_EOL
50 | );
51 | }
52 |
53 | /**
54 | * @inheritDoc
55 | */
56 | protected function execute(InputInterface $input, OutputInterface $output)
57 | {
58 | $daysFromCreation = $this->getNbDaysFromCreation(_PS_CREATION_DATE_);
59 | $nbCustomers = $this->getCustomersCount();
60 | $nbOrders = $this->getOrdersCount();
61 | $nbProducts = $this->getCatalogProductsCount();
62 | $nbCategories = $this->getCatalogCategoryCount();
63 | $multipleShop = $this->hasMultipleShops();
64 | $output->writeln('Prestashop version: ' . _PS_VERSION_ . '');
65 | if (true === $multipleShop) {
66 | $output->writeln('This website has multiple shops');
67 | }
68 | $output->writeln('Used theme name: ' . _THEME_NAME_ . '');
69 | $output->writeln('This website is installed since: ' . _PS_CREATION_DATE_ . ' (' . $daysFromCreation . ' days)');
70 | $output->writeln('Number of customers: ' . $nbCustomers . ' (' . round($nbCustomers / $daysFromCreation, 2) . '/day)');
71 | $output->writeln('Number of orders: ' . $nbOrders . ' (' . round($nbOrders / $daysFromCreation, 2) . '/day)');
72 | $output->writeln('Number of products: ' . $nbProducts . '');
73 | $output->writeln('Number of categories: ' . $nbCategories . '');
74 |
75 | return 0;
76 | }
77 |
78 | /**
79 | * Calculate the difference of day from the installation to now
80 | * @param string $creationDate
81 | * @return int
82 | * @throws \Exception
83 | */
84 | protected function getNbDaysFromCreation($creationDate)
85 | {
86 | $now = new DateTime();
87 | return $now->diff(new DateTime($creationDate))->days;
88 | }
89 |
90 | /**
91 | * Get number of customers
92 | * @return false|string|null
93 | */
94 | protected function getCustomersCount()
95 | {
96 | return $this->getCount('customer', 'deleted=0');
97 | }
98 |
99 | /**
100 | * Get number of orders
101 | * @return false|string|null
102 | */
103 | protected function getOrdersCount()
104 | {
105 | return $this->getCount('orders');
106 | }
107 |
108 | /**
109 | * Get number of products
110 | * @return false|string|null
111 | */
112 | protected function getCatalogProductsCount()
113 | {
114 | return $this->getCount('product');
115 | }
116 |
117 | /**
118 | * Get number of categories
119 | * @return false|string|null
120 | */
121 | protected function getCatalogCategoryCount()
122 | {
123 | return $this->getCount('category');
124 | }
125 |
126 | /**
127 | * Check if website use multiples shops
128 | * @return bool
129 | */
130 | protected function hasMultipleShops()
131 | {
132 | $nbShops = $this->getCount('shop');
133 | if ($nbShops > 1) {
134 | return true;
135 | }
136 | return false;
137 | }
138 |
139 | /**
140 | * Get count from a table with or without conditions
141 | * @param string $table
142 | * @param string|void $where
143 | * @return false|string|null
144 | */
145 | protected function getCount($table, $where = '')
146 | {
147 | $whereCondition = ($where != '') ? ' WHERE ' . $where : '';
148 | return Db::getInstance()->getValue("SELECT COUNT(*) FROM " . _DB_PREFIX_ . $table . $whereCondition);
149 | }
150 | }
151 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Cache/CleanCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Cache;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputArgument;
25 | use Symfony\Component\Console\Input\InputInterface;
26 | use Symfony\Component\Console\Output\OutputInterface;
27 | use Cache;
28 |
29 | /**
30 | * Clean cache
31 | *
32 | * @author hhennes
33 | */
34 | class CleanCommand extends Command
35 | {
36 | protected function configure()
37 | {
38 | $this
39 | ->setName('cache:clean')
40 | ->setDescription('Clean cache')
41 | ->addArgument('key', InputArgument::OPTIONAL, 'key name | default *');
42 | }
43 |
44 | protected function execute(InputInterface $input, OutputInterface $output)
45 | {
46 | $key = $input->getArgument('key');
47 |
48 | if (!$key || $key == '') {
49 | $key = "*";
50 | }
51 |
52 | $cache = Cache::getInstance();
53 | $cache->clean($key);
54 |
55 | $output->writeln('Cache cleaned');
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Cache/ClearAllCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Cache;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputInterface;
25 | use Symfony\Component\Console\Output\OutputInterface;
26 | use PrestaShop\PrestaShop\Adapter\Cache\CacheClearer;
27 | use Tools;
28 |
29 | /**
30 | * Clear all caches commands
31 | */
32 | class ClearAllCommand extends Command
33 | {
34 | protected function configure()
35 | {
36 | $this
37 | ->setName('cache:clearAll')
38 | ->setDescription('Clear all cache');
39 | }
40 |
41 | protected function execute(InputInterface $input, OutputInterface $output)
42 | {
43 | if (Tools::version_compare(_PS_VERSION_, '1.7.0.0', '>=')) {
44 | $cacheClearer = new CacheClearer();
45 | $cacheClearer->clearAllCaches();
46 | $output->writeln("All cache cleared with success");
47 | } else {
48 | $output->writeln("This command is only available for Prestashop > 1.7.0.0 ");
49 | return 1;
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Cache/FlushCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Cache;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputInterface;
25 | use Symfony\Component\Console\Output\OutputInterface;
26 | use Cache;
27 |
28 | /**
29 | * Flush prestashop cache
30 | *
31 | * @author hhennes
32 | */
33 | class FlushCommand extends Command
34 | {
35 | protected function configure()
36 | {
37 | $this
38 | ->setName('cache:flush')
39 | ->setDescription('Flush cache');
40 | }
41 |
42 | protected function execute(InputInterface $input, OutputInterface $output)
43 | {
44 | $cache = Cache::getInstance();
45 | $cache->flush();
46 |
47 | //Specific cacheFS
48 | if (get_class($cache) == 'cacheFs') {
49 | $cache::deleteCacheDirectory();
50 | $cache::createCacheDirectories();
51 | }
52 |
53 | $output->writeln('Cache flushed');
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Cache/MediaCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Cache;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputInterface;
25 | use Symfony\Component\Console\Output\OutputInterface;
26 | use Media;
27 |
28 | /**
29 | * Clear Media cache
30 | */
31 | class MediaCommand extends Command
32 | {
33 | protected function configure()
34 | {
35 | $this
36 | ->setName('cache:media')
37 | ->setDescription('Clean media cache directory');
38 | }
39 |
40 | public function execute(InputInterface $input, OutputInterface $output)
41 | {
42 | Media::clearCache();
43 | $output->writeln('Media cache cleared');
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Cache/Smarty/ClearCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Cache\Smarty;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputInterface;
25 | use Symfony\Component\Console\Output\OutputInterface;
26 | use Tools;
27 |
28 | /**
29 | * Commande qui permet de supprimer tout le cache smarty
30 | * (Fichiers compilés + cache)
31 | * Pour l'instant nécessite la function exec
32 | * @todo Optmimiser pour ne pas supprimer le fichier index.php + gérer le mode SQL
33 | */
34 | class ClearCommand extends Command
35 | {
36 | protected function configure()
37 | {
38 | $this
39 | ->setName('cache:smarty:clear')
40 | ->setDescription('Clear smarty cache');
41 | }
42 |
43 | protected function execute(InputInterface $input, OutputInterface $output)
44 | {
45 | Tools::clearSmartyCache();
46 | $output->writeln('Smarty Cache and compiled dir cleaned');
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Cache/Smarty/ConfigureCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Cache\Smarty;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputArgument;
25 | use Symfony\Component\Console\Input\InputInterface;
26 | use Symfony\Component\Console\Output\OutputInterface;
27 | use Configuration;
28 |
29 | /**
30 | * Commande qui permet de configurer le cache Smarty
31 | *
32 | */
33 | class ConfigureCommand extends Command
34 | {
35 |
36 | /**
37 | * Limitation des donnés à saisir
38 | * @var array $_allowedNames
39 | */
40 | protected $_allowedNames = array(
41 | 'compile' => array('config_value' => 'PS_SMARTY_FORCE_COMPILE', 'allowed_values' => array('0', '1', '2')),
42 | 'cache' => array('config_value' => 'PS_SMARTY_CACHE', 'allowed_values' => array('0', '1')),
43 | 'cacheType' => array('config_value' => 'PS_SMARTY_CACHING_TYPE', 'allowed_values' => array('filesystem', 'mysql')),
44 | 'clearCache' => array('config_value' => 'PS_SMARTY_CLEAR_CACHE', 'allowed_values' => array('never', 'everytime'))
45 | );
46 |
47 | protected function configure()
48 | {
49 | $this
50 | ->setName('cache:smarty:configure')
51 | ->setDescription('Configure Smarty cache')
52 | ->addArgument('name', InputArgument::REQUIRED, 'configuration name')
53 | ->addArgument('value', InputArgument::REQUIRED, 'configuration value');
54 | }
55 |
56 | protected function execute(InputInterface $input, OutputInterface $output)
57 | {
58 | $name = $input->getArgument('name');
59 | $value = $input->getArgument('value');
60 |
61 | if (!array_key_exists($name, $this->_allowedNames)) {
62 | $output->writeln("Name not allowed");
63 | return 1;
64 | } else {
65 | //Vérification de la valeur
66 | if (!in_array($value, $this->_allowedNames[$name]['allowed_values'])) {
67 | $output->writeln("Value not allowed for configuration " . $name."");
68 | return 1;
69 | } else {
70 | Configuration::updateValue($this->_allowedNames[$name]['config_value'], $value);
71 | $output->writeln("Update configuration " . $name . " with " . $value."");
72 | }
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Configuration/DeleteCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Configuration;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputArgument;
25 | use Symfony\Component\Console\Input\InputInterface;
26 | use Symfony\Component\Console\Output\OutputInterface;
27 | use Configuration;
28 |
29 | /**
30 | * Commande qui permet de supprimer une valeur de configuration
31 | *
32 | */
33 | class DeleteCommand extends Command
34 | {
35 | protected function configure()
36 | {
37 | $this
38 | ->setName('configuration:delete')
39 | ->setDescription('delete configuration value')
40 | ->addArgument(
41 | 'name',
42 | InputArgument::REQUIRED,
43 | 'configuration name'
44 | );
45 | }
46 |
47 | protected function execute(InputInterface $input, OutputInterface $output)
48 | {
49 | $name = $input->getArgument('name');
50 | $value = Configuration::deleteByName($name);
51 | $output->writeln(''.$value.'');
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Configuration/GetAllCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Configuration;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Helper\Table;
25 | use Symfony\Component\Console\Input\InputInterface;
26 | use Symfony\Component\Console\Output\OutputInterface;
27 | use Configuration;
28 | use Db;
29 |
30 | /**
31 | * Get All Configuration values
32 | *
33 | */
34 | class GetAllCommand extends Command
35 | {
36 | const MAX_LENGTH_CONFIGURATION_VALUE = 130;
37 |
38 | protected function configure()
39 | {
40 | $this
41 | ->setName('configuration:getAll')
42 | ->setDescription('get all configuration values');
43 | }
44 |
45 | protected function execute(InputInterface $input, OutputInterface $output)
46 | {
47 | //Load All Configurations
48 | Configuration::loadConfiguration();
49 |
50 | //Get All Configuration names (except xml configuration)
51 | $configurationNames = Db::getInstance()->executeS("SELECT name FROM "._DB_PREFIX_."configuration WHERE name <> 'PS_INSTALL_XML_LOADERS_ID'");
52 |
53 | $table = new Table($output);
54 | $table->setHeaders(['Name', 'Value']);
55 | foreach ($configurationNames as $configuration_name) {
56 | $configuration_value = Configuration::get($configuration_name['name']);
57 | if (strlen($configuration_value) > self::MAX_LENGTH_CONFIGURATION_VALUE) {
58 | $configuration_value = substr($configuration_value, 0, self::MAX_LENGTH_CONFIGURATION_VALUE)." (*)";
59 | }
60 | $table->addRow([$configuration_name['name'], $configuration_value]);
61 | }
62 |
63 | $table->render();
64 | $output->writeln("(*) : Value truncated");
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Configuration/GetCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Configuration;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputArgument;
25 | use Symfony\Component\Console\Input\InputInterface;
26 | use Symfony\Component\Console\Output\OutputInterface;
27 | use Configuration;
28 |
29 | /**
30 | * Commande qui permet de récupérer une valeur de configuration
31 | *
32 | */
33 | class GetCommand extends Command
34 | {
35 | protected function configure()
36 | {
37 | $this
38 | ->setName('configuration:get')
39 | ->setDescription('get configuration value')
40 | ->addArgument(
41 | 'name',
42 | InputArgument::REQUIRED,
43 | 'configuration name'
44 | );
45 | }
46 |
47 | protected function execute(InputInterface $input, OutputInterface $output)
48 | {
49 | $name = $input->getArgument('name');
50 | $value = Configuration::get($name);
51 | $output->writeln(''.$value.'');
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Configuration/MassCommand.php:
--------------------------------------------------------------------------------
1 |
22 | * @copyright 2013-2019 Mariusz Mielnik
23 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
24 | * http://www.ecbox.pl
25 | */
26 |
27 | namespace Hhennes\PrestashopConsole\Command\Configuration;
28 |
29 | use Symfony\Component\Console\Command\Command;
30 | use Symfony\Component\Console\Input\InputInterface;
31 | use Symfony\Component\Console\Input\InputOption;
32 | use Symfony\Component\Console\Output\OutputInterface;
33 | use Symfony\Component\Yaml\Yaml;
34 |
35 | /**
36 | * Commands: Mass configuration operations based on yaml definition
37 | *
38 | */
39 | class MassCommand extends Command
40 | {
41 | protected $allowedCalls = [
42 | 'Configuration' => [
43 | 'updateValue',
44 | 'deleteByName',
45 | 'updateGlobalValue',
46 | 'set'
47 | ]];
48 |
49 |
50 | protected function configure()
51 | {
52 | $this
53 | ->setName('configuration:mass')
54 | ->setDescription('Mass operation configured in yaml file')
55 | ->addOption('config', null, InputOption::VALUE_REQUIRED, 'Yaml definition file');
56 | }
57 |
58 | protected function execute(InputInterface $input, OutputInterface $output)
59 | {
60 | $yamlFile = $input->getOption('config');
61 |
62 |
63 | //check if file exist
64 | if (file_exists($yamlFile)) {
65 | //parse yaml file
66 | $definitions = Yaml::parse(file_get_contents($yamlFile));
67 | //Get the call object name;
68 | $callObjName = key($definitions);
69 |
70 | //check if object is allowed to call
71 | if (in_array($callObjName, array_keys($this->allowedCalls))) {
72 | //create instance
73 | $callObject = new $callObjName();
74 |
75 | foreach ($definitions[$callObjName] as $method => $params) {
76 |
77 | //check if method of object is allowed to call
78 | if (in_array($method, array_values($this->allowedCalls[$callObjName]))) {
79 |
80 | //check if configured method exist
81 | if (method_exists($callObject, $method)) {
82 |
83 | //if single params for one method convert to indexed array
84 | if (isset($params['key'])) {
85 | $params = array($params);
86 | }
87 |
88 | //call the same method with different params
89 | foreach ($params as $callParams) {
90 | $firstValue = reset($callParams);
91 | $firstKey = key($callParams);
92 | $output->writeln("Calling $callObjName.$method($firstKey => $firstValue [...])");
93 | call_user_func_array(array($callObject, $method), array_values($callParams));
94 | }
95 | } else {
96 | $output->writeln("Method '$callObjName.$method' doesnt exist");
97 | }
98 | } else {
99 | $output->writeln("Method '$callObjName.$method' is not allowed");
100 | }
101 | }
102 | } else {
103 | $output->writeln("Object '$callObjName' is not allowed");
104 | }
105 | } else {
106 | $output->writeln("Yaml definition file: '$yamlFile' doesnt exist!");
107 | return 1;
108 | }
109 |
110 | $output->writeln("Definitions from file '$yamlFile' processed successfully!");
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Configuration/SetCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Configuration;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputArgument;
25 | use Symfony\Component\Console\Input\InputInterface;
26 | use Symfony\Component\Console\Output\OutputInterface;
27 | use Configuration;
28 |
29 | /**
30 | * Commande qui permet de définir une valeur de configuration
31 | *
32 | */
33 | class SetCommand extends Command
34 | {
35 | protected function configure()
36 | {
37 | $this
38 | ->setName('configuration:set')
39 | ->setDescription('set configuration value')
40 | ->addArgument('name', InputArgument::REQUIRED, 'configuration name')
41 | ->addArgument('value', InputArgument::REQUIRED, 'configuration value');
42 | }
43 |
44 | protected function execute(InputInterface $input, OutputInterface $output)
45 | {
46 | $name = $input->getArgument('name');
47 | $value = $input->getArgument('value');
48 | Configuration::updateValue($name, $value);
49 | $output->writeln("Update configuration ".$name." with ".$value."");
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Console/SelfUpdateCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Console;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputInterface;
25 | use Symfony\Component\Console\Output\OutputInterface;
26 | use Humbug\SelfUpdate\Updater;
27 | use Exception;
28 |
29 | /**
30 | * Commande qui permet de mettre à jour la console
31 | *
32 | */
33 | class SelfUpdateCommand extends Command
34 | {
35 | const PHAR_URL = 'https://github.com/nenes25/prestashop_console/raw/master/bin/prestashopConsole.phar';
36 | const VERSION_URL = 'https://github.com/nenes25/prestashop_console/raw/master/bin/phar/current.version';
37 |
38 | protected function configure()
39 | {
40 | $this
41 | ->setName('console:self-upgrade')
42 | ->setDescription('Upgrade console to last version (phar only)');
43 | }
44 |
45 | /**
46 | *
47 | * @param InputInterface $input
48 | * @param OutputInterface $output
49 | */
50 | public function execute(InputInterface $input, OutputInterface $output)
51 | {
52 | if ($this->getApplication()->getRunAs() == 'php') {
53 | $output->writeln('This commande can only be run in phar mode');
54 | return;
55 | }
56 |
57 | $updater = new Updater(null, false);
58 | $updater->getStrategy()->setPharUrl(self::PHAR_URL);
59 | $updater->getStrategy()->setVersionUrl(self::VERSION_URL);
60 |
61 | try {
62 | $result = $updater->update();
63 | if ($result) {
64 | $output->writeLn('Prestashop console was updated with success to last version');
65 | } else {
66 | $output->writeLn('No update needed');
67 | }
68 | } catch (Exception $e) {
69 | $output->writeln('Unable to update console');
70 | $output->writeln(''.$e->getMessage().'');
71 | return 1;
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Db/ImportCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Db;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputInterface;
25 | use Symfony\Component\Console\Input\InputOption;
26 | use Symfony\Component\Console\Output\OutputInterface;
27 |
28 | class ImportCommand extends Command
29 | {
30 | protected function configure()
31 | {
32 | $this
33 | ->setName('db:import')
34 | ->setDescription('Import db dump ')
35 | ->addOption('file', 'f', InputOption::VALUE_REQUIRED)
36 | ->addOption('gzip', 'g', InputOption::VALUE_OPTIONAL, 'gzip ')
37 | ->setHelp('This command will import dumb (gziped or not ) in current prestashop database using mysql shell command');
38 | }
39 |
40 | /**
41 | * @param InputInterface $input
42 | * @param OutputInterface $output
43 | * @return bool|void
44 | */
45 | protected function execute(InputInterface $input, OutputInterface $output)
46 | {
47 |
48 | //Shell_exec function is required
49 | if (!function_exists('shell_exec')) {
50 | $output->writeln('The function shell_exec is not present');
51 | return 1;
52 | }
53 |
54 | $file = $input->getOption('file');
55 | $gzip = $input->getOption('gzip');
56 |
57 | if (!is_file($file)) {
58 | $output->writeln('The import file does not exists');
59 | return 1;
60 | }
61 |
62 | if (null !== $gzip) {
63 | $command = 'zcat ' . $file . ' | mysql -h ' . _DB_SERVER_ . ' -u ' . _DB_USER_ . ' -p' . _DB_PASSWD_ . ' ' . _DB_NAME_;
64 | } else {
65 | $command = 'mysql -h ' . _DB_SERVER_ . ' -u ' . _DB_USER_ . ' -p' . _DB_PASSWD_ . ' ' . _DB_NAME_ . ' < ' . $file;
66 | }
67 | $output->writeln('Import started');
68 | $import = shell_exec($command);
69 | $output->writeln($import);
70 | $output->writeln('Import ended');
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Db/QueryCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Db;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputInterface;
25 | use Symfony\Component\Console\Input\InputOption;
26 | use Symfony\Component\Console\Output\OutputInterface;
27 | use Symfony\Component\Console\Helper\Table;
28 | use Db;
29 | use PrestaShopDatabaseException;
30 |
31 | class QueryCommand extends Command
32 | {
33 | protected function configure()
34 | {
35 | $this
36 | ->setName('db:query')
37 | ->addOption('query', 's', InputOption::VALUE_REQUIRED)
38 | ->setDescription('Run sql query on prestashop db')
39 | ->setHelp('This command will exec db query using the prestashop Db class, its only allow SELECT queries');
40 | }
41 |
42 | /**
43 | * @param InputInterface $input
44 | * @param OutputInterface $output
45 | * @return bool | void
46 | */
47 | protected function execute(InputInterface $input, OutputInterface $output)
48 | {
49 | $query = $input->getOption('query');
50 | if (null === $query) {
51 | $output->writeln('No query given');
52 | return 1;
53 | }
54 |
55 | $query = trim($query);
56 |
57 | //Only allow select queries
58 | if (preg_match('#^SELECT#i', $query)) {
59 | try {
60 | $results = Db::getInstance()->executeS($query);
61 |
62 | if ($results) {
63 | $table = new Table($output);
64 | $table->setHeaders(array_keys($results[0]));
65 | foreach ($results as $result) {
66 | $table->addRow(
67 | array_values($result)
68 | );
69 | }
70 | $table->render();
71 | } else {
72 | $output->writeln('No results for your query');
73 | }
74 | } catch (PrestaShopDatabaseException $e) {
75 | $output->writeln('' . $e->getMessage() . '');
76 | return 1;
77 | }
78 | } else {
79 | $output->writeln('Only SELECT query are managed for now');
80 | return 1;
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Dev/AddIndexFilesCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Dev;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputArgument;
25 | use Symfony\Component\Console\Input\InputInterface;
26 | use Symfony\Component\Console\Output\OutputInterface;
27 | use Symfony\Component\Finder\Finder;
28 |
29 | /**
30 | * Commande qui permet d'ajouter des fichiers index.php dans les dossiers manquants
31 | *
32 | */
33 | class AddIndexFilesCommand extends Command
34 | {
35 | protected function configure()
36 | {
37 | $this
38 | ->setName('dev:add-index-files')
39 | ->setDescription('Add missing index.php files in directory')
40 | ->addArgument(
41 | 'dir',
42 | InputArgument::REQUIRED,
43 | 'directory to fill ( relative to ps root path)'
44 | );
45 | }
46 |
47 | /**
48 | *
49 | * @param InputInterface $input
50 | * @param OutputInterface $output
51 | * @throws \Exception
52 | */
53 | protected function execute(InputInterface $input, OutputInterface $output)
54 | {
55 | $dir = $input->getArgument('dir');
56 | try {
57 | if (!is_dir(_PS_ROOT_DIR_.DIRECTORY_SEPARATOR.$dir)) {
58 | throw new \Exception('directory doesn\'t exists');
59 | }
60 |
61 | //Create index file in the root directory if it not exists
62 | if ( !is_file(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . $dir.'/index.php')){
63 | $fp = fopen(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . $dir.'/index.php', 'w+');
64 | fputs($fp, $this->_getIndexContent());
65 | fclose($fp);
66 | }
67 |
68 | $finder = new Finder();
69 |
70 | //List all directories
71 | $directories = $finder->directories()->in(_PS_ROOT_DIR_.DIRECTORY_SEPARATOR.$dir)->exclude('vendor');
72 |
73 | $i = 0;
74 | foreach ($directories as $directory) {
75 | ${$i} = new Finder();
76 | //Check if index.php file exists in directory
77 | $indexFile = ${$i}->files()->in((string)$directory)->depth('==0')->name('index.php');
78 | //Create if if not
79 | if (!sizeof($indexFile)) {
80 | $fp = fopen($directory.DIRECTORY_SEPARATOR.'index.php', 'w+');
81 | fputs($fp, $this->_getIndexContent());
82 | fclose($fp);
83 | }
84 | $i++;
85 | }
86 | } catch (\Exception $e) {
87 | $output->writeln("ERROR:" . $e->getMessage() . "");
88 | }
89 | $output->writeln("Index files added with success");
90 | }
91 |
92 | /**
93 | * Get index.php content file
94 | * @return string
95 | */
96 | protected function _getIndexContent()
97 | {
98 | return "
99 |
120 | * @copyright 2007-2016 PrestaShop SA
121 | * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
122 | * International Registered Trademark & Property of PrestaShop SA
123 | */
124 |
125 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
126 | header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
127 | header('Cache-Control: no-store, no-cache, must-revalidate');
128 | header('Cache-Control: post-check=0, pre-check=0', false);
129 | header('Pragma: no-cache');
130 | header('Location: ../');
131 | exit;";
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Dev/ChangeShopDomainCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 |
22 | namespace Hhennes\PrestashopConsole\Command\Dev;
23 |
24 | use Symfony\Component\Console\Command\Command;
25 | use Symfony\Component\Console\Input\InputInterface;
26 | use Symfony\Component\Console\Output\OutputInterface;
27 | use Symfony\Component\Console\Input\InputOption;
28 | use Symfony\Component\Console\Input\InputArgument;
29 | use Db;
30 | use Validate;
31 |
32 | /**
33 | * Class ChangeUrl
34 | * This command will change the domain of the shop
35 | */
36 | class ChangeShopDomainCommand extends Command
37 | {
38 | /**
39 | * @inheritDoc
40 | */
41 | protected function configure()
42 | {
43 | $this
44 | ->setName('dev:change-domain')
45 | ->setDescription('Change the domain of the website')
46 | ->addArgument('domain', InputArgument::REQUIRED, 'New shop domain')
47 | ->addOption('physical_uri', null, InputOption::VALUE_OPTIONAL, 'Physical uri')
48 | ->addOption('virtual_uri', null, InputOption::VALUE_OPTIONAL, 'Virtual uri')
49 | ->addOption('id_shop', null, InputOption::VALUE_OPTIONAL, 'affected id_shop')
50 | ->setHelp(
51 | 'This command allow to change the domain , physical_uri and virtual_uri of registered shops'
52 | );
53 | }
54 |
55 | /**
56 | * @inheritDoc
57 | */
58 | public function execute(InputInterface $input, OutputInterface $output)
59 | {
60 | $domain = $input->getArgument('domain');
61 | $physicalUri = $input->getOption('physical_uri');
62 | $virtualUri = $input->getOption('virtual_uri');
63 | $id_shop = $input->getOption('id_shop');
64 |
65 | //Validate domain
66 | if (!$this->validateDomain($domain)) {
67 | $output->writeln('The provided domain is invalid');
68 | return 1;
69 | }
70 |
71 | //Validate options
72 | if (null !== $physicalUri && !$this->validateUri($physicalUri)) {
73 | $output->writeln('The provided physical uri is invalid');
74 | return 1;
75 | }
76 | if (null !== $virtualUri && !$this->validateUri($virtualUri)) {
77 | $output->writeln('The provided virtual uri is invalid');
78 | return 1;
79 | }
80 | if (null !== $id_shop && !Validate::isUnsignedId($id_shop)) {
81 | $output->writeln('The provided id_shop is invalid');
82 | return 1;
83 | }
84 |
85 | //Update domain
86 | try {
87 | $this->updateDomain(
88 | $domain,
89 | $physicalUri,
90 | $virtualUri,
91 | $id_shop
92 | );
93 | $output->writeln('The domain have been updated with success');
94 | } catch (\Exception $e) {
95 | $output->writeln('An error occurs when updating domain');
96 | return 1;
97 | }
98 |
99 | return 0;
100 | }
101 |
102 | /**
103 | * Update domain
104 | * @param string $domain
105 | * @param ?string $physicalUri
106 | * @param ?string $virtualUri
107 | * @param ?int $id_shop
108 | * @return bool
109 | */
110 | protected function updateDomain($domain, $physicalUri = null, $virtualUri = null, $id_shop = null)
111 | {
112 | $updatedData = [
113 | 'domain' => pSQL($domain),
114 | 'domain_ssl' => pSQL($domain),
115 | ];
116 | if (null !== $physicalUri) {
117 | $updatedData['physical_uri'] = pSQL($this->normalizeUri($physicalUri));
118 | }
119 | if (null !== $virtualUri) {
120 | $updatedData['virtual_uri'] = pSQL($virtualUri);
121 | }
122 |
123 | return Db::getInstance()->update(
124 | 'shop_url',
125 | $updatedData,
126 | null !== $id_shop ? 'id_shop=' . $id_shop : ''
127 | );
128 | }
129 |
130 | /**
131 | * Normalize uri with /
132 | * @param string $uri
133 | * @return string
134 | */
135 | protected function normalizeUri($uri)
136 | {
137 | if (strpos($uri, '/') !== 1) {
138 | $uri = '/'.$uri;
139 | }
140 |
141 | return $uri;
142 | }
143 |
144 | /**
145 | * Validate that the domain is well formatted
146 | * @param string $domain
147 | * @return bool
148 | */
149 | protected function validateDomain($domain)
150 | {
151 | return !preg_match('#^http?://#', $domain);
152 | }
153 |
154 | /**
155 | * Validate uri
156 | * @param string $uri
157 | * @return bool
158 | */
159 | protected function validateUri($uri)
160 | {
161 | return true;
162 | //return Validate::isDirName($uri);
163 | }
164 | }
165 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Dev/Clean/CleanCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Dev\Clean;
22 |
23 | use Symfony\Component\Console\Input\InputInterface;
24 | use Symfony\Component\Console\Input\InputArgument;
25 | use Symfony\Component\Console\Output\OutputInterface;
26 | use Symfony\Component\Lock\Factory;
27 | use Symfony\Component\Lock\Store\SemaphoreStore;
28 |
29 | class CleanCommand extends CleanCommandAbstract
30 | {
31 | protected $_allowedCleanType = ['all','catalog','sales'];
32 |
33 | protected function configure()
34 | {
35 | $this
36 | ->setName('dev:clean')
37 | ->setDescription('Clean existing datas with module PsCleaner')
38 | ->addArgument('type', InputArgument::REQUIRED, 'data types. Possibles values '. implode(', ', $this->_allowedCleanType));
39 | }
40 |
41 | protected function execute(InputInterface $input, OutputInterface $output)
42 | {
43 | if ($this->_cleanModuleInstance) {
44 | $type = $input->getArgument('type');
45 |
46 | $store = new SemaphoreStore();
47 | $factory = new Factory($store);
48 |
49 | $lock = $factory->createLock($this->getName());
50 | if (!$lock->acquire()) {
51 | $output->writeln('The command is already running in another process.');
52 | return 1;
53 | }
54 |
55 | switch ($type) {
56 |
57 | case 'all':
58 | $this->_cleanModuleInstance->truncate('catalog');
59 | $this->_cleanModuleInstance->truncate('sales');
60 | $output->writeln('All datas have been cleaned');
61 | break;
62 | case 'catalog':
63 | $this->_cleanModuleInstance->truncate('catalog');
64 | $output->writeln('Catalog datas have been cleaned');
65 | break;
66 | case 'sales':
67 | $this->_cleanModuleInstance->truncate('sales');
68 | $output->writeln('Sales datas have been cleaned');
69 | break;
70 | default:
71 | $output->writeln('Unknow clean type');
72 | return 1;
73 | break;
74 | }
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Dev/Clean/CleanCommandAbstract.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Dev\Clean;
22 |
23 | use Module;
24 | use Symfony\Component\Console\Command\Command;
25 | use Symfony\Component\Console\Input\InputInterface;
26 | use Symfony\Component\Console\Output\OutputInterface;
27 |
28 | abstract class CleanCommandAbstract extends Command
29 | {
30 |
31 | /** @var string Prestashop clean Module */
32 | protected $_cleanModuleName = 'pscleaner';
33 |
34 | /** @var PSCleaner | null */
35 | protected $_cleanModuleInstance = null;
36 |
37 | /**
38 | *
39 | * @param InputInterface $input
40 | * @param OutputInterface $output
41 | */
42 | protected function initialize(InputInterface $input, OutputInterface $output)
43 | {
44 | if ($module = Module::getInstanceByName($this->_cleanModuleName)) {
45 | if (!Module::isInstalled($module->name) || !$module->active) {
46 | $output->writeln('' . $this->_cleanModuleName . ' is not active or installed');
47 | return 0;
48 | }
49 | $this->_cleanModuleInstance = $module;
50 | } else {
51 | $output->writeln('' . $this->_cleanModuleName . ' is not installed');
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Dev/Cron/ListCronCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Dev\Cron;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputInterface;
25 | use Symfony\Component\Console\Output\OutputInterface;
26 | use Symfony\Component\Console\Helper\Table;
27 | use Module;
28 |
29 | class ListCronCommand extends Command
30 | {
31 |
32 | /** @var string cron Module Name */
33 | protected $_cronModuleName = 'cronjobs';
34 |
35 | protected function configure()
36 | {
37 | $this
38 | ->setName('dev:cron:list')
39 | ->setDescription('List cron tasks configured with the module cronjobs');
40 | }
41 |
42 | protected function execute(InputInterface $input, OutputInterface $output)
43 | {
44 | if ($module = Module::getInstanceByName($this->_cronModuleName)) {
45 | if (!Module::isInstalled($module->name) || !$module->active) {
46 | $output->writeln('' . $this->_cronModuleName . ' is not active or installed');
47 | return 1;
48 | }
49 |
50 | $output->writeln('Configured cron jobs');
51 |
52 | \CronJobsForms::init($module);
53 | $cronJobs = \CronJobsForms::getTasksListValues();
54 |
55 | $table = new Table($output);
56 | $table->setHeaders(['id_cronjob','description', 'task', 'hour', 'day', 'month', 'week_day', 'last_execution', 'active']);
57 | foreach ($cronJobs as $cronJob) {
58 | $table->addRow([
59 | $cronJob['id_cronjob'],
60 | $cronJob['description'],
61 | $cronJob['task'],
62 | $cronJob['hour'],
63 | $cronJob['day'],
64 | $cronJob['month'],
65 | $cronJob['week_day'],
66 | $cronJob['last_execution'],
67 | $cronJob['active']
68 | ]);
69 | }
70 | $table->render();
71 | } else {
72 | $output->writeln('' . $this->_cronModuleName . ' is not installed');
73 | return 1;
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Dev/Cron/RunCronCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Dev\Cron;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputArgument;
25 | use Symfony\Component\Console\Input\InputInterface;
26 | use Symfony\Component\Console\Output\OutputInterface;
27 | use Module;
28 |
29 | class RunCronCommand extends Command
30 | {
31 |
32 | /** @var string cron Module Name */
33 | protected $_cronModuleName = 'cronjobs';
34 |
35 | protected function configure()
36 | {
37 | $this
38 | ->setName('dev:cron:run')
39 | ->setDescription('Run cron task configured with the module cronjobs')
40 | ->addArgument(
41 | 'id_cronjob',
42 | InputArgument::REQUIRED,
43 | 'cron job id ( use command dev:cron:list to get it )'
44 | );
45 | }
46 |
47 | protected function execute(InputInterface $input, OutputInterface $output)
48 | {
49 | if ($module = Module::getInstanceByName($this->_cronModuleName)) {
50 | if (!Module::isInstalled($module->name) || !$module->active) {
51 | $output->writeln('' . $this->_cronModuleName . ' is not active or installed');
52 | return 1;
53 | }
54 |
55 | $cronjob_id = $input->getArgument('id_cronjob');
56 | $output->writeln($this->_runTask($cronjob_id));
57 | } else {
58 | $output->writeln('' . $this->_cronModuleName . ' is not installed');
59 | }
60 | }
61 |
62 | /**
63 | * Run task
64 | * @param type $cronjob_id
65 | * @return string
66 | */
67 | protected function _runTask($cronjob_id)
68 | {
69 | $cronJob = \Db::getInstance()->getRow("SELECT id_module,task FROM " . _DB_PREFIX_ . "cronjobs WHERE id_cronjob=" . (int) $cronjob_id);
70 |
71 | if (!$cronJob) {
72 | return 'Unknow cronjob_id';
73 | }
74 |
75 | if ($cronJob['id_module'] !== null) {
76 | \Hook::exec('actionCronJob', array(), $cronJob['id_module']);
77 | } else {
78 | \Tools::file_get_contents(urldecode($cronJob['task']), false);
79 | }
80 |
81 | \Db::getInstance()->execute("UPDATE " . _DB_PREFIX_ . "cronjobs SET `updated_at` = NOW() WHERE `id_cronjob` =" . (int) $cronjob_id);
82 |
83 | return 'Cron job run with success';
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Dev/DevModeCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright 2007-2019 Monterisi Sébastien
15 | * @copyright since 2016 Hennes Hervé
16 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
17 | *
18 | * https://github.com/nenes25/prestashop_console
19 | * https://www.h-hennes.fr/blog/
20 | */
21 |
22 | namespace Hhennes\PrestashopConsole\Command\Dev;
23 |
24 | use Symfony\Component\Console\Command\Command;
25 | use Symfony\Component\Console\Input\InputArgument;
26 | use Symfony\Component\Console\Input\InputInterface;
27 | use Symfony\Component\Console\Output\OutputInterface;
28 |
29 | /**
30 | * Command to change prestashop debug mode
31 | *
32 | */
33 | class DevModeCommand extends Command
34 | {
35 | /**
36 | * @var array possible allowed dev mode passed in command
37 | */
38 | private $allowed_command_states = ['enable', 'disable', 'toggle'];
39 |
40 | private $enable_code = 'setName('dev:mode')
48 | ->setDescription('Enable / Disable debug mode (to display errors).')
49 | ->addArgument(
50 | 'state',
51 | InputArgument::REQUIRED,
52 | 'enable or disable debug mode ( possible values : '.implode(",", $this->allowed_command_states).') '.PHP_EOL
53 | .$this->getWarningText()
54 | );
55 | }
56 |
57 | /**
58 | *
59 | * @param InputInterface $input
60 | * @param OutputInterface $output
61 | * @throws \Exception
62 | */
63 | protected function execute(InputInterface $input, OutputInterface $output)
64 | {
65 | try {
66 | // filter requested mode
67 | if (!in_array($input->getArgument('state'), $this->allowed_command_states)) {
68 | throw new \InvalidArgumentException("Unexpected state [".$input->getArgument('state')."] . Use one of : ".implode(",", $this->allowed_command_states));
69 | }
70 |
71 | // _PS_MODE_DEV_ not defined ?
72 | if (!defined('_PS_MODE_DEV_')) {
73 | throw new \RuntimeException(" constant _PS_MODE_DEV_ is not defined (?)");
74 | }
75 |
76 | // handle requested state
77 | $is_currently_enable = _PS_MODE_DEV_ ;
78 | $requested_state = $input->getArgument('state');
79 | if ($input->getArgument('state') === 'toggle') {
80 | $requested_state = $is_currently_enable ? 'disable' : 'enable';
81 | }
82 |
83 | // no need to change mode
84 | if ((_PS_MODE_DEV_ && $requested_state === 'enable') || (!_PS_MODE_DEV_ && $requested_state === 'disable')) {
85 | $output->writeln('Already in requested mode (_PS_MODE_DEV_ = '.(_PS_MODE_DEV_ ? 'true' : 'false').')');
86 | $output->writeln("{$this->getWarningText()}");
87 | return;
88 | }
89 |
90 | // create custom file if needed
91 | if (!file_exists($this->getDebugFilePath())) {
92 | if (!touch($this->getDebugFilePath())) {
93 | throw new \RuntimeException("Failed to create ".$this->getDebugFilePath());
94 | }
95 | }
96 |
97 | // open & modify config file
98 | $file_contents = $requested_state === 'enable' ? $this->enable_code : $this->disable_code;
99 |
100 | if (!file_put_contents($this->getDebugFilePath(), $file_contents)) {
101 | throw new \RuntimeException("Failed to write debug file. ");
102 | };
103 |
104 | $output->writeln("Debug mode successfully changed (_PS_MODE_DEV_ = ".($requested_state === 'enable' ? 'true' : 'false').")");
105 | $output->writeln("{$this->getWarningText()}");
106 | } catch (\Exception $e) {
107 | $output->writeln("ERROR:" . $e->getMessage() . "");
108 | return 1;
109 | }
110 | }
111 |
112 | private function getWarningText()
113 | {
114 | return 'Be sure to include "include(__DIR__. \'/'.$this->debug_file_name.'\');" in config/defines.inc.php for this feature to run.';
115 | }
116 |
117 | /**
118 | * @return string
119 | */
120 | protected function getDebugFilePath()
121 | {
122 | return getcwd() . '/config/' . $this->debug_file_name;
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Dev/IdeClassNamesCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Dev;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputInterface;
25 | use Symfony\Component\Console\Output\OutputInterface;
26 |
27 | /**
28 | * Récupération d'un fichier des classes pour l'autocomplétion dans l'IDE
29 | * ( PhpStorm / Netbeans ... )
30 | * Utilse le dépôt : https://github.com/julienbourdeau/PhpStorm-PrestaShop-Autocomplete
31 | */
32 | class IdeClassNamesCommand extends Command
33 | {
34 | const CLASS_NAME_SOURCE = 'https://raw.githubusercontent.com/julienbourdeau/PhpStorm-PrestaShop-Autocomplete/master/autocomplete.php';
35 | const CLASS_NAME_FILE = 'autocomplete.php';
36 |
37 | protected function configure()
38 | {
39 | $this
40 | ->setName('dev:ide-class-names')
41 | ->setDescription('Download class names index to resolve autocompletion in IDE');
42 | }
43 |
44 | /**
45 | * @param InputInterface $input
46 | * @param OutputInterface $output
47 | */
48 | public function execute(InputInterface $input, OutputInterface $output)
49 | {
50 | //Download content
51 | $content = file_get_contents(self::CLASS_NAME_SOURCE);
52 | $fileName= self::CLASS_NAME_FILE;
53 |
54 | if ($this->getApplication()->getRunAs() == 'php') {
55 | $fileName = '../'.$fileName;
56 | }
57 |
58 | if (file_put_contents($fileName, $content) !== false) {
59 | $output->writeln('File '.self::CLASS_NAME_FILE.' download with success');
60 | } else {
61 | $output->writeln('Unable to create file'.self::CLASS_NAME_FILE.'');
62 | return 1;
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Dev/ListOverridesCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Dev;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputInterface;
25 | use Symfony\Component\Console\Output\OutputInterface;
26 | use Symfony\Component\Finder\Finder;
27 |
28 | /**
29 | * Commande qui permet de lister les overrides en place sur le site
30 | *
31 | */
32 | class ListOverridesCommand extends Command
33 | {
34 | protected function configure()
35 | {
36 | $this
37 | ->setName('dev:list-overrides')
38 | ->setDescription('List overrides of classes and controllers in the project');
39 | }
40 |
41 | protected function execute(InputInterface $input, OutputInterface $output)
42 | {
43 | $outputString = '';
44 | try {
45 | $finder = new Finder();
46 | $finder->files()->in(_PS_OVERRIDE_DIR_)->name('*.php')->notName('index.php');
47 |
48 | foreach ($finder as $file) {
49 | $outputString.= $file->getRelativePathname()."\n";
50 | }
51 | } catch (\Exception $e) {
52 | $output->writeln("ERROR:" . $e->getMessage() . "");
53 | return 1;
54 | }
55 | if ($outputString == '') {
56 | $outputString = 'No class or controllers overrides on this project';
57 | }
58 | $output->writeln("".$outputString."");
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Hook/ListCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 |
22 | namespace Hhennes\PrestashopConsole\Command\Hook;
23 |
24 | use Symfony\Component\Console\Command\Command;
25 | use Symfony\Component\Console\Input\InputInterface;
26 | use Symfony\Component\Console\Output\OutputInterface;
27 | use Symfony\Component\Console\Helper\Table;
28 | use Hook;
29 |
30 | /**
31 | * Class Module
32 | * List hook with registered modules
33 | */
34 | class ListCommand extends Command
35 | {
36 | /**
37 | * @inheritDoc
38 | */
39 | protected function configure()
40 | {
41 | $this
42 | ->setName('hook:list')
43 | ->setDescription('List all hooks registered in database');
44 | }
45 |
46 | /**
47 | * @inheritDoc
48 | */
49 | public function execute(InputInterface $input, OutputInterface $output)
50 | {
51 | //Get Hooks list
52 | $hooks = Hook::getHooks();
53 |
54 | //Extract only hooks name
55 | $hooks = array_map(function ($row) {
56 | return $row['name'];
57 | }, $hooks);
58 |
59 | //Sort hooks by name
60 | usort($hooks, array($this, "cmp"));
61 |
62 | //Init Table
63 | $table = new Table($output);
64 | $table->setHeaders(['Hook Name']);
65 |
66 | foreach ($hooks as $hook) {
67 | $table->addRow([$hook]);
68 | }
69 |
70 | //Display result
71 | $table->render();
72 | }
73 |
74 | /**
75 | * Function to sort hook by name
76 | * @param $a
77 | * @param $b
78 | * @return int|\lt
79 | */
80 | private function cmp($a, $b)
81 | {
82 | return strcmp($a, $b);
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Hook/ModuleCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Hook;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputInterface;
25 | use Symfony\Component\Console\Output\OutputInterface;
26 | use Symfony\Component\Console\Helper\Table;
27 | use Hook;
28 |
29 | /**
30 | * Class Module
31 | * List hook with registered modules
32 | */
33 | class ModuleCommand extends Command
34 | {
35 | /**
36 | * @inheritDoc
37 | */
38 | protected function configure()
39 | {
40 | $this
41 | ->setName('hook:modules')
42 | ->setDescription('List all hooks with hooked modules');
43 | }
44 |
45 | /**
46 | * @inheritDoc
47 | */
48 | public function execute(InputInterface $input, OutputInterface $output)
49 | {
50 | //Get Hooks list
51 | $hooks = Hook::getHooks();
52 |
53 | //Extract only hooks name
54 | $hooks = array_map(function ($row) {
55 | return $row['name'];
56 | }, $hooks);
57 |
58 | //Sort hooks by name
59 | usort($hooks, array($this, "cmp"));
60 |
61 | //Init Table
62 | $table = new Table($output);
63 | $table->setHeaders(['Hook Name', 'Modules hooked']);
64 |
65 | foreach ($hooks as $hook) {
66 |
67 | //Get Modules hooked
68 | $hookModules = Hook::getHookModuleExecList($hook);
69 |
70 | if ($hookModules) {
71 |
72 | //Add module information on hook
73 | $hookModulesInformations = '';
74 | foreach ($hookModules as $index => $hookModule) {
75 | $hookModulesInformations .= ($index+1).".".$hookModule['module'].", ";
76 | }
77 | $table->addRow([$hook, trim($hookModulesInformations, ', ')]);
78 | }
79 | }
80 |
81 | //Display result
82 | $table->render();
83 | }
84 |
85 | /**
86 | * Function to sort hook by name
87 | * @param $a
88 | * @param $b
89 | * @return int|\lt
90 | */
91 | private function cmp($a, $b)
92 | {
93 | return strcmp($a, $b);
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Images/ExportCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Images;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputInterface;
25 | use Symfony\Component\Console\Input\InputOption;
26 | use Symfony\Component\Console\Output\OutputInterface;
27 | use Symfony\Component\Console\Question\Question;
28 | use RuntimeException;
29 |
30 | class ExportCommand extends Command
31 | {
32 |
33 | /** @var array Images Types */
34 | protected $_types = [
35 | 'all',
36 | 'admin',
37 | 'product',
38 | 'category',
39 | 'cms',
40 | 'tmp',
41 | ];
42 |
43 | /** @var array Archives Types */
44 | protected $_archivesFormat = [
45 | 'tar.gz',
46 | 'zip',
47 | ];
48 |
49 | protected $_type;
50 | protected $_archiveFormat;
51 |
52 | protected function configure()
53 | {
54 | $this
55 | ->setName('images:export')
56 | ->setDescription('Export images')
57 | ->addOption('type', 't', InputOption::VALUE_OPTIONAL, 'type of file to export')
58 | ->addOption('interactive', 'i', InputOption::VALUE_OPTIONAL, 'Interactive Mode')
59 | ->addOption('archive', 'a', InputOption::VALUE_OPTIONAL, 'Archive format', 'tar.gz');
60 | }
61 |
62 | /**
63 | *
64 | * @param InputInterface $input
65 | * @param OutputInterface $output
66 | * @return bool | void
67 | * @throws \Exception
68 | */
69 | protected function execute(InputInterface $input, OutputInterface $output)
70 | {
71 |
72 | //Shell_exec function is required
73 | //@Todo make it optionnal and do it also with php ( symfony finder )
74 | if (!function_exists('shell_exec')) {
75 | $output->writeln('The function shell_exec is not present');
76 | return false;
77 | }
78 |
79 | $this->_archiveFormat = $input->getOption('archive');
80 | if (!in_array($this->_archiveFormat, $this->_archivesFormat)) {
81 | $this->_archiveFormat = 'tar.gz';
82 | }
83 | $this->_type = $input->getOption('type');
84 |
85 | if ($input->getOption('interactive')) {
86 | $questionHelper = $this->getHelper('question');
87 | $imagesTypes = $this->_types;
88 | $typeQuestion = new Question('Image Type :');
89 | $typeQuestion->setAutocompleterValues($imagesTypes);
90 | $typeQuestion->setValidator(function ($answer) use ($imagesTypes) {
91 | if ($answer !== null && !in_array($answer, $imagesTypes)) {
92 | throw new RuntimeException('The field type must be part of the suggested');
93 | }
94 | return $answer;
95 | });
96 |
97 | $this->_type = $questionHelper->ask($input, $output, $typeQuestion);
98 | }
99 |
100 | $this->_exportImages($output);
101 | }
102 |
103 | /**
104 | * Export images
105 | * @param OutputInterface $output
106 | */
107 | protected function _exportImages(OutputInterface $output)
108 | {
109 | switch ($this->_type) {
110 |
111 | case 'admin':
112 | case 'cms':
113 | case 'tmp':
114 | $directory = $this->_type;
115 | break;
116 |
117 | case 'product':
118 | $directory = 'p';
119 | break;
120 |
121 | case 'category':
122 | $directory = 'c';
123 | break;
124 |
125 | default:
126 | $directory = "";
127 | break;
128 | }
129 |
130 | $exportPath = _PS_IMG_DIR_ . $directory;
131 |
132 | if (is_dir($exportPath)) {
133 | $filePath = _PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . date('YmdHi') . '-export-images' . $this->_type . '.' . $this->_archiveFormat;
134 |
135 | if ($this->_archiveFormat == 'tar.gz') {
136 | $command = 'tar czf ' . $filePath . ' *';
137 | } else {
138 | $command = 'zip -qr ' . $filePath . ' *';
139 | }
140 |
141 | $output->writeln('Images export started');
142 | $export = shell_exec("cd " . $exportPath . ' && ' . $command);
143 | $output->writeln($export);
144 | $output->writeln('Images export ended in path ' . $filePath . '');
145 | } else {
146 | $output->writeln('The path ' . $exportPath . ' does not exists');
147 | }
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Images/GenerateCategoriesCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Images;
22 |
23 | class GenerateCategoriesCommand extends GenerateAbstract
24 | {
25 | /** @var type string */
26 | const IMAGE_TYPE = 'categories';
27 | }
28 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Images/GenerateManufacturersCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Images;
22 |
23 | class GenerateManufacturersCommand extends GenerateAbstract
24 | {
25 | /** @var type string */
26 | const IMAGE_TYPE = 'manufacturers';
27 | }
28 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Images/GenerateProductsCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Images;
22 |
23 | class GenerateProductsCommand extends GenerateAbstract
24 | {
25 | /** @var type string */
26 | const IMAGE_TYPE = 'products';
27 | }
28 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Images/GenerateStoresCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Images;
22 |
23 | class GenerateStoresCommand extends GenerateAbstract
24 | {
25 | /** @var type string */
26 | const IMAGE_TYPE = 'stores';
27 | }
28 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Images/GenerateSuppliersCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Images;
22 |
23 | class GenerateSuppliersCommand extends GenerateAbstract
24 | {
25 | /** @var type string */
26 | const IMAGE_TYPE = 'suppliers';
27 | }
28 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Install/InfoCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Install;
22 |
23 | use Symfony\Component\Console\Input\InputInterface;
24 | use Symfony\Component\Console\Output\OutputInterface;
25 | use Symfony\Component\Console\Command\ListCommand;
26 |
27 | /**
28 | * This commands display information on ps install
29 | *
30 | */
31 | class InfoCommand extends ListCommand
32 | {
33 | protected function configure()
34 | {
35 | $this
36 | ->setName('install:info')
37 | ->setDescription('prestashop install info')
38 | ->setDefinition($this->getNativeDefinition());
39 | }
40 |
41 | protected function execute(InputInterface $input, OutputInterface $output)
42 | {
43 | parent::execute($input, $output);
44 | $output->writeln("No prestashop installation detected, please install it or place the console in the right place.");
45 | $output->writeln("Or run install:install to install a new prestashop website.");
46 | $output->writeln("All console commands will be available once a prestashop installation will be detected");
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Module/DisableCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Module;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputArgument;
25 | use Symfony\Component\Console\Input\InputInterface;
26 | use Symfony\Component\Console\Output\OutputInterface;
27 | use Module;
28 | use PrestaShopException;
29 |
30 | /**
31 | * Commande qui permet d'activer un module
32 | *
33 | */
34 | class DisableCommand extends Command
35 | {
36 | protected function configure()
37 | {
38 | $this
39 | ->setName('module:disable')
40 | ->setDescription('Disable module')
41 | ->addArgument(
42 | 'name',
43 | InputArgument::IS_ARRAY | InputArgument::REQUIRED,
44 | 'module name ( separate multiple with spaces )'
45 | );
46 | }
47 |
48 | protected function execute(InputInterface $input, OutputInterface $output)
49 | {
50 | $name = $input->getArgument('name');
51 |
52 | if (count($name) > 0) {
53 | foreach ($name as $moduleName) {
54 | if ($module = Module::getInstanceByName($moduleName)) {
55 | if (Module::isInstalled($module->name)) {
56 | try {
57 | $module->disable();
58 | } catch (PrestaShopException $e) {
59 | $outputString = 'Error : module ' . $moduleName . ' ' . $e->getMessage() . "";
60 | $output->writeln($outputString);
61 | return;
62 | }
63 | $outputString = 'Module ' . $moduleName . ' disable with sucess' . "";
64 | } else {
65 | $outputString = 'Error : module ' . $moduleName . ' is not installed' . "";
66 | }
67 | } else {
68 | $outputString = 'Error : Unknow module name ' . $moduleName . "";
69 | }
70 | $output->writeln($outputString);
71 | }
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Module/EnableCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Module;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputArgument;
25 | use Symfony\Component\Console\Input\InputInterface;
26 | use Symfony\Component\Console\Output\OutputInterface;
27 | use Module;
28 | use PrestaShopException;
29 |
30 | /**
31 | * Commande qui permet d'activer un module
32 | *
33 | */
34 | class EnableCommand extends Command
35 | {
36 | protected function configure()
37 | {
38 | $this->setName('module:enable')
39 | ->setDescription('Enable module')
40 | ->addArgument(
41 | 'name',
42 | InputArgument::IS_ARRAY | InputArgument::REQUIRED,
43 | 'module name ( separate multiple with spaces )'
44 | );
45 | }
46 |
47 | protected function execute(InputInterface $input, OutputInterface $output)
48 | {
49 | $name = $input->getArgument('name');
50 |
51 | if (count($name) > 0) {
52 | foreach ($name as $moduleName) {
53 | if ($module = Module::getInstanceByName($moduleName)) {
54 | if (Module::isInstalled($module->name)) {
55 |
56 | // Exécution de l'action du module
57 | try {
58 | $module->enable();
59 | } catch (PrestaShopException $e) {
60 | $outputString = 'module ' . $moduleName . ' ' . $e->getMessage() . "";
61 | $output->writeln($outputString);
62 | return;
63 | }
64 | $outputString = 'Module ' . $moduleName . ' enable with sucess' . "";
65 | } else {
66 | $outputString = 'module ' . $moduleName . ' is not installed' . "";
67 | }
68 | } else {
69 | $outputString = 'Unknow module name ' . $moduleName . "";
70 | }
71 | $output->writeln($outputString);
72 | }
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Module/Generate/ModuleHeader.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Module\Generate;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputArgument;
25 | use Symfony\Component\Console\Input\InputInterface;
26 | use Symfony\Component\Console\Output\OutputInterface;
27 | use Symfony\Component\Filesystem\Exception\IOException;
28 | use Symfony\Component\Filesystem\Filesystem;
29 |
30 | /**
31 | * Class UpgradeCommand
32 | * This command will create a new upgrade file
33 | * @package Hhennes\PrestashopConsole\Command\Module\Generate
34 | */
35 | class UpgradeCommand extends Command
36 | {
37 | /** @var string Module Name */
38 | protected $_moduleName;
39 |
40 | /** @var Filesystem */
41 | protected $_fileSystem;
42 | /**
43 | * @var OutputInterface
44 | */
45 | protected $_output;
46 |
47 | protected function configure()
48 | {
49 | $this
50 | ->setName('module:generate:upgrade')
51 | ->setDescription('Generate module upgrade file')
52 | ->setHelp(
53 | 'This command generate an upgrade file in the directory "upgrade" of the given module ' . PHP_EOL
54 | . 'In the following format upgrade-moduleVersion.php ' . PHP_EOL
55 | . 'Example : ' . PHP_EOL
56 | . './prestashopConsole.phar generate:module:upgrade samplemodule 0.2.0 : ' . PHP_EOL
57 | . 'will generate a file in modules/samplemodule/upgrade/upgrade-0.2.0.php' . PHP_EOL
58 | )
59 | ->addArgument('moduleName', InputArgument::REQUIRED, 'module name')
60 | ->addArgument('moduleVersion', InputArgument::REQUIRED, 'module version');
61 | }
62 |
63 | public function execute(InputInterface $input, OutputInterface $output)
64 | {
65 | $moduleName = $input->getArgument('moduleName');
66 | $moduleVersion = $input->getArgument('moduleVersion');
67 | $this->_fileSystem = new Filesystem();
68 | $this->_moduleName = $moduleName;
69 | $this->_output = $output;
70 |
71 | if (!$this->_isValidModuleVersion($moduleVersion)) {
72 | $output->writeln('Module version is not valid');
73 | return 1;
74 | }
75 | $convertedVersion = str_replace('.', '_', $moduleVersion);
76 |
77 | if (!is_dir(_PS_MODULE_DIR_ . $moduleName)) {
78 | $output->writeln('Module not exists');
79 | return 1;
80 | }
81 |
82 | try {
83 | $this->_createDirectories();
84 | } catch (IOException $e) {
85 | $output->writeln('Unable to creat ugrade directory');
86 | return 1;
87 | }
88 |
89 | $defaultContent = $this->_getDefaultContent();
90 | $defaultContent = str_replace('{version}', $convertedVersion, $defaultContent);
91 |
92 | try {
93 | $upgradeFile = _PS_MODULE_DIR_ . $moduleName . '/upgrade/upgrade-' . $moduleVersion . '.php';
94 | $this->_fileSystem->dumpFile(
95 | $upgradeFile,
96 | $defaultContent
97 | );
98 | $output->writeln('Create or update file ' . $upgradeFile . '');
99 | } catch (IOException $e) {
100 | $output->writeln('Unable to create upgrade file');
101 | return 1;
102 | }
103 |
104 | $output->writeln('Update file generated');
105 | return 0;
106 | }
107 |
108 | /**
109 | * Check if module version is in correct format
110 | * @param $moduleVersion
111 | * @return bool
112 | */
113 | protected function _isValidModuleVersion($moduleVersion)
114 | {
115 | return preg_match('#^[0-9]{1}\.[0-9]+\.?[0-9]*$#', $moduleVersion);
116 | }
117 |
118 | /**
119 | * @return string
120 | */
121 | protected function _getDefaultContent()
122 | {
123 | return
124 | '_moduleName . '/upgrade';
151 | if (!$this->_fileSystem->exists($upgradeDir)) {
152 | $this->_fileSystem->mkdir($upgradeDir, 0775);
153 | $this->_output->writeln('Create directory ' . $upgradeDir . '');
154 | }
155 | }
156 | }
157 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Module/Hook/AddModuleHooksCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Module\Hook;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputArgument;
25 | use Symfony\Component\Console\Input\InputInterface;
26 | use Symfony\Component\Console\Output\OutputInterface;
27 | use Module;
28 |
29 | /**
30 | * Commande qui permet de greffer des modules sur un hook
31 | *
32 | */
33 | class AddModuleHooksCommand extends Command
34 | {
35 | protected function configure()
36 | {
37 | $this
38 | ->setName('module:hook:add')
39 | ->setDescription('Add module to one or several hooks')
40 | ->addArgument(
41 | 'name',
42 | InputArgument::REQUIRED,
43 | 'module name'
44 | )
45 | ->addArgument(
46 | 'hooks',
47 | InputArgument::IS_ARRAY | InputArgument::REQUIRED,
48 | 'hooks name ( separate multiple with spaces )'
49 | );
50 | }
51 |
52 | /**
53 | *
54 | * @param InputInterface $input
55 | * @param OutputInterface $output
56 | */
57 | public function execute(InputInterface $input, OutputInterface $output)
58 | {
59 | $moduleName = $input->getArgument('name');
60 | $hooks = $input->getArgument('hooks');
61 |
62 | if ($module = Module::getInstanceByName($moduleName)) {
63 | if (! $module->registerHook($hooks)) {
64 | $output->writeln('Error during hook assignation');
65 | } else {
66 | $output->writeln('Module hooked with success');
67 | }
68 | } else {
69 | $output->writeln('Error the module ' . $moduleName . ' doesn\'t exists');
70 | return 1;
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Module/Hook/ListModuleHooksCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Module\Hook;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputArgument;
25 | use Symfony\Component\Console\Input\InputInterface;
26 | use Symfony\Component\Console\Output\OutputInterface;
27 | use Symfony\Component\Console\Helper\Table;
28 | use Module;
29 |
30 | /**
31 | * Commande qui permet de lister les hooks d'un module
32 | *
33 | */
34 | class ListModuleHooksCommand extends Command
35 | {
36 | protected function configure()
37 | {
38 | $this
39 | ->setName('module:hook:list')
40 | ->setDescription('Get modules list')
41 | ->addArgument(
42 | 'name',
43 | InputArgument::REQUIRED,
44 | 'module name'
45 | );
46 | }
47 |
48 | /**
49 | *
50 | * @param InputInterface $input
51 | * @param OutputInterface $output
52 | */
53 | public function execute(InputInterface $input, OutputInterface $output)
54 | {
55 | $moduleName = $input->getArgument('name');
56 |
57 | if ($module = Module::getInstanceByName($moduleName)) {
58 |
59 | //Possible hook list
60 | $possibleHooksList = $module->getPossibleHooksList();
61 | $moduleHooks = array();
62 |
63 | foreach ($possibleHooksList as $hook) {
64 | $isHooked = (int)$module->getPosition($hook['id_hook']);
65 | if ($isHooked != 0) {
66 | $moduleHooks[] = [
67 | 'name' => $hook['name'] ,
68 | 'position' => $isHooked
69 | ];
70 | }
71 | }
72 |
73 | if (count($moduleHooks)) {
74 | $output->writeln('The module ' . $moduleName . ' is linked on the following hooks :');
75 | $table = new Table($output);
76 | $table->setHeaders(['Hook Name','Position']);
77 | foreach ($moduleHooks as $moduleHook) {
78 | $table->addRow([$moduleHook['name'],$moduleHook['position']]);
79 | }
80 | $table->render();
81 | } else {
82 | $output->writeln('The module is not hooked');
83 | }
84 | } else {
85 | $output->writeln('Error the module ' . $moduleName . ' doesn\'t exists');
86 | return 1;
87 | }
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Module/Hook/RemoveModuleHooksCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Module\Hook;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputArgument;
25 | use Symfony\Component\Console\Input\InputInterface;
26 | use Symfony\Component\Console\Output\OutputInterface;
27 | use Module;
28 |
29 | /**
30 | * Commande qui permet de supprimer les modules d'un hook
31 | *
32 | */
33 | class RemoveModuleHooksCommand extends Command
34 | {
35 | protected function configure()
36 | {
37 | $this
38 | ->setName('module:hook:remove')
39 | ->setDescription('Remove module to one or several hooks')
40 | ->addArgument(
41 | 'name',
42 | InputArgument::REQUIRED,
43 | 'module name'
44 | )
45 | ->addArgument(
46 | 'hooks',
47 | InputArgument::IS_ARRAY | InputArgument::REQUIRED,
48 | 'hooks name ( separate multiple with spaces )'
49 | );
50 | }
51 |
52 | /**
53 | *
54 | * @param InputInterface $input
55 | * @param OutputInterface $output
56 | */
57 | public function execute(InputInterface $input, OutputInterface $output)
58 | {
59 | $moduleName = $input->getArgument('name');
60 | $hooks = $input->getArgument('hooks');
61 |
62 | if ($module = Module::getInstanceByName($moduleName)) {
63 | if (sizeof($hooks)) {
64 | foreach ($hooks as $hook) {
65 | if (!$module->unregisterHook($hook)) {
66 | $output->writeln('Error during hook remove from hook '.$hook.'');
67 | return 1;
68 | } else {
69 | $output->writeln('Module remove from hook '.$hook.' with success');
70 | }
71 | }
72 | } else {
73 | $output->writeln('Not hooks given for ' . $moduleName . '');
74 | return 1;
75 | }
76 | } else {
77 | $output->writeln('Error the module ' . $moduleName . ' doesn\'t exists');
78 | return 1;
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Module/InstallCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Module;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputArgument;
25 | use Symfony\Component\Console\Input\InputInterface;
26 | use Symfony\Component\Console\Output\OutputInterface;
27 | use Module;
28 | use PrestaShopException;
29 |
30 | class InstallCommand extends Command
31 | {
32 | protected function configure()
33 | {
34 | $this->setName('module:install')
35 | ->setDescription('Install module')
36 | ->addArgument(
37 | 'name',
38 | InputArgument::IS_ARRAY | InputArgument::REQUIRED,
39 | 'module name ( separate multiple with spaces )'
40 | );
41 | }
42 |
43 | protected function execute(InputInterface $input, OutputInterface $output)
44 | {
45 | $name = $input->getArgument('name');
46 |
47 | if (count($name) > 0) {
48 | foreach ($name as $moduleName) {
49 | if ($module = Module::getInstanceByName($moduleName)) {
50 | if (!Module::isInstalled($module->name)) {
51 | try {
52 | if (!$module->install()) {
53 | $output->writeln("Cannot install module: '$moduleName'");
54 | return 1;
55 | }
56 | } catch (PrestaShopException $e) {
57 | $output->writeln("Module: '$moduleName' $e->displayMessage()");
58 | return 1;
59 | }
60 | $output->writeln("Module '$moduleName' installed with success");
61 | } else {
62 | $output->writeln("Module '$moduleName' is installed");
63 | }
64 | } else {
65 | $output->writeln("Unknow module name '$moduleName' ");
66 | return 1;
67 | }
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Module/ResetCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Module;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputArgument;
25 | use Symfony\Component\Console\Input\InputInterface;
26 | use Symfony\Component\Console\Input\InputOption;
27 | use Symfony\Component\Console\Output\OutputInterface;
28 | use Module;
29 | use PrestaShopException;
30 |
31 | class ResetCommand extends Command
32 | {
33 | protected function configure()
34 | {
35 | $this->setName('module:reset')
36 | ->setDescription('Reset module: hard = remove data and reinstall, soft(default) = keep data and reinstall')
37 | ->addArgument(
38 | 'name',
39 | InputArgument::IS_ARRAY | InputArgument::REQUIRED,
40 | 'module name ( separate multiple with spaces )'
41 | )
42 | ->addOption('type', null, InputOption::VALUE_OPTIONAL, 'hard|soft(default)');
43 | }
44 |
45 | protected function execute(InputInterface $input, OutputInterface $output)
46 | {
47 | $name = $input->getArgument('name');
48 | $type = $input->getOption('type');
49 |
50 | if (count($name) > 0) {
51 | foreach ($name as $moduleName) {
52 | if ($module = Module::getInstanceByName($moduleName)) {
53 | if (Module::isInstalled($module->name)) {
54 | try {
55 | $error = false;
56 | switch ($type) {
57 | case 'hard':
58 | if ($module->uninstall()) {
59 | if (!$module->install()) {
60 | $output->writeln("Cannot install module: '$moduleName'");
61 | $error = true;
62 | }
63 | } else {
64 | $output->writeln("Cannot uninstall module: '$moduleName'");
65 | $error = true;
66 | }
67 | break;
68 | case 'soft':
69 | default:
70 | if (method_exists($module, 'reset')) {
71 | if (!$module->reset()) {
72 | $output->writeln("Cannot reset module: '$moduleName'");
73 | $error = true;
74 | }
75 | } else {
76 | $output->writeln("Module '$moduleName' doesnt support soft reset");
77 | $error = true;
78 | }
79 | break;
80 | }
81 | } catch (PrestaShopException $e) {
82 | $output->writeln("Module: '$moduleName' $e->getMessage()");
83 | $error = true;
84 | }
85 | if (!$error) {
86 | $output->writeln("Module '$moduleName' reset with success");
87 | } else {
88 | return 1;
89 | }
90 | } else {
91 | $output->writeln("Module '$moduleName' is uninstalled");
92 | }
93 | } else {
94 | $output->writeln("Unknow module name '$moduleName' ");
95 | return 1;
96 | }
97 | }
98 | }
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Module/Tab/AddCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Module\Tab;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputArgument;
25 | use Symfony\Component\Console\Input\InputInterface;
26 | use Symfony\Component\Console\Input\InputOption;
27 | use Symfony\Component\Console\Output\OutputInterface;
28 | use Module;
29 | use Tab;
30 | use Language;
31 |
32 | /**
33 | * This command create new admin tab for given module
34 | */
35 | class AddCommand extends Command
36 | {
37 | /**
38 | * @inheritDoc
39 | */
40 | protected function configure()
41 | {
42 | $this
43 | ->setName('module:tab:add')
44 | ->setDescription('Add module admin tab')
45 | ->addArgument('name', InputArgument::REQUIRED, 'module name')
46 | ->addArgument('tab', InputArgument::REQUIRED, 'tab class name')
47 | ->addArgument('label', InputArgument::REQUIRED, 'tab label')
48 | ->addOption(
49 | 'parentTab',
50 | 'p',
51 | InputOption::VALUE_OPTIONAL,
52 | 'Parent tab',
53 | 'DEFAULT'
54 | )
55 | ->addOption('icon', 'i', InputOption::VALUE_OPTIONAL, 'Tab icon')
56 | ->setHelp('Allow to add a new admin tab (controller )');
57 | }
58 |
59 |
60 | /**
61 | * @inheritDoc
62 | */
63 | public function execute(InputInterface $input, OutputInterface $output)
64 | {
65 | $moduleName = $input->getArgument('name');
66 | $tabClass = $input->getArgument('tab');
67 | $label = $input->getArgument('label');
68 | $parentTab = $input->getOption('parentTab');
69 | $icon = $input->getOption('icon');
70 |
71 | if ($module = Module::getInstanceByName($moduleName)) {
72 | try {
73 | $tab = new Tab();
74 | $tab->class_name = $tabClass;
75 | $tab->module = $moduleName;
76 | $tab->id_parent = (int)Tab::getIdFromClassName($parentTab);
77 | if (null !== $icon) {
78 | $tab->icon = $icon;
79 | }
80 | $languages = Language::getLanguages();
81 | foreach ($languages as $lang) {
82 | $tab->name[$lang['id_lang']] = $label;
83 | }
84 |
85 | $tab->save();
86 | } catch (\Exception $e) {
87 | $output->writeln('' . $e->getMessage() . '');
88 | return 1;
89 | }
90 | $output->writeln('Tab ' . $tabClass . ' added with success');
91 | } else {
92 | $output->writeln('Error the module ' . $moduleName . ' doesn\'t exists');
93 | return 1;
94 | }
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Module/Tab/ListCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Module\Tab;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputArgument;
25 | use Symfony\Component\Console\Input\InputInterface;
26 | use Symfony\Component\Console\Output\OutputInterface;
27 | use Symfony\Component\Console\Helper\Table;
28 | use Module;
29 | use Tab;
30 |
31 | /**
32 | * This command list module tabs
33 | */
34 | class ListCommand extends Command
35 | {
36 | protected function configure()
37 | {
38 | $this
39 | ->setName('module:tab:list')
40 | ->setDescription('list module admin tab')
41 | ->addArgument(
42 | 'name',
43 | InputArgument::REQUIRED,
44 | 'module name'
45 | );
46 | }
47 |
48 | /**
49 | * @param InputInterface $input
50 | * @param OutputInterface $output
51 | * @return int|string|void|null
52 | */
53 | public function execute(InputInterface $input, OutputInterface $output)
54 | {
55 | $moduleName = $input->getArgument('name');
56 | if ($module = Module::getInstanceByName($moduleName)) {
57 | $tabs = Tab::getCollectionFromModule($moduleName);
58 | $results = $tabs->getResults();
59 | if (count($results)) {
60 | $output->writeln('Module ' . $moduleName . 'admin tabs');
61 | $table = new Table($output);
62 | $table->setHeaders(['id', 'class', 'label']);
63 | foreach ($results as $tab) {
64 | /** @var Tab $tab */
65 | $table->addRow([$tab->id, $tab->class_name, $tab->name]);
66 | }
67 | $table->render();
68 | } else {
69 | $output->writeln('Module ' . $moduleName . ' has no admin tabs');
70 | }
71 | } else {
72 | $output->writeln('Error the module ' . $moduleName . ' doesn\'t exists');
73 | return 1;
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Module/Tab/RemoveCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Module\Tab;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputArgument;
25 | use Symfony\Component\Console\Input\InputInterface;
26 | use Symfony\Component\Console\Output\OutputInterface;
27 | use Module;
28 | use Tab;
29 |
30 | class RemoveCommand extends Command
31 | {
32 | protected function configure()
33 | {
34 | $this
35 | ->setName('module:tab:remove')
36 | ->setDescription('remove module admin tab')
37 | ->addArgument(
38 | 'name',
39 | InputArgument::REQUIRED,
40 | 'module name'
41 | )
42 | ->addArgument(
43 | 'tab',
44 | InputArgument::REQUIRED,
45 | 'tab class name'
46 | );
47 | }
48 |
49 | /**
50 | * @param InputInterface $input
51 | * @param OutputInterface $output
52 | * @return int|void|null
53 | */
54 | public function execute(InputInterface $input, OutputInterface $output)
55 | {
56 | $moduleName = $input->getArgument('name');
57 | $tab = $input->getArgument('tab');
58 |
59 | try {
60 | if ($module = Module::getInstanceByName($moduleName)) {
61 | if ($id_tab = Tab::getIdFromClassName($tab)) {
62 | $tabObject = new Tab($id_tab);
63 | try {
64 | $tabObject->delete();
65 | } catch (\Exception $e) {
66 | $output->writeln('' . $e->getMessage() . '');
67 | return 1;
68 | }
69 | $output->writeln('Tab ' . $tab . ' removed with success');
70 | } else {
71 | $output->writeln('Tab ' . $tab . ' does not exists');
72 | return 1;
73 | }
74 | } else {
75 | $output->writeln('Error the module ' . $moduleName . ' doesn\'t exists');
76 | }
77 | } catch (\Exception $e) {
78 | $output->writeln('Error unable to get information about ' . $moduleName . '');
79 | return 1;
80 | }
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Module/UninstallCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Module;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputArgument;
25 | use Symfony\Component\Console\Input\InputInterface;
26 | use Symfony\Component\Console\Output\OutputInterface;
27 | use Module;
28 | use PrestaShopException;
29 |
30 | class UninstallCommand extends Command
31 | {
32 | protected function configure()
33 | {
34 | $this->setName('module:uninstall')
35 | ->setDescription('Uninstall module')
36 | ->addArgument(
37 | 'name',
38 | InputArgument::IS_ARRAY | InputArgument::REQUIRED,
39 | 'module name ( separate multiple with spaces )'
40 | );
41 | }
42 |
43 | protected function execute(InputInterface $input, OutputInterface $output)
44 | {
45 | $name = $input->getArgument('name');
46 |
47 | if (count($name) > 0) {
48 | foreach ($name as $moduleName) {
49 | if ($module = Module::getInstanceByName($moduleName)) {
50 | if (Module::isInstalled($module->name)) {
51 | try {
52 | if (!$module->uninstall()) {
53 | $output->writeln("Cannot uninstall module: '$moduleName'");
54 | return 1;
55 | }
56 | } catch (PrestaShopException $e) {
57 | $output->writeln("Module: '$moduleName' $e->getMessage()");
58 | return 1;
59 | }
60 | $output->writeln("Module '$moduleName' uninstalled with success");
61 | } else {
62 | $output->writeln("Module '$moduleName' is uninstalled");
63 | }
64 | } else {
65 | $output->writeln("Unknow module name '$moduleName' ");
66 | return 1;
67 | }
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Parameters/Generate/HtaccessCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Parameters\Generate;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputInterface;
25 | use Symfony\Component\Console\Output\OutputInterface;
26 | use Tools;
27 |
28 | /**
29 | * Class HtaccessCommand
30 | * This command will generate the .htaccess file
31 | * @package Hhennes\PrestashopConsole\Command\Parameters\Generate
32 | */
33 | class HtaccessCommand extends Command
34 | {
35 | /**
36 | * @inheritDoc
37 | */
38 | protected function configure()
39 | {
40 | $this
41 | ->setName('parameters:generate:htaccess')
42 | ->setDescription('Generate the .htaccess file');
43 | }
44 |
45 | /**
46 | * @inheritDoc
47 | */
48 | protected function execute(InputInterface $input, OutputInterface $output)
49 | {
50 | if (true === Tools::generateHtaccess()) {
51 | $output->writeln(".htaccess file generated with success");
52 | } else {
53 | $output->writeln("An error occurs while generating .htaccess file");
54 | return 1;
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Parameters/Generate/RobotsTxtCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Parameters\Generate;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputOption;
25 | use Symfony\Component\Console\Input\InputInterface;
26 | use Symfony\Component\Console\Output\OutputInterface;
27 | use Tools;
28 |
29 | /**
30 | * Class RobotsTxtCommand
31 | * This command will generate the robots.txt file
32 | * @package Hhennes\PrestashopConsole\Command\Parameters\Generate
33 | */
34 | class RobotsTxtCommand extends Command
35 | {
36 |
37 | /**
38 | * @inheritDoc
39 | */
40 | protected function configure()
41 | {
42 | $this
43 | ->setName('parameters:generate:robots')
44 | ->setDescription('Generate the robots.txt file')
45 | ->addOption(
46 | 'executeHook',
47 | 'e',
48 | InputOption::VALUE_OPTIONAL,
49 | 'Generate actionAdminMetaBeforeWriteRobotsFile hook ?'
50 | );
51 | }
52 |
53 | /**
54 | * @inheritDoc
55 | */
56 | protected function execute(InputInterface $input, OutputInterface $output)
57 | {
58 | $input->getOption('executeHook') ? $executeHook = true : $executeHook = false;
59 |
60 | if (true === Tools::generateRobotsFile($executeHook)) {
61 | $output->writeln("robots.txt file generated with success");
62 | } else {
63 | $output->writeln("An error occurs while generating robots.txt file");
64 | return 1;
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Preferences/CmsCategoryCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Preferences;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputArgument;
25 | use Symfony\Component\Console\Input\InputInterface;
26 | use Symfony\Component\Console\Output\OutputInterface;
27 | use Context;
28 | use Shop;
29 | use CMSCategory;
30 |
31 | /**
32 | * This commands allow to enable/disable cms categories
33 | *
34 | */
35 | class CmsCategoryCommand extends Command
36 | {
37 | protected function configure()
38 | {
39 | $this
40 | ->setName('preferences:cmscategory')
41 | ->setDescription('Disable or enable a specific cms category')
42 | ->addArgument(
43 | 'id',
44 | InputArgument::REQUIRED,
45 | 'cms category id'
46 | )
47 | ->addArgument(
48 | 'action',
49 | InputArgument::OPTIONAL,
50 | 'enable|disable(default)'
51 | );
52 | }
53 |
54 | protected function execute(InputInterface $input, OutputInterface $output)
55 | {
56 | $id_cms = $input->getArgument('id');
57 | $action = $input->getArgument('action');
58 |
59 | Context::getContext()->shop->setContext(Shop::CONTEXT_ALL);
60 |
61 | $cmsCategory = new CMSCategory($id_cms);
62 |
63 | if ($cmsCategory->id == null) {
64 | $output->writeln(sprintf("Error Cms category %d doesn't exists", $id_cms));
65 | return 1;
66 | }
67 |
68 | switch ($action) {
69 | case 'enable':
70 | $cmsCategory->active = 1;
71 | $output->writeln(sprintf("Enable cms category %d", $id_cms));
72 | break;
73 | case 'disable':
74 | default:
75 | $output->writeln(sprintf("Disable cms category %d", $id_cms));
76 | $cmsCategory->active = 0;
77 | break;
78 | }
79 |
80 | try {
81 | $cmsCategory->save();
82 | } catch (\Exception $e) {
83 | $output->writeln(''.$e->getMessage().'');
84 | return 1;
85 | }
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Preferences/CmsCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Preferences;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputArgument;
25 | use Symfony\Component\Console\Input\InputInterface;
26 | use Symfony\Component\Console\Output\OutputInterface;
27 | use Context;
28 | use Shop;
29 | use CMS;
30 |
31 | /**
32 | * This commands allow to enable/disable cms pages
33 | *
34 | */
35 | class CmsCommand extends Command
36 | {
37 | protected function configure()
38 | {
39 | $this
40 | ->setName('preferences:cmspage')
41 | ->setDescription('Disable or enable a specific cms page')
42 | ->addArgument(
43 | 'id',
44 | InputArgument::REQUIRED,
45 | 'cms page id'
46 | )
47 | ->addArgument(
48 | 'action',
49 | InputArgument::OPTIONAL,
50 | 'enable|disable(default'
51 | );
52 | }
53 |
54 | protected function execute(InputInterface $input, OutputInterface $output)
55 | {
56 | $id_cms = $input->getArgument('id');
57 | $action = $input->getArgument('action');
58 |
59 | Context::getContext()->shop->setContext(Shop::CONTEXT_ALL);
60 |
61 | $cms = new CMS($id_cms);
62 |
63 | if ($cms->id == null) {
64 | $output->writeln(sprintf("Error Cms page %d doesn't exists", $id_cms));
65 | return 1;
66 | }
67 |
68 | switch ($action) {
69 | case 'enable':
70 | $cms->active = 1;
71 | $output->writeln(sprintf("Enable cms page %d", $id_cms));
72 | break;
73 | case 'disable':
74 | default:
75 | $output->writeln(sprintf("Disable cms page %d", $id_cms));
76 | $cms->active = 0;
77 | break;
78 | }
79 |
80 | try {
81 | $cms->save();
82 | } catch (\Exception $e) {
83 | $output->writeln(''.$e->getMessage().'');
84 | return 1;
85 | }
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Preferences/MaintenanceCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright 2019 Mariusz Mielnik
15 | * @copyright since 2016 Hennes Hervé
16 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
17 | *
18 | * https://github.com/nenes25/prestashop_console
19 | * https://www.h-hennes.fr/blog/
20 | */
21 |
22 | namespace Hhennes\PrestashopConsole\Command\Preferences;
23 |
24 | use Symfony\Component\Console\Command\Command;
25 | use Symfony\Component\Console\Input\InputArgument;
26 | use Symfony\Component\Console\Input\InputInterface;
27 | use Symfony\Component\Console\Output\OutputInterface;
28 | use Context;
29 | use Shop;
30 | use Configuration;
31 |
32 | class MaintenanceCommand extends Command
33 | {
34 | protected function configure()
35 | {
36 | $this
37 | ->setName('preferences:maintenance')
38 | ->setDescription('Disable or enable shop')
39 | ->addArgument(
40 | 'type',
41 | InputArgument::OPTIONAL,
42 | 'enable|disable(default)'
43 | );
44 | }
45 |
46 | protected function execute(InputInterface $input, OutputInterface $output)
47 | {
48 | $type = $input->getArgument('type');
49 | Context::getContext()->shop->setContext(Shop::CONTEXT_ALL);
50 |
51 | switch ($type) {
52 | case 'enable':
53 | $output->writeln("Shop is enabled");
54 | Configuration::updateValue('PS_SHOP_ENABLE', 1);
55 | break;
56 | case 'disable':
57 | default:
58 | $output->writeln("Shop is disabled");
59 | Configuration::updateValue('PS_SHOP_ENABLE', 0);
60 | break;
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Preferences/OverrideCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Preferences;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputArgument;
25 | use Symfony\Component\Console\Input\InputInterface;
26 | use Symfony\Component\Console\Output\OutputInterface;
27 | use Context;
28 | use Shop;
29 | use Configuration;
30 |
31 | /**
32 | * Commande qui permet d'activer / desactiver les override
33 | *
34 | */
35 | class OverrideCommand extends Command
36 | {
37 | protected function configure()
38 | {
39 | $this
40 | ->setName('preferences:override')
41 | ->setDescription('Disable or enable Override')
42 | ->addArgument(
43 | 'type',
44 | InputArgument::OPTIONAL,
45 | 'enable|disable(default)'
46 | );
47 | }
48 |
49 | protected function execute(InputInterface $input, OutputInterface $output)
50 | {
51 | $type = $input->getArgument('type');
52 |
53 | Context::getContext()->shop->setContext(Shop::CONTEXT_ALL);
54 |
55 | switch ($type) {
56 | case 'enable':
57 | case 1:
58 | $output->writeln("All override are enabled");
59 | Configuration::updateValue('PS_DISABLE_OVERRIDES', 0);
60 | break;
61 | case 'disable':
62 | default:
63 | $output->writeln("All override are disabled");
64 | Configuration::updateValue('PS_DISABLE_OVERRIDES', 1);
65 | break;
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Preferences/Search/IndexCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright 2019 Mariusz Mielnik
15 | * @copyright since 2016 Hennes Hervé
16 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
17 | *
18 | * https://github.com/nenes25/prestashop_console
19 | * https://www.h-hennes.fr/blog/
20 | */
21 |
22 | namespace Hhennes\PrestashopConsole\Command\Preferences\Search;
23 |
24 | use Symfony\Component\Console\Command\Command;
25 | use Symfony\Component\Console\Input\InputArgument;
26 | use Symfony\Component\Console\Input\InputInterface;
27 | use Symfony\Component\Console\Output\OutputInterface;
28 | use Context;
29 | use Shop;
30 | use Search;
31 | use Db;
32 |
33 | /**
34 | * Commands: Add missing products to the index or re-build the entire index
35 | *
36 | */
37 | class IndexCommand extends Command
38 | {
39 | protected function configure()
40 | {
41 | $this
42 | ->setName('preferences:search:index')
43 | ->setDescription('Add missing products to the index or re-build the entire index (default)')
44 | ->addArgument(
45 | 'type',
46 | InputArgument::OPTIONAL,
47 | 'add|rebuild(default)'
48 | );
49 | }
50 |
51 | protected function execute(InputInterface $input, OutputInterface $output)
52 | {
53 | $type = $input->getArgument('type');
54 |
55 | Context::getContext()->shop->setContext(Shop::CONTEXT_ALL);
56 |
57 | switch ($type) {
58 | case 'add':
59 | $output->writeln('Adding missing products to the index...');
60 | Search::indexation();
61 | break;
62 | case 'rebuild':
63 | default:
64 | $output->writeln('Re-building the entire index...');
65 | Search::indexation(1);
66 | break;
67 | }
68 |
69 | list($total, $indexed) = Db::getInstance()->getRow('SELECT COUNT(*) as "0", SUM(product_shop.indexed) as "1" FROM ' . _DB_PREFIX_ . 'product p ' . Shop::addSqlAssociation('product', 'p') . ' WHERE product_shop.`visibility` IN ("both", "search") AND product_shop.`active` = 1');
70 |
71 | $output->writeln('Currently indexed products: ' . (int)$indexed . ' / ' . (int)$total . '');
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Preferences/UrlRewriteCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole\Command\Preferences;
22 |
23 | use Symfony\Component\Console\Command\Command;
24 | use Symfony\Component\Console\Input\InputArgument;
25 | use Symfony\Component\Console\Input\InputInterface;
26 | use Symfony\Component\Console\Output\OutputInterface;
27 | use Context;
28 | use Shop;
29 | use Configuration;
30 |
31 | /**
32 | * Commande qui permet d'activer / desactiver la réécriture d'url
33 | *
34 | */
35 | class UrlRewriteCommand extends Command
36 | {
37 | protected function configure()
38 | {
39 | $this
40 | ->setName('preferences:urlrewrite')
41 | ->setDescription('Disable or enable Url Rewrite')
42 | ->addArgument(
43 | 'type',
44 | InputArgument::OPTIONAL,
45 | 'enable|disable(default)'
46 | );
47 | }
48 |
49 | protected function execute(InputInterface $input, OutputInterface $output)
50 | {
51 | $type = $input->getArgument('type');
52 |
53 | Context::getContext()->shop->setContext(Shop::CONTEXT_ALL);
54 |
55 | switch ($type) {
56 | case 'enable':
57 | $output->writeln("Url rewrite is enabled");
58 | Configuration::updateValue('PS_REWRITING_SETTINGS', 1);
59 | break;
60 | case 'disable':
61 | default:
62 | $output->writeln("Url rewrite is disabled");
63 | Configuration::updateValue('PS_REWRITING_SETTINGS', 0);
64 | break;
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Webservice/CreateKeyCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 |
22 | namespace Hhennes\PrestashopConsole\Command\Webservice;
23 |
24 | use Symfony\Component\Console\Command\Command;
25 | use Symfony\Component\Console\Input\InputInterface;
26 | use Symfony\Component\Console\Output\OutputInterface;
27 | use Symfony\Component\Console\Input\InputOption;
28 | use PrestaShopException;
29 | use WebserviceKey;
30 | use WebserviceRequest;
31 | use Tools;
32 |
33 | /**
34 | * Class CreateKey
35 | * Create an api key in prestashop
36 | */
37 | class CreateKeyCommand extends Command
38 | {
39 | /** @var string Option Key */
40 | const OPTION_KEY = 'key';
41 |
42 | /** @var string Option description */
43 | const OPTION_DESCRIPTION = 'description';
44 |
45 | /**
46 | * @inheritDoc
47 | */
48 | protected function configure()
49 | {
50 | $this
51 | ->setName('webservice:key:create')
52 | ->setDescription('Create a webservice key')
53 | ->addOption(
54 | self::OPTION_KEY,
55 | 'k',
56 | InputOption::VALUE_OPTIONAL,
57 | 'Force a key ( get a new one by default)'
58 | )
59 | ->addOption(
60 | self::OPTION_DESCRIPTION,
61 | 'd',
62 | InputOption::VALUE_OPTIONAL,
63 | 'Api Key description',
64 | 'Api key created by prestashop console'
65 | );
66 | }
67 |
68 | /**
69 | * @inheritDoc
70 | */
71 | public function execute(InputInterface $input, OutputInterface $output)
72 | {
73 | $apiKey = $input->getOption(self::OPTION_KEY);
74 | $apiDescription = $input->getOption(self::OPTION_DESCRIPTION);
75 |
76 | if (null !== $apiKey) {
77 | if (!$this->_validateWebserviceKey($apiKey)) {
78 | $output->writeln('The api key is invalid ( 32 characters required)');
79 | return 1;
80 | }
81 | if (WebserviceKey::keyExists(pSQL($apiKey))) {
82 | $output->writeln('The api key already exists');
83 | return 1;
84 | }
85 | }
86 |
87 | $webserviceKey = new WebserviceKey();
88 | $webserviceKey->key = $apiKey ? $apiKey : $this->_generateWebserviceKey();
89 | $webserviceKey->description = $apiDescription;
90 |
91 | try {
92 | $webserviceKey->save();
93 | WebserviceKey::setPermissionForAccount($webserviceKey->id, $this->_getPermissions());
94 | } catch (PrestaShopException $e) {
95 | $output->writeln('An error occurs while saving webservice key');
96 | return 1;
97 | }
98 |
99 | $output->writeln("Webservice key created with success", OutputInterface::VERBOSITY_VERBOSE);
100 | $output->writeln($webserviceKey->key);
101 |
102 | return 0;
103 | }
104 |
105 | /**
106 | * Get permission for webservice Key
107 | * For now the key will have all accesses
108 | * @return array
109 | */
110 | protected function _getPermissions()
111 | {
112 | $resources = WebserviceRequest::getResources();
113 | $methods = array('GET', 'PUT', 'POST', 'DELETE', 'HEAD');
114 | $permissions = [];
115 | foreach ($resources as $resource => $params) {
116 | foreach ($methods as $method) {
117 | if (array_key_exists('forbidden_method', $params) && in_array($method, $params['forbidden_method'])) {
118 | continue;
119 | }
120 | $permissions[$resource][$method] = 1;
121 | }
122 | }
123 | return $permissions;
124 | }
125 |
126 | /**
127 | * Get a random api key
128 | * @return string
129 | */
130 | protected function _generateWebserviceKey()
131 | {
132 | return Tools::passwdGen(32, 'NO_NUMERIC');
133 | }
134 |
135 | /**
136 | * Validate that provided key is valid
137 | * @param string $key
138 | * @return bool
139 | */
140 | protected function _validateWebserviceKey($key)
141 | {
142 | return (bool)preg_match('/^[A-Z_0-9-]{32}$/', $key);
143 | }
144 | }
145 |
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/Command/Webservice/DeleteKeyCommand.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 |
22 | namespace Hhennes\PrestashopConsole\Command\Webservice;
23 |
24 | use Symfony\Component\Console\Command\Command;
25 | use Symfony\Component\Console\Input\InputInterface;
26 | use Symfony\Component\Console\Input\InputArgument;
27 | use Symfony\Component\Console\Output\OutputInterface;
28 | use PrestaShopException;
29 | use WebserviceKey;
30 | use Db;
31 |
32 | /**
33 | * Class DeleteKey
34 | * Delete webservice key
35 | */
36 | class DeleteKeyCommand extends Command
37 | {
38 |
39 | /** @var string Argument Key */
40 | const ARGUMENT_KEY = 'key';
41 |
42 | /**
43 | * @inheritDoc
44 | */
45 | protected function configure()
46 | {
47 | $this
48 | ->setName('webservice:key:delete')
49 | ->setDescription('Delet a webservice key')
50 | ->addArgument(
51 | self::ARGUMENT_KEY,
52 | InputArgument::REQUIRED,
53 | 'Webservice key to delete'
54 | );
55 | }
56 |
57 | /**
58 | * @inheritDoc
59 | */
60 | public function execute(InputInterface $input, OutputInterface $output)
61 | {
62 | $apiKey = $input->getArgument(self::ARGUMENT_KEY);
63 |
64 | if ((empty($apiKey) || !$this->_validateWebserviceKey($apiKey))) {
65 | $output->writeln('The api key is invalid ( 32 characters required)');
66 | return 1;
67 | }
68 | if (!WebserviceKey::keyExists(pSQL($apiKey))) {
69 | $output->writeln('The api key does not exists');
70 | return 1;
71 | }
72 |
73 | $idKey = Db::getInstance()->getValue("
74 | SELECT id_webservice_account
75 | FROM " . _DB_PREFIX_ . "webservice_account
76 | WHERE `key`= '" . pSQL($apiKey) . "'
77 | ");
78 |
79 | $webserviceKey = new WebserviceKey($idKey);
80 | try {
81 | $webserviceKey->delete();
82 | } catch (PrestaShopException $e) {
83 | $output->writeln('An error occurs while saving webservice key');
84 | return 1;
85 | }
86 | $output->writeln("Webservice key deleted with success");
87 | return 0;
88 | }
89 |
90 | /**
91 | * Validate that provided key is valid
92 | * @param string $key
93 | * @return bool
94 | */
95 | protected function _validateWebserviceKey($key)
96 | {
97 | return (bool)preg_match('/^[A-Z_0-9-]{32}$/', $key);
98 | }
99 |
100 | }
--------------------------------------------------------------------------------
/src/Hhennes/PrestashopConsole/PrestashopConsoleApplication.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright since 2016 Hennes Hervé
15 | * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
16 | *
17 | * https://github.com/nenes25/prestashop_console
18 | * https://www.h-hennes.fr/blog/
19 | */
20 |
21 | namespace Hhennes\PrestashopConsole;
22 |
23 | use Symfony\Component\Console\Application as BaseApplication;
24 | use Symfony\Component\Finder\Finder;
25 |
26 | class PrestashopConsoleApplication extends BaseApplication
27 | {
28 | const APP_NAME = 'prestashopConsole';
29 | // Execution of the console from a phar archive
30 | const EXECUTION_MODE_PHAR = "phar";
31 | // Namespace of the Commands classes
32 | const COMMANDS_NAMESPACE = 'Hhennes\\PrestashopConsole\\Command';
33 |
34 | /** @var string php|phar Console run mod */
35 | protected $_runAs = 'php';
36 |
37 | /** @var string Phar archive root location */
38 | protected $_pharArchiveRootLocation = null;
39 |
40 | /**
41 | * Set RunAs Mode
42 | * @param string $mode
43 | */
44 | public function setRunAs($mode)
45 | {
46 | $this->_runAs = $mode;
47 | }
48 |
49 | /**
50 | * Get RunAs
51 | * @return string
52 | */
53 | public function getRunAs()
54 | {
55 | return $this->_runAs;
56 | }
57 |
58 | /**
59 | * Initialize the console application for an execution in phar mode.
60 | *
61 | * @param string $archiveLocation : The location of the phar archive currently executed.
62 | *
63 | * @throws Exception
64 | */
65 | public function initializeForPharExecution($archiveLocation)
66 | {
67 | // Assert that the given path is a file in the file system.
68 | if (!file_exists($archiveLocation)) {
69 | throw new \Exception("The given phar archive location is not a file : ".$archiveLocation);
70 | }
71 | // Assert that the location starts with the PHAR prefix
72 | if (0 !== strpos($archiveLocation, "phar://")) {
73 | throw new \Exception(
74 | "The given phar archive location is not a phar archive path (It must start with phar://) : ".$archiveLocation
75 | );
76 | }
77 | $this->_runAs = PrestashopConsoleApplication::EXECUTION_MODE_PHAR;
78 | $this->_pharArchiveRootLocation = $archiveLocation;
79 | }
80 |
81 | /**
82 | * Automatically register all existing commands
83 | */
84 | public function getDeclaredCommands()
85 | {
86 | $this->registerCommands();
87 | }
88 |
89 | /**
90 | * Register only the installation commands.
91 | */
92 | public function registerInstallCommands()
93 | {
94 | $this->registerCommands("install");
95 | }
96 |
97 | /**
98 | * Register commands in the application with an optionnal filter on the namespace.
99 | * At the moment, the namespace is an actual file namespace (The directory in which the commands scripts are declared)
100 | *
101 | * @param string $commandNamespace : (OPTIONNAL) The name of the namespace for the commands to register
102 | */
103 | protected function registerCommands($commandNamespace = null)
104 | {
105 | // The root of the search depends on the run mode
106 | $dir = ($this->_runAs == PrestashopConsoleApplication::EXECUTION_MODE_PHAR) ? $this->_pharArchiveRootLocation : getcwd();
107 | // Source directory
108 | $dir .= DIRECTORY_SEPARATOR . "src";
109 |
110 | $commandsSearchNamespace = PrestashopConsoleApplication::COMMANDS_NAMESPACE;
111 | // Add the namespace to the search directory path
112 | if (null !== $commandNamespace) {
113 | $commandsSearchNamespace .= '\\' . ucwords($commandNamespace);
114 | }
115 |
116 | $commandFilepaths = Finder::create()->files()
117 | ->name('*Command.php')
118 | ->in($dir. DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $commandsSearchNamespace));
119 |
120 | if (sizeof($commandFilepaths)) {
121 | $customCommands = array();
122 | foreach ($commandFilepaths as $command) {
123 | $classPath = $commandsSearchNamespace .'\\'. str_replace(
124 | DIRECTORY_SEPARATOR,
125 | "\\",
126 | $command->getRelativePathname()
127 | );
128 | $commandName = basename($classPath, '.php');
129 | $customCommands[] = new $commandName();
130 | }
131 |
132 | $this->addCommands($customCommands);
133 | }
134 | }
135 | }
136 |
--------------------------------------------------------------------------------