daily.4am.php 1.66 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 19 20 21 22 23 24 25 26 27 28 29 30 31 32
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");

$req = new requete($site->db,"SELECT * FROM `cpt_verrou` WHERE DATEDIFF(NOW(),date_res) >= 1");

$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";
  
  $client->id = $row['id_utilisateur'];
  $vp->load_by_id ( $row['id_produit'], $row['id_comptoir'], true );
  $vp->debloquer ( $client, $row['quantite'] );
}

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

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 41 42 43
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)");

// Tâche 3 : Nettoyage des créneaux "vides" expriés

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

Ayolo's avatar
Ayolo committed
45

Ayolo's avatar
hack  
Ayolo committed
46
?>