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

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

Ayolo's avatar
fix  
Ayolo committed
8
$topdir=$_SERVER['SCRIPT_FILENAME']."/../";
Ayolo's avatar
Ayolo committed
9 10 11 12 13 14
require_once($topdir. "include/site.inc.php");

$site = new site ();

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

Ayolo's avatar
Ayolo committed
15
// Tâche 1 : Nettoyage des produits (et eventuels verrous liés), et des types
Feu's avatar
Feu committed
16

Feu's avatar
Feu committed
17
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
18

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

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

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

25
/*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
26

Ayolo's avatar
Ayolo committed
27
// Tâche 3 : Nettoyages des sessions expirés
28 29 30

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

Ayolo's avatar
Ayolo committed
31
// Tâche 4 : Nettoyages des sessions trop vieilles
32 33 34

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

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

Ayolo's avatar
Ayolo committed
37 38 39
$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
40

Ayolo's avatar
hack  
Ayolo committed
41
?>