daily.4am.php 1.98 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');
Ayolo's avatar
Ayolo committed
14 15 16 17 18

$site = new site ();

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

jlaval's avatar
jlaval committed
19
// 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
20

Feu's avatar
Feu committed
21
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
22

Feu's avatar
Feu committed
23
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
24

Feu's avatar
Feu committed
25 26
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)");

jlaval's avatar
jlaval committed
27 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(SECOND, r.ttl, NOW()) WHERE NOW()>p.date_fin_produit AND DAYOFWEEK(CURDATE())-1 = r.jour_remise_en_vente AND p.prod_archive = 0');

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

31
/*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
32

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

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

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

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

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

Ayolo's avatar
Ayolo committed
43 44 45
$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
46

Ayolo's avatar
hack  
Ayolo committed
47
?>