Jump to content

Script format help


Recommended Posts

Posted (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 by ddbodyjab
added version for context (see edit history)
Link to comment
Share on other sites

Posted (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 by Andrei H (see edit history)
  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...