Compare commits

...

20 Commits

Author SHA1 Message Date
Michael RICOIS
7b152ac3c4 Forget file 2018-01-25 17:59:22 +01:00
Michael RICOIS
5aa5a1f2e1 Harmonisation ps and sf 2018-01-25 17:59:03 +01:00
Michael RICOIS
fd118aa0fc Harmonize 2018-01-25 17:48:32 +01:00
Michael RICOIS
46d71df134 ENV 2018-01-25 17:38:58 +01:00
Michael RICOIS
c3c55bb6f9 Update 2018-01-25 17:35:01 +01:00
Michael RICOIS
e7bad57f96 Already in config 2018-01-25 15:49:44 +01:00
Michael RICOIS
c753865625 Sample and documentation 2018-01-25 15:45:58 +01:00
Michael RICOIS
274a18e6dc Rename scripts dir as mksh 2018-01-25 10:50:52 +01:00
Michael RICOIS
4659267245 Move option 2018-01-25 10:28:47 +01:00
Michael RICOIS
eb636f096d prestashop autoload 2018-01-05 18:01:25 +01:00
Michael RICOIS
9d711d512e Autoload prestashop 2018-01-05 18:00:34 +01:00
Michael RICOIS
604126cea6 README 2018-01-05 17:19:19 +01:00
Michael RICOIS
cdc0fddff7 Update 2018-01-05 17:13:05 +01:00
Michael RICOIS
7cd1365afb dotenv 2018-01-05 12:10:44 +01:00
Michael RICOIS
0a4279504f First command 2018-01-05 11:50:18 +01:00
Michael RICOIS
21effa8f84 Remove release 2018-01-04 16:25:26 +01:00
Michael RICOIS
79bd12c34c Ignore 2018-01-03 12:32:18 +01:00
Michael RICOIS
c041d14cbb Remove release 2018-01-03 12:28:18 +01:00
Michael RICOIS
51026f99e4 Composer 2018-01-02 17:46:41 +01:00
Michael RICOIS
837a9c96c0 Add makefile 2018-01-02 17:43:52 +01:00
17 changed files with 603 additions and 0 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/.settings/ /.settings/
/.buildpath /.buildpath
/.project /.project
/vendor/

23
Makefile Normal file
View File

@ -0,0 +1,23 @@
TMP_FOLDER=/tmp
RELEASE_FOLDER=release
ENV ?= prod
help: ## Display this help menu
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
clean: ## Clear the application cache
rm -rf var/cache/*
install: ## Install with the latest version
@sh mksh/install.sh $(ENV)
update: ## Update the installation to the latest version
@sh mksh/update.sh $(ENV)
dev: ## Install the latest dev version
@sh mksh/dev.sh
.PHONY: help clean install update dev
.DEFAULT_GOAL := install

32
README.md Normal file
View File

@ -0,0 +1,32 @@
# Scripts BebeBoutik
## Install
> git clone git@gitlab.antadis.net:michael/bebeboutik-scripts.git <dir>
### Local
```
make dev
```
### Server
- First install
Install project dependencies (composer install)
```
make install
```
Configure your project by setting environment var in .env file
- `WEBROOT` : Set prestashop website dir
- Update
Update from master (git checkout AND composer install)
```
make update
```
## Development
- /bin : symfony command, only console (`php bin/console` and you get help)
- /binps : PrestaShop CLI with hard depencies
Get ENV vars in prestashop CLI

19
bin/console Normal file
View File

@ -0,0 +1,19 @@
#!/usr/bin/env php
<?php
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../config/ps_autoload.php';
use Symfony\Component\Console\Application;
use Symfony\Component\Dotenv\Dotenv;
$dotenv = new Dotenv();
$dotenv->load(__DIR__.'/../.env');
$app = new Application();
// Register command
$app->add(new Sale\CacheCommand());
$app->run();

4
binps/sample.php Normal file
View File

@ -0,0 +1,4 @@
<?php
require_once __DIR__ . '/../config/bootstrap_ps.php';
echo Configuration::get('PS_SHOP_NAME')."\n";

22
composer.json Normal file
View File

@ -0,0 +1,22 @@
{
"require": {
"symfony/console": "^3.4",
"symfony/dotenv": "^3.4"
},
"scripts": {
"post-cmd": [
"php -r \"copy('config/.env.example', '.env');\""
],
"post-install-cmd": [
"@post-cmd"
],
"post-update-cmd": [
"@post-cmd"
]
},
"autoload": {
"psr-4": {
"": "src/"
}
}
}

306
composer.lock generated Normal file
View File

@ -0,0 +1,306 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "a893d4337306fc8073584fbc1daaf1a7",
"packages": [
{
"name": "psr/log",
"version": "1.0.2",
"source": {
"type": "git",
"url": "https://github.com/php-fig/log.git",
"reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d",
"reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Log\\": "Psr/Log/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for logging libraries",
"homepage": "https://github.com/php-fig/log",
"keywords": [
"log",
"psr",
"psr-3"
],
"time": "2016-10-10T12:19:37+00:00"
},
{
"name": "symfony/console",
"version": "v3.4.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/console.git",
"reference": "2cdef78de8f54f68ff16a857e710e7302b47d4c7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/console/zipball/2cdef78de8f54f68ff16a857e710e7302b47d4c7",
"reference": "2cdef78de8f54f68ff16a857e710e7302b47d4c7",
"shasum": ""
},
"require": {
"php": "^5.5.9|>=7.0.8",
"symfony/debug": "~2.8|~3.0|~4.0",
"symfony/polyfill-mbstring": "~1.0"
},
"conflict": {
"symfony/dependency-injection": "<3.4",
"symfony/process": "<3.3"
},
"require-dev": {
"psr/log": "~1.0",
"symfony/config": "~3.3|~4.0",
"symfony/dependency-injection": "~3.4|~4.0",
"symfony/event-dispatcher": "~2.8|~3.0|~4.0",
"symfony/lock": "~3.4|~4.0",
"symfony/process": "~3.3|~4.0"
},
"suggest": {
"psr/log": "For using the console logger",
"symfony/event-dispatcher": "",
"symfony/lock": "",
"symfony/process": ""
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.4-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\Console\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Console Component",
"homepage": "https://symfony.com",
"time": "2017-12-02T18:20:11+00:00"
},
{
"name": "symfony/debug",
"version": "v3.4.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/debug.git",
"reference": "fb2001e5d85f95d8b6ab94ae3be5d2672df128fd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/debug/zipball/fb2001e5d85f95d8b6ab94ae3be5d2672df128fd",
"reference": "fb2001e5d85f95d8b6ab94ae3be5d2672df128fd",
"shasum": ""
},
"require": {
"php": "^5.5.9|>=7.0.8",
"psr/log": "~1.0"
},
"conflict": {
"symfony/http-kernel": ">=2.3,<2.3.24|~2.4.0|>=2.5,<2.5.9|>=2.6,<2.6.2"
},
"require-dev": {
"symfony/http-kernel": "~2.8|~3.0|~4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.4-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\Debug\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Debug Component",
"homepage": "https://symfony.com",
"time": "2017-11-21T09:01:46+00:00"
},
{
"name": "symfony/dotenv",
"version": "v3.4.3",
"source": {
"type": "git",
"url": "https://github.com/symfony/dotenv.git",
"reference": "66265f80c0f585cd6aec3fbdfc4ffdf7a0d75992"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/dotenv/zipball/66265f80c0f585cd6aec3fbdfc4ffdf7a0d75992",
"reference": "66265f80c0f585cd6aec3fbdfc4ffdf7a0d75992",
"shasum": ""
},
"require": {
"php": "^5.5.9|>=7.0.8"
},
"require-dev": {
"symfony/process": "~3.2|~4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.4-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\Dotenv\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Registers environment variables from a .env file",
"homepage": "https://symfony.com",
"keywords": [
"dotenv",
"env",
"environment"
],
"time": "2018-01-03T17:14:19+00:00"
},
{
"name": "symfony/polyfill-mbstring",
"version": "v1.6.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-mbstring.git",
"reference": "2ec8b39c38cb16674bbf3fea2b6ce5bf117e1296"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/2ec8b39c38cb16674bbf3fea2b6ce5bf117e1296",
"reference": "2ec8b39c38cb16674bbf3fea2b6ce5bf117e1296",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"suggest": {
"ext-mbstring": "For best performance"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.6-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Polyfill\\Mbstring\\": ""
},
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill for the Mbstring extension",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"mbstring",
"polyfill",
"portable",
"shim"
],
"time": "2017-10-11T12:05:26+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": []
}

1
config/.env.example Normal file
View File

@ -0,0 +1 @@
WEBROOT=/home/vhosts/bebeboutik

16
config/bootstrap_ps.php Normal file
View File

@ -0,0 +1,16 @@
<?php
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../config/ps_autoload.php';
use Symfony\Component\Dotenv\Dotenv;
$dotenv = new Dotenv();
$dotenv->load(__DIR__.'/../.env');
// Configuration ENV
$webroot = getenv('WEBROOT');
$_SERVER['HTTP_PORT'] = 80;
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
// Boostrap PrestaShop
require_once $webroot.'/config/config.inc.php';

9
config/bootstrap_sf.php Normal file
View File

@ -0,0 +1,9 @@
<?php
$_SERVER['HTTP_PORT'] = 80;
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
// Configuration ENV
$webroot = getenv('WEBROOT');
// Boostrap PrestaShop
require_once $webroot.'/config/config.inc.php';

38
config/ps_autoload.php Normal file
View File

@ -0,0 +1,38 @@
<?php
spl_autoload_register(function($className)
{
if (function_exists('smartyAutoload') AND smartyAutoload($className)) {
return true;
}
if (function_exists('Predis\predisAutoload') AND Predis\predisAutoload($className)) {
return true;
}
$className = str_replace(chr(0), '', $className);
$classDir = getenv('WEBROOT').'/classes/';
$overrideDir = getenv('WEBROOT').'/override/classes/';
$file_in_override = file_exists($overrideDir.$className.'.php');
$file_in_classes = file_exists($classDir.$className.'.php');
// This is a Core class and its name is the same as its declared name
if (substr($className, -4) == 'Core') {
require_once($classDir.substr($className, 0, -4).'.php');
}
else {
if ($file_in_override && $file_in_classes) {
require_once($classDir.str_replace(chr(0), '', $className).'.php');
require_once($overrideDir.$className.'.php');
}
elseif (!$file_in_override && $file_in_classes) {
require_once($classDir.str_replace(chr(0), '', $className).'.php');
$classInfos = new ReflectionClass($className.((interface_exists($className, false) or class_exists($className, false)) ? '' : 'Core'));
if (!$classInfos->isInterface() && substr($classInfos->name, -4) == 'Core') {
eval(($classInfos->isAbstract() ? 'abstract ' : '').'class '.$className.' extends '.$className.'Core {}');
}
}
elseif ($file_in_override && !$file_in_classes) {
require_once($overrideDir.$className.'.php');
}
}
});

17
mksh/composer-install.sh Normal file
View File

@ -0,0 +1,17 @@
#!/usr/bin/env sh
EXPECTED_SIGNATURE=$(wget -q -O - https://composer.github.io/installer.sig)
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_SIGNATURE=$(php -r "echo hash_file('SHA384', 'composer-setup.php');")
if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]
then
>&2 echo 'ERROR: Invalid installer signature'
rm composer-setup.php
exit 1
fi
php composer-setup.php --filename=composer --install-dir=/usr/local/bin --quiet
RESULT=$?
rm composer-setup.php
exit $RESULT

11
mksh/dev.sh Normal file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env bash
# You can execute this file to install dev environment
# eg: `sh dev.sh`
COMPOSER_COMMAND='composer'
DIR="${BASH_SOURCE}"
if [ ! -d "$DIR" ]; then DIR="$PWD/scripts"; fi
. "$DIR/require.sh"
$COMPOSER_COMMAND install

20
mksh/install.sh Normal file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env bash
# You can execute this file to install
# eg: `sh install.sh prod`
COMPOSER_COMMAND='composer'
DIR="${BASH_SOURCE}"
if [ ! -d "$DIR" ]; then DIR="$PWD/scripts"; fi
. "$DIR/require.sh"
ENV=$1
if [ $ENV == 'preprod' ]
then
git checkout develop
else
git checkout master
fi
$COMPOSER_COMMAND install --no-dev -o --prefer-dist

9
mksh/require.sh Normal file
View File

@ -0,0 +1,9 @@
#! /usr/bin/env bash
# File used to check dependencies
if [ ! -f composer.phar ]; then
echo "composer.phar not found, we'll see if composer is installed globally."
command -v composer >/dev/null 2>&1 || { echo >&2 "app requires composer but it's not installed (see composer-install.sh). Aborting."; exit 1; }
else
COMPOSER_COMMAND='./composer.phar'
fi

20
mksh/update.sh Normal file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env bash
# You can execute this file to update
# eg: `sh update.sh prod`
COMPOSER_COMMAND='composer'
DIR="${BASH_SOURCE}"
if [ ! -d "$DIR" ]; then DIR="$PWD/scripts"; fi
. "$DIR/require.sh"
ENV=$1
if [ $ENV == 'preprod' ]
then
git checkout --force develop
else
git checkout --force master
fi
$COMPOSER_COMMAND install --no-dev -o --prefer-dist

55
src/Sale/CacheCommand.php Normal file
View File

@ -0,0 +1,55 @@
<?php
namespace Sale;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
class CacheCommand extends Command
{
protected function configure()
{
$this->setName('sale:cache')
->setDescription('Reset the product cache')
->setHelp('This command reset product_ps_cache which associated product and sales')
->addOption('reset', 'r', InputOption::VALUE_NONE, 'Reset the cache', null);
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('Start');
require_once __DIR__ . '/../../config/bootstrap_sf.php';
$min_id_product = \Db::getInstance()->getValue('
SELECT MIN(`id_product`) FROM `'._DB_PREFIX_.'product` WHERE `date_add` > DATE_SUB(NOW(), INTERVAL 10 DAY)
');
echo $min_id_product."\n";
/*
Db::getInstance()->ExecuteS('
DELETE FROM `'._DB_PREFIX_.'product_ps_cache`
WHERE `id_product` >= '.$min_id_product.'
');
Db::getInstance()->ExecuteS('
INSERT IGNORE INTO `'._DB_PREFIX_.'product_ps_cache` (
SELECT p.id_product, IFNULL(
(
SELECT s.id_sale
FROM `'._DB_PREFIX_.'privatesale_category` s
WHERE s.`id_category` = p.`id_category_default`
LIMIT 1)
, 0
)
FROM `'._DB_PREFIX_.'product` p
WHERE p.`id_product` >= '.$min_id_product.'
)
');
*/
$output->writeln('Done');
}
}