ddbodyjab Posted May 3, 2025 Share Posted May 3, 2025 (edited) I'm using PrestaShop 8.2.1 and I have a module that puts an insane amount of data in 2 tables and I manually truncate them with a simple script that I upload then delete every time I need it done and it works great. I don't want the script sitting in my files because they contain the DB , USER, and password in plain text. I would like to streamline this and put it in my cronjobs for automation. $sql = new mysqli ("localhost","Actual_DB", "actual_password", "Actual_USER"); mysqli_query($sql, "truncate wmbi_square_logs"); mysqli_query($sql, "truncate wmbi_square_task_item"); $sql->close(); Any hints or tips would be appreciated. Can I create it as a function every time I open the backend or as a cronjob script? I am not interested in purchasing a module for this, BTW... Edited May 3, 2025 by ddbodyjab added version for context (see edit history) Link to comment Share on other sites More sharing options...
Andrei H Posted May 4, 2025 Share Posted May 4, 2025 (edited) Hello, You have a couple of options to achieve what you want. The easiest one is to create a file, script.php (the name does not matter), inside the PrestaShop root. Its content should be: <?php require dirname(__FILE__) . '/config/config.inc.php'; Db::getInstance()->execute('TRUNCATE ps_test1'); Db::getInstance()->execute('TRUNCATE ps_test2'); Then you can add it to the existing cronjobs (e.g.: * * * * * php <full_path_to_prestashop_root>/script.php). This should work as expected. The other option would be to create a custom module that can: 1. Use the actionAdminControllerSetMedia hook, so it gets called each time you access an admin page 2. Create a Symfony Command that you can use in your cronjobs If you want, I can provide some code for this option as well. Edited May 4, 2025 by Andrei H (see edit history) 1 Link to comment Share on other sites More sharing options...
ddbodyjab Posted May 5, 2025 Author Share Posted May 5, 2025 Thank you...works perfectly. 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