diff --git a/scripts/import_categories.php b/scripts/import_categories.php new file mode 100644 index 0000000..e289dff --- /dev/null +++ b/scripts/import_categories.php @@ -0,0 +1,146 @@ +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); + + + diff --git a/synchro.sh b/synchro.sh new file mode 100755 index 0000000..55f4c88 --- /dev/null +++ b/synchro.sh @@ -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"