Merge branch 'master' of gitlab.antadis.net:dev-antadis/versionecologique
This commit is contained in:
commit
cdc723ee45
146
scripts/import_categories.php
Normal file
146
scripts/import_categories.php
Normal file
@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
|
||||
require '../www/config/config.inc.php';
|
||||
fwrite(STDOUT, 'START IMPORTING CATEGORIES'.PHP_EOL);
|
||||
|
||||
/* Connexion à une base ODBC avec l'invocation de pilote */
|
||||
$dsn = 'mysql:dbname=old_versionecologique;host=192.168.0.41';
|
||||
$user = 'root';
|
||||
$password = '';
|
||||
$old_bdd = new PDO($dsn, $user, $password);
|
||||
|
||||
$categories = array(
|
||||
340,
|
||||
341,
|
||||
342,
|
||||
343,
|
||||
344,
|
||||
345,
|
||||
346,
|
||||
347,
|
||||
348,
|
||||
350,
|
||||
351
|
||||
);
|
||||
|
||||
$results = $old_bdd->query('
|
||||
SELECT c.id_category, cl.name, cl.description, cl.link_rewrite, cl.meta_title, cl.meta_keywords, cl.meta_description, c.id_parent
|
||||
FROM ps_category c
|
||||
LEFT JOIN ps_category_lang cl ON (cl.id_category = c.id_category)
|
||||
WHERE c.id_category IN (' .implode(',', $categories) .')
|
||||
', PDO::FETCH_OBJ);
|
||||
|
||||
$data_insert = array();
|
||||
foreach ($results as $key => $result) {
|
||||
|
||||
$data_insert[] = array(
|
||||
'id' => $result->id_category,
|
||||
'name' => $result->name,
|
||||
'description' => $result->description,
|
||||
'link_rewrite' => $result->link_rewrite,
|
||||
'meta_title' => $result->meta_title,
|
||||
'meta_keywords' => $result->meta_keywords,
|
||||
'meta_description' => $result->meta_description,
|
||||
'id_parent' => $result->id_parent
|
||||
);
|
||||
|
||||
|
||||
$childs = $old_bdd->query('
|
||||
SELECT c.id_category, cl.name, cl.description, cl.link_rewrite, cl.meta_title, cl.meta_keywords, cl.meta_description, c.id_parent
|
||||
FROM ps_category c
|
||||
LEFT JOIN ps_category_lang cl ON (cl.id_category = c.id_category)
|
||||
WHERE c.id_parent = ' .$result->id_category
|
||||
, PDO::FETCH_OBJ);
|
||||
|
||||
foreach ($childs as $child) {
|
||||
$data_insert[] = array(
|
||||
'id' => $child->id_category,
|
||||
'name' => $child->name,
|
||||
'description' => $child->description,
|
||||
'link_rewrite' => $child->link_rewrite,
|
||||
'meta_title' => $child->meta_title,
|
||||
'meta_keywords' => $child->meta_keywords,
|
||||
'meta_description' => $child->meta_description,
|
||||
'id_parent' => $child->id_parent
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$query = 'INSERT INTO `ps_category` VALUES';
|
||||
$query_lang = 'INSERT INTO `ps_category_lang` VALUES';
|
||||
$query_shop = 'INSERT INTO `ps_category_shop` VALUES';
|
||||
$query_groups = 'INSERT INTO `ps_category_group` VALUES';
|
||||
|
||||
$langs = Language::getLanguages();
|
||||
$shops = Shop::getShops(false);
|
||||
|
||||
foreach ($data_insert as $key => $data) {
|
||||
$query.= '(
|
||||
'.(int) $data['id'].',
|
||||
'.(int) $data['id_parent'].',
|
||||
1,
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
1,
|
||||
"'.date('Y-m-d H:i:s').'",
|
||||
"'.date('Y-m-d H:i:s').'",
|
||||
'.Category::getLastPosition($data['id_parent'],1).',
|
||||
0
|
||||
),';
|
||||
|
||||
foreach ($shops as $shop) {
|
||||
foreach ($langs as $key => $lang) {
|
||||
$query_lang.= '(
|
||||
'.(int) $data['id'].',
|
||||
'.(int) $shop['id_shop'].',
|
||||
'.(int) $lang['id_lang'].',
|
||||
"'.pSQL($data['name']).'",
|
||||
"'.pSQL($data['description']).'",
|
||||
"'.pSQL($data['link_rewrite']).'",
|
||||
"'.pSQL($data['meta_title']).'",
|
||||
"'.pSQL($data['meta_keywords']).'",
|
||||
"'.pSQL($data['meta_description']).'"
|
||||
),';
|
||||
}
|
||||
|
||||
$query_shop.= '('.(int) $data['id'].', '.(int) $shop['id_shop'].', 0),';
|
||||
}
|
||||
|
||||
$query_groups.=
|
||||
'('.(int) $data['id'].', 1),
|
||||
('.(int) $data['id'].', 2),
|
||||
('.(int) $data['id'].', 3)'
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
$query = rtrim($query,',');
|
||||
$query_lang = rtrim($query_lang,',');
|
||||
$query_shop = rtrim($query_shop,',');
|
||||
|
||||
Db::getInstance()->execute('DELETE FROM ps_category WHERE id_category > 2');
|
||||
Db::getInstance()->execute('DELETE FROM ps_category_lang WHERE id_category > 2');
|
||||
Db::getInstance()->execute('DELETE FROM ps_category_group WHERE id_category > 2');
|
||||
Db::getInstance()->execute('DELETE FROM ps_category_shop WHERE id_category > 2');
|
||||
|
||||
|
||||
Db::getInstance()->execute($query);
|
||||
Db::getInstance()->execute($query_lang);
|
||||
Db::getInstance()->execute($query_shop);
|
||||
Db::getInstance()->execute($query_groups);
|
||||
|
||||
|
||||
fwrite(STDOUT, 'FIN IMPORT CATEGORIES'.PHP_EOL);
|
||||
|
||||
Category::regenerateEntireNtree();
|
||||
|
||||
fwrite(STDOUT, 'START IMPORTING CATEGORIES'.PHP_EOL);
|
||||
|
||||
|
||||
|
27
synchro.sh
Executable file
27
synchro.sh
Executable file
@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
|
||||
clear
|
||||
|
||||
## NO MOE DB UPDATES ON THE PREPROD ##
|
||||
|
||||
#Dump local database
|
||||
echo "exporting the local Database"
|
||||
mysqldump -h 192.168.0.41 -u root versionecologique > versionecologique.sql
|
||||
printf "Export complete => file versionecologique.sql has been created\n"
|
||||
|
||||
printf "replacing shop names\n"
|
||||
sed -i -e 's/versionecologique.local/versionecologique.preprod.antadis.fr/g' versionecologique.sql
|
||||
|
||||
printf "Sending the Database dump to the preprod server"
|
||||
PORT="4096"
|
||||
rsync -e "ssh -p$PORT" -az ./versionecologique.sql root@versionecologique.preprod.antadis.fr:/home/www/versionecologique.preprod.antadis.fr
|
||||
printf "Sending complete\n"
|
||||
|
||||
#printf "importing the Database on the preprod server\n"
|
||||
ssh root@versionecologique.preprod.antadis.fr -p4096 "cd /home/www/versionecologique.preprod.antadis.fr \\
|
||||
&& git pull origin master \\
|
||||
&& mysql -u versionecologique -pShoh5Re5 versionecologique < versionecologique.sql \\
|
||||
&& if [ -f /home/www/versionecologique.preprod.antadis.fr/www/cache/class_index.php ] ; then rm /home/www/versionecologique.preprod.antadis.fr/www/cache/class_index.php ; fi \\
|
||||
&& chown -R www-data:www-data www/* \\
|
||||
"
|
||||
printf "sync complete !! \n"
|
Loading…
Reference in New Issue
Block a user