From 775b49263928f8c261c3afec22b34cd7f913a0ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Hennes?= Date: Thu, 9 Dec 2021 21:40:09 +0100 Subject: [PATCH] #229 New Command analyse:website --- COMMANDS.md | 154 ++++++++++++++++++ bin/phar/current.version | 2 +- bin/prestashopConsole.phar | Bin 1287144 -> 1295303 bytes changelog.txt | 1 + .../Command/Analyze/GlobalCommand.php | 114 +++++++++++++ .../Command/Analyze/WebsiteCommand.php | 142 ++++++++++++++++ 6 files changed, 412 insertions(+), 1 deletion(-) create mode 100644 src/Hhennes/PrestashopConsole/Command/Analyze/GlobalCommand.php create mode 100644 src/Hhennes/PrestashopConsole/Command/Analyze/WebsiteCommand.php diff --git a/COMMANDS.md b/COMMANDS.md index 7ca6351..759c8e7 100644 --- a/COMMANDS.md +++ b/COMMANDS.md @@ -13,7 +13,9 @@ PrestashopConsole 1.6.3 **analyze:** * [`analyze:carriers`](#analyzecarriers) +* [`analyze:global`](#analyzeglobal) * [`analyze:payments`](#analyzepayments) +* [`analyze:website`](#analyzewebsite) **cache:** @@ -627,6 +629,82 @@ Do not ask any interactive question * Is multiple: no * Default: `false` +`analyze:global` +---------------- + +Run a global analysis on the website + +### Usage + +* `analyze:global` + +Run a global analysis on the website + +### Options + +#### `--help|-h` + +Display this help message + +* Accept value: no +* Is value required: no +* Is multiple: no +* Default: `false` + +#### `--quiet|-q` + +Do not output any message + +* Accept value: no +* Is value required: no +* Is multiple: no +* Default: `false` + +#### `--verbose|-v|-vv|-vvv` + +Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug + +* Accept value: no +* Is value required: no +* Is multiple: no +* Default: `false` + +#### `--version|-V` + +Display this application version + +* Accept value: no +* Is value required: no +* Is multiple: no +* Default: `false` + +#### `--ansi` + +Force ANSI output + +* Accept value: no +* Is value required: no +* Is multiple: no +* Default: `false` + +#### `--no-ansi` + +Disable ANSI output + +* Accept value: no +* Is value required: no +* Is multiple: no +* Default: `false` + +#### `--no-interaction|-n` + +Do not ask any interactive question + +* Accept value: no +* Is value required: no +* Is multiple: no +* Default: `false` + `analyze:payments` ------------------ @@ -703,6 +781,82 @@ Do not ask any interactive question * Is multiple: no * Default: `false` +`analyze:website` +----------------- + +Get website statistics + +### Usage + +* `analyze:website` + +Get website statistics + +### Options + +#### `--help|-h` + +Display this help message + +* Accept value: no +* Is value required: no +* Is multiple: no +* Default: `false` + +#### `--quiet|-q` + +Do not output any message + +* Accept value: no +* Is value required: no +* Is multiple: no +* Default: `false` + +#### `--verbose|-v|-vv|-vvv` + +Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug + +* Accept value: no +* Is value required: no +* Is multiple: no +* Default: `false` + +#### `--version|-V` + +Display this application version + +* Accept value: no +* Is value required: no +* Is multiple: no +* Default: `false` + +#### `--ansi` + +Force ANSI output + +* Accept value: no +* Is value required: no +* Is multiple: no +* Default: `false` + +#### `--no-ansi` + +Disable ANSI output + +* Accept value: no +* Is value required: no +* Is multiple: no +* Default: `false` + +#### `--no-interaction|-n` + +Do not ask any interactive question + +* Accept value: no +* Is value required: no +* Is multiple: no +* Default: `false` + `cache:clean` ------------- diff --git a/bin/phar/current.version b/bin/phar/current.version index d8810df..390cabf 100644 --- a/bin/phar/current.version +++ b/bin/phar/current.version @@ -1 +1 @@ -0d6d820447207c1d56e1c3b20ade4a2c3357f342 \ No newline at end of file +9d35ab7e4bf5f7bfc6ae3b99bd700416bd6c4f3f \ No newline at end of file diff --git a/bin/prestashopConsole.phar b/bin/prestashopConsole.phar index d56ab4afc4eafe7973f8495821359d26c0505b84..01a86118fcede8e247e5143e04b996cfc393980d 100755 GIT binary patch delta 6896 zcmdT|dsN$1p8o-Xgje!Q0)%IC36z9a2-H5H5THPLSRe%oh4Ko?4~T{&@Ra>$J7D?s}%X&PbU@omG#s_kMqY0J`g* zGxN{(oZD}I_kQ2s&-Z(8dgJYux9@MA{;$Zrc8)7N_?0Dm#(^zit&AKE8)76fd?zCV z;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Uyv)Ouuxd)64`7-A{lgRU*v#5<%nN65&a2Mbay+vg*!QBx$+bo7nkC8n!_Z^A9d?sFBMuvPMcOf^_gQx4rqg|gPTw^2 z>|iK&^@`OSV<4FwGZ5A787O3~6AD=GgtRX?5ko>cDzqUz0FNHgwo*@07Hvw;CrbvR zotsh4K|hlL2G3`}OLQiv31otdBbhC15|)Mg8ne7`rjL@OoqzeliG)7Lg0qKNxV2Xx8T1*m_qk z0=bt97qzqG?r=uP)3V}?SLvD|g|5tUvgOn)KZ1N+aCmsnz%II$VI!MMOE0)gyua5~ zEi)pjQXti6@sM5a2r}j+@_ue!F~eZq0+>~c#&>zzK)Vo>P_bK2H%g}~PlUxJj5mdMR^K-`(MC;D3|&9Knb5)(N+(a4}x zyo&5Cmp9WUPbLj`bnIe-2gIH5+S>k3)a{o>lq%eH(bL~WscRf#lQX+%7qieldxGO5W}CDc`^=d-G+ zwG7WyEob;w)gZ%?1w#xM7eLt7h4>h)UnsxIg<#TF-3ym7G*6Hiv+t2#Y!)G*xc($z(d*3v! z;92LA5c22{RORfPJWsd#vS^}FPmxXdQrMbM_TeT(cfASG6*fbE`(9=$~$b`+v4UTt)42 z7dj*ga<{K3p31#$y4G&v=pVKt>jpo1vM-)X}G<+ zwCF2Wmf=)RhfHpV@L#^}$`Ga0yJ@0B{_pxyB=d7;>B0XmD##JA^2KEVIoVp_YH)k- z9F4ThrpbVOC{?tPOQ91!3hQ;#t$>oMI%D{dzfO zF*IUm#n6cnB}TLudNB-Q7{@~)(_3eDKhUejYvRoJ!p9x?=7SNV8~e@r@mD8}$HPa9 zpEA!J&22Yt-(989?k+H9j84unSVu2b8e&J2{btMfl?L;tL)L+#&kiVqj^9mv@&3kb Uo>)!QFE0LCe0`+qiu#KG0X~*?yZ`_I diff --git a/changelog.txt b/changelog.txt index af5df13..f32ad61 100644 --- a/changelog.txt +++ b/changelog.txt @@ -28,6 +28,7 @@ #232 Enhancement module:generate:controller #233 Provide verbose information when module controller is created #92 Improve module list ( add option to show id ) + #229 New Command analyse:website 2021-03-11 - V 1.6.2 : #142 Error when try to start by prestashopConsole command #170 Create Webservice key command #173 Change link in readme diff --git a/src/Hhennes/PrestashopConsole/Command/Analyze/GlobalCommand.php b/src/Hhennes/PrestashopConsole/Command/Analyze/GlobalCommand.php new file mode 100644 index 0000000..208e95e --- /dev/null +++ b/src/Hhennes/PrestashopConsole/Command/Analyze/GlobalCommand.php @@ -0,0 +1,114 @@ + + * @copyright since 2021 Hervé HENNES + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License ("AFL") v. 3.0 + */ + +namespace Hhennes\PrestashopConsole\Command\Analyze; + +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Input\ArrayInput; + +class GlobalCommand extends Command +{ + /** + * @inheritDoc + */ + protected function configure() + { + $this + ->setName('analyze:global') + ->setDescription('Run a global analysis on the website'); + } + + /** + * @inheritDoc + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $commands = $this->getCommandList(); + foreach ($commands as $command) { + try { + $output->writeln('========================'); + $output->writeln('' . $command['description'] . ''); + $runCommand = $this->getApplication()->find($command['name']); + if (array_key_exists('arguments', $command)) { + $arguments = new ArrayInput($command['arguments']); + $runCommand->run($arguments, $output); + } else { + $runCommand->run($input, $output); + } + } catch (\Exception $e) { + $output->writeln( + sprintf( + 'Get exception during command run %s', + $e->getMessage() + ) + ); + } + } + + return 0; + } + + /** + * Get the list of commands to execute + * @return array + */ + protected function getCommandList() + { + $commands = [ + [ + 'description' => 'Get website statistics', + 'name' => 'analyze:website', + ], + [ + 'description' => 'List installed modules', + 'name' => 'module:list', + 'arguments' => [ + '--active' => true, + ] + ], + [ + 'description' => 'List installed modules no natives', + 'name' => 'module:list', + 'arguments' => [ + '--active' => true, + '--no-native' => true, + ] + ], + [ + 'description' => 'List installed payments modules', + 'name' => 'analyze:payments', + ], + [ + 'description' => 'List installed carriers', + 'name' => 'analyze:carriers', + 'arguments' => [ + '--active' => true, + ] + ], + [ + 'description' => 'List overrides of the project', + 'name' => 'dev:list-overrides', + ], + ]; + + return $commands; + } +} diff --git a/src/Hhennes/PrestashopConsole/Command/Analyze/WebsiteCommand.php b/src/Hhennes/PrestashopConsole/Command/Analyze/WebsiteCommand.php new file mode 100644 index 0000000..c01c5d7 --- /dev/null +++ b/src/Hhennes/PrestashopConsole/Command/Analyze/WebsiteCommand.php @@ -0,0 +1,142 @@ + + * @copyright since 2021 Hervé HENNES + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License ("AFL") v. 3.0 + */ + +namespace Hhennes\PrestashopConsole\Command\Analyze; + +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Input\ArrayInput; +use Symfony\Component\Console\Helper\Table; +use Db; +use DateTime; + +/** + * @todo this command should deals with multistore in next version + */ +class WebsiteCommand extends Command +{ + /** + * @inheritDoc + */ + protected function configure() + { + $this + ->setName('analyze:website') + ->setDescription('Get website statistics'); + } + + /** + * @inheritDoc + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $daysFromCreation = $this->getNbDaysFromCreation(_PS_CREATION_DATE_); + $nbCustomers = $this->getCustomersCount(); + $nbOrders = $this->getOrdersCount(); + $nbProducts = $this->getCatalogProductsCount(); + $nbCategories = $this->getCatalogCategoryCount(); + $multipleShop = $this->hasMultipleShops(); + $output->writeln('Prestashop version: '._PS_VERSION_.''); + if (true === $multipleShop) { + $output->writeln('This website has multiple shops'); + } + $output->writeln('Used theme name: '._THEME_NAME_.''); + $output->writeln('This website is installed since: '._PS_CREATION_DATE_. ' ('.$daysFromCreation.' days)'); + $output->writeln('Number of customers: '.$nbCustomers.' ('.round($nbCustomers/$daysFromCreation, 2).'/day)'); + $output->writeln('Number of orders: '.$nbOrders.' ('.round($nbOrders/$daysFromCreation, 2).'/day)'); + $output->writeln('Number of products: '.$nbProducts.''); + $output->writeln('Number of categories: '.$nbCategories.''); + + return 0; + } + + /** + * Calculate the difference of day from the installation to now + * @param string $creationDate + * @return int + * @throws \Exception + */ + protected function getNbDaysFromCreation($creationDate) + { + $now = new DateTime(); + return $now->diff(new DateTime($creationDate))->days; + } + + /** + * Get number of customers + * @return false|string|null + */ + protected function getCustomersCount() + { + return $this->getCount('customer', 'deleted=0'); + } + + /** + * Get number of orders + * @return false|string|null + */ + protected function getOrdersCount() + { + return $this->getCount('orders'); + } + + /** + * Get number of products + * @return false|string|null + */ + protected function getCatalogProductsCount() + { + return $this->getCount('product'); + } + + /** + * Get number of categories + * @return false|string|null + */ + protected function getCatalogCategoryCount() + { + return $this->getCount('category'); + } + + /** + * Check if website use multiples shops + * @return bool + */ + protected function hasMultipleShops() + { + $nbShops = $this->getCount('shop'); + if ($nbShops > 1) { + return true; + } + return false; + } + + /** + * Get count from a table with or without conditions + * @param string $table + * @param string|void $where + * @return false|string|null + */ + protected function getCount($table, $where = '') + { + $whereCondition = ($where != '') ? ' WHERE ' . $where : ''; + return Db::getInstance()->getValue("SELECT COUNT(*) FROM " . _DB_PREFIX_ . $table .$whereCondition); + } +}