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

$site = new site ();

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

// Tâche 1 : Enelver les verrous expirés

require_once($topdir . "comptoir/include/venteproduit.inc.php");

Ayolo's avatar
Ayolo committed
19
$req = new requete($site->db,"SELECT * FROM `cpt_verrou` WHERE TIMEDIFF(NOW(),date_res) >= 1");
Ayolo's avatar
Ayolo committed
20 21 22 23 24 25 26 27

$vp = new venteproduit($site->db,$site->dbrw);
$client = new utilisateur($site->db);

while ( $row = $req->get_row() )
{
  echo "debloquer('".$row['id_utilisateur']."','".$row['id_produit']."','".$row['id_comptoir']."','".$row['quantite']."');\n";
  
Ayolo's avatar
Ayolo committed
28
  $client->load_by_id($row['id_utilisateur']);
Ayolo's avatar
Ayolo committed
29 30 31 32
  $vp->load_by_id ( $row['id_produit'], $row['id_comptoir'], true );
  $vp->debloquer ( $client, $row['quantite'] );
}

33
// Tâche 2 : Nettoyage des produits (et eventuels verrous liés), et des types
Feu's avatar
Feu committed
34

Feu's avatar
Feu committed
35
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
36

Feu's avatar
Feu committed
37
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
38

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

41
// Tâche 3 : Nettoyage des créneaux "vides" expriés
Feu's avatar
Feu committed
42

43
/*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
44

45 46 47 48 49 50 51 52
// Tâche 4 : Nettoyages des sessions expirés

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

// Tâche 5 : Nettoyages des sessions trop vieilles

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

53 54 55
// Tâche 6 : Optimisation de la table des créneaux machine

new requete($site->dbrw, "OPTIMIZE TABLE `mc_creneaux`");
Ayolo's avatar
Ayolo committed
56

Ayolo's avatar
hack  
Ayolo committed
57
?>