daily.4am.php 1.6 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 13 14 15 16 17
require_once($topdir. "include/site.inc.php");

$site = new site ();

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

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

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

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

Feu's avatar
Feu committed
24 25
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
26
// Tâche 2 : Nettoyage des créneaux "vides" expriés
Feu's avatar
Feu committed
27

28
/*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
29

Ayolo's avatar
Ayolo committed
30
// Tâche 3 : Nettoyages des sessions expirés
31 32 33

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

Ayolo's avatar
Ayolo committed
34
// Tâche 4 : Nettoyages des sessions trop vieilles
35 36 37

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

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

Ayolo's avatar
Ayolo committed
40 41 42
$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
43

Ayolo's avatar
hack  
Ayolo committed
44
?>