daily.4am.php 2.74 KB
Newer Older
Ayolo's avatar
Ayolo committed
1 2
<?php

3 4 5
if(!isset($argc))
  exit();

Ayolo's avatar
Ayolo committed
6 7 8
/*
 * Daily at 4am (04h)
 */
Ayolo's avatar
hack  
Ayolo committed
9
$_SERVER['SCRIPT_FILENAME']="/var/www/ae/www/ae2/phpcron";
Ayolo's avatar
Ayolo committed
10

Ayolo's avatar
fix  
Ayolo committed
11
$topdir=$_SERVER['SCRIPT_FILENAME']."/../";
Ayolo's avatar
Ayolo committed
12
require_once($topdir. "include/site.inc.php");
jlaval's avatar
jlaval committed
13
require_once($topdir. 'comptoir/include/produitrecurrent.inc.php');
14
require_once($topdir. 'include/redis.inc.php');
Ayolo's avatar
Ayolo committed
15 16 17 18 19

$site = new site ();

echo "==== ".date("d/m/Y")." ====\n";

jlaval's avatar
jlaval committed
20
// Tâche 1 : Nettoyage des produits (et eventuels verrous liés), et des types, remise en vente des produits hebdomadaires
Feu's avatar
Feu committed
21

Feu's avatar
Feu committed
22
new requete($site->dbrw,"DELETE FROM `cpt_produits` WHERE prod_archive=1 AND NOT EXISTS(SELECT * FROM cpt_vendu WHERE cpt_vendu.id_produit=cpt_produits.id_produit)");
Feu's avatar
Feu committed
23

Feu's avatar
Feu committed
24
new requete($site->dbrw,"DELETE FROM `cpt_verrou` WHERE NOT EXISTS(SELECT * FROM cpt_produits WHERE cpt_verrou.id_produit=cpt_produits.id_produit)");
Feu's avatar
Feu committed
25

Feu's avatar
Feu committed
26 27
new requete($site->dbrw,"DELETE FROM `cpt_type_produit` WHERE NOT EXISTS ( SELECT * FROM cpt_produits WHERE cpt_produits.id_typeprod=cpt_type_produit.id_typeprod)");

28
new requete($site->dbrw,'UPDATE cpt_produits AS p JOIN cpt_produit_recurrent AS r ON p.id_produit = r.id_produit SET p.date_fin_produit=TIMESTAMPADD(DAY, r.ttl, p.date_fin_produit) WHERE NOW()>p.date_fin_produit AND DAYOFWEEK(CURDATE())-1 = r.jour_remise_en_vente AND p.prod_archive = 0');
jlaval's avatar
jlaval committed
29

Ayolo's avatar
Ayolo committed
30
// Tâche 2 : Nettoyage des créneaux "vides" expriés
Feu's avatar
Feu committed
31

32
/*new requete($site->dbrw,"DELETE FROM `pl_gap` WHERE NOT EXISTS ( SELECT * FROM pl_gap_user WHERE pl_gap_user.id_gap = pl_gap.id_gap AND pl_gap_user.id_planning = pl_gap.id_planning ) AND end_gap < NOW( )");*/
Feu's avatar
Feu committed
33

Ayolo's avatar
Ayolo committed
34
// Tâche 3 : Nettoyages des sessions expirés
35 36 37

new requete($site->dbrw, "DELETE FROM `site_sessions` WHERE expire_sess < NOW() AND expire_sess IS NOT NULL");

Ayolo's avatar
Ayolo committed
38
// Tâche 4 : Nettoyages des sessions trop vieilles
39 40 41

new requete($site->dbrw, "DELETE FROM `site_sessions` WHERE datediff(NOW(),derniere_visite) > 120");

Ayolo's avatar
Ayolo committed
42
// Tâche 5 : Optimisation de la table des créneaux machine
43

Ayolo's avatar
Ayolo committed
44 45 46
$req = new requete($site->db, "SHOW TABLES");
while(list($table)=$req->get_row())
  new requete($site->dbrw, "OPTIMIZE TABLE `".$table."`");
Ayolo's avatar
Ayolo committed
47

48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
// Tâche 6 : on regenere le cache de fsearch pour les choses modifies
$input = null;
$redis = redis_open_connection ();
while (($input = $redis->sPop('_cache_to_process')) != null) {
    // Si l'input est plus grand que 4 caractere, on efface juste les entree eventuellement presentes
    if (strlen ($input) > 4 && $redis->exists ($input)) {
        $redis->del ($input);
        continue;
    }
    // Sinon on recalcule le cache
    require_once ($topdir. 'include/cts/fsearch.inc.php');
    $_REQUEST['pattern'] = $input;
    $fsearch = new fsearch ($site, false, true);
    if (!empty ($fsearch->buffer))
        $redis->set ($input, $fsearch->buffer);
    else
        $redis->del ($input);
}
$redis->close ();

Ayolo's avatar
hack  
Ayolo committed
68
?>