/rai Posted October 25, 2016 Share Posted October 25, 2016 estoy intentado llamar a la función truncateTables() en mi script .php para que me vacié las tablas antes de hacer las funciones loadCategoriesPost() y loadProductsPost() , no hay manera de que las vacié algo estoy haciendo mal al llamarla y no se que es. la función tiene esta pinta y se supone que si le paso el 0 me tiene que borrar las categorías. protected function truncateTables($case) { switch ((int)$case) { case $this->entities[$this->l('Categories')]: Db::getInstance()->execute(' DELETE FROM `'._DB_PREFIX_.'category` WHERE id_category NOT IN ('.(int)Configuration::get('PS_HOME_CATEGORY'). ', '.(int)Configuration::get('PS_ROOT_CATEGORY').')'); Db::getInstance()->execute(' DELETE FROM `'._DB_PREFIX_.'category_lang` WHERE id_category NOT IN ('.(int)Configuration::get('PS_HOME_CATEGORY'). ', '.(int)Configuration::get('PS_ROOT_CATEGORY').')'); Db::getInstance()->execute(' DELETE FROM `'._DB_PREFIX_.'category_shop` WHERE `id_category` NOT IN ('.(int)Configuration::get('PS_HOME_CATEGORY'). ', '.(int)Configuration::get('PS_ROOT_CATEGORY').')'); Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'category` AUTO_INCREMENT = 3'); foreach (scandir(_PS_CAT_IMG_DIR_) as $d) { if (preg_match('/^[0-9]+(\-(.*))?\.jpg$/', $d)) { unlink(_PS_CAT_IMG_DIR_.$d); } } break; case $this->entities[$this->l('Products')]: Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'product`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'product_shop`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'feature_product`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'product_lang`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'category_product`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'product_tag`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'image`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'image_lang`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'image_shop`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'specific_price`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'specific_price_priority`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'product_carrier`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'cart_product`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'compare_product`'); if (count(Db::getInstance()->executeS('SHOW TABLES LIKE \''._DB_PREFIX_.'favorite_product\' '))) { //check if table exist Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'favorite_product`'); } Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'product_attachment`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'product_country_tax`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'product_download`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'product_group_reduction_cache`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'product_sale`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'product_supplier`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'scene_products`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'warehouse_product_location`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'stock`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'stock_available`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'stock_mvt`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'customization`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'customization_field`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'supply_order_detail`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'attribute_impact`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'product_attribute`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'product_attribute_shop`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'product_attribute_combination`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'product_attribute_image`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'pack`'); Image::deleteAllImages(_PS_PROD_IMG_DIR_); if (!file_exists(_PS_PROD_IMG_DIR_)) { mkdir(_PS_PROD_IMG_DIR_); } break; case $this->entities[$this->l('Combinations')]: Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'attribute`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'attribute_impact`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'attribute_lang`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'attribute_group`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'attribute_group_lang`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'attribute_group_shop`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'attribute_shop`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'product_attribute`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'product_attribute_shop`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'product_attribute_combination`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'product_attribute_image`'); Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'stock_available` WHERE id_product_attribute != 0'); break; case $this->entities[$this->l('Customers')]: Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'customer`'); break; case $this->entities[$this->l('Addresses')]: Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'address`'); break; case $this->entities[$this->l('Manufacturers')]: Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'manufacturer`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'manufacturer_lang`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'manufacturer_shop`'); foreach (scandir(_PS_MANU_IMG_DIR_) as $d) { if (preg_match('/^[0-9]+(\-(.*))?\.jpg$/', $d)) { unlink(_PS_MANU_IMG_DIR_.$d); } } break; case $this->entities[$this->l('Suppliers')]: Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'supplier`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'supplier_lang`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'supplier_shop`'); foreach (scandir(_PS_SUPP_IMG_DIR_) as $d) { if (preg_match('/^[0-9]+(\-(.*))?\.jpg$/', $d)) { unlink(_PS_SUPP_IMG_DIR_.$d); } } break; case $this->entities[$this->l('Alias')]: Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'alias`'); break; } Image::clearTmpDir(); return true; } Link to comment Share on other sites More sharing options...
jesa Posted October 26, 2016 Share Posted October 26, 2016 Esto te lo has hecho a mano? hay un módulo que te vacía todos los productos y categorías gratuito en prestashop. Si no recuerdo mal viene con la propia instalación. Link to comment Share on other sites More sharing options...
/rai Posted October 26, 2016 Author Share Posted October 26, 2016 Esto te lo has hecho a mano? hay un módulo que te vacía todos los productos y categorías gratuito en prestashop. Si no recuerdo mal viene con la propia instalación. no, lo trae prestashop en el admin import, ya pero yo quiero hacerlo de forma automática con una tarea cron. Lo que intentaba es implementar esa función en este script https://www.prestashop.com/forums/topic/499237-script-importacion-automatica-prestashop-16/ Pero al final me decanto por hacerlo manual y no me como la cabeza: //limpiar productos if ($mysqli->query("TRUNCATE TABLE ps_product") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n" . PHP_EOL; } if ($mysqli->query("TRUNCATE TABLE ps_product_shop") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n" . PHP_EOL; } if ($mysqli->query("TRUNCATE TABLE ps_feature_product") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n" . PHP_EOL; } if ($mysqli->query("TRUNCATE TABLE ps_product_lang") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n" . PHP_EOL; } if ($mysqli->query("TRUNCATE TABLE ps_category_product") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n" . PHP_EOL; } if ($mysqli->query("TRUNCATE TABLE ps_image") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n" . PHP_EOL; } if ($mysqli->query("TRUNCATE TABLE ps_image_lang") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n" . PHP_EOL; } if ($mysqli->query("TRUNCATE TABLE ps_image_shop") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n" . PHP_EOL; } if ($mysqli->query("TRUNCATE TABLE ps_specific_price") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n" . PHP_EOL; } if ($mysqli->query("TRUNCATE TABLE ps_specific_price_priority") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n" . PHP_EOL; } if ($mysqli->query("TRUNCATE TABLE ps_product_carrier") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n" . PHP_EOL; } if ($mysqli->query("TRUNCATE TABLE ps_cart_product") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n" . PHP_EOL; } if ($mysqli->query("TRUNCATE TABLE ps_compare_product") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n" . PHP_EOL; } if ($mysqli->query("TRUNCATE TABLE ps_product_attachment") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n" . PHP_EOL; } if ($mysqli->query("TRUNCATE TABLE ps_product_country_tax") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n" . PHP_EOL; } if ($mysqli->query("TRUNCATE TABLE ps_product_download") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n" . PHP_EOL; } if ($mysqli->query("TRUNCATE TABLE ps_product_group_reduction_cache") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n" . PHP_EOL; } if ($mysqli->query("TRUNCATE TABLE ps_product_sale") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n" . PHP_EOL; } if ($mysqli->query("TRUNCATE TABLE ps_product_supplier") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n" . PHP_EOL; } if ($mysqli->query("TRUNCATE TABLE ps_scene_products") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n" . PHP_EOL; } if ($mysqli->query("TRUNCATE TABLE ps_warehouse_product_location") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n" . PHP_EOL; } if ($mysqli->query("TRUNCATE TABLE ps_stock") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n" . PHP_EOL; } if ($mysqli->query("TRUNCATE TABLE ps_stock_available") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n" . PHP_EOL; } if ($mysqli->query("TRUNCATE TABLE ps_stock_mvt") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n" . PHP_EOL; } if ($mysqli->query("TRUNCATE TABLE ps_customization") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n" . PHP_EOL; } if ($mysqli->query("TRUNCATE TABLE ps_customization_field") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n" . PHP_EOL; } if ($mysqli->query("TRUNCATE TABLE ps_supply_order_detail") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n" . PHP_EOL; } if ($mysqli->query("TRUNCATE TABLE ps_attribute_impact") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n" . PHP_EOL; } if ($mysqli->query("TRUNCATE TABLE ps_product_attribute") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n" . PHP_EOL; } if ($mysqli->query("TRUNCATE TABLE ps_product_attribute_shop") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n" . PHP_EOL; } if ($mysqli->query("TRUNCATE TABLE ps_product_attribute_combination") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n" . PHP_EOL; } if ($mysqli->query("TRUNCATE TABLE ps_product_attribute_image") === TRUE) { //echo "Se ha vaciado la tabla ps_category_lang correctamente \n Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now