Changeset 107664 in spip-zone
- Timestamp:
- Nov 20, 2017, 6:00:30 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
_plugins_/paniers/trunk/paniers_pipelines.php
r104603 r107664 2 2 3 3 // Sécurité 4 if (!defined('_ECRIRE_INC_VERSION')) return; 4 if (!defined('_ECRIRE_INC_VERSION')) { 5 return; 6 } 5 7 6 8 // Supprimer tous les paniers en cours qui sont trop vieux 7 function paniers_optimiser_base_disparus($flux) {9 function paniers_optimiser_base_disparus($flux) { 8 10 include_spip('inc/config'); 9 11 // On cherche la date depuis quand on a le droit d'avoir fait le panier 10 $depuis_ephemere = date('Y-m-d H:i:s', time() - 3600*intval(lire_config('paniers/limite_ephemere', 24)));11 $depuis_enregistres = date('Y-m-d H:i:s', time() - 3600 *intval(lire_config('paniers/limite_enregistres', 168)));12 12 $depuis_ephemere = date('Y-m-d H:i:s', time() - 3600 * intval(lire_config('paniers/limite_ephemere', 24))); 13 $depuis_enregistres = date('Y-m-d H:i:s', time() - 3600 * intval(lire_config('paniers/limite_enregistres', 168))); 14 13 15 // Soit le panier est à un anonyme donc on prend la limite éphémère, soit le panier appartient à un auteur et on prend l'autre limite 14 16 $paniers = sql_allfetsel( 15 17 'id_panier', 16 18 'spip_paniers', 17 'statut = ' .sql_quote('encours').' and ((id_auteur=0 and date<'.sql_quote($depuis_ephemere).') or (id_auteur>0 and date<'.sql_quote($depuis_enregistres).'))'19 'statut = ' . sql_quote('encours') . ' and ((id_auteur=0 and date<' . sql_quote($depuis_ephemere) . ') or (id_auteur>0 and date<' . sql_quote($depuis_enregistres) . '))' 18 20 ); 19 if (is_array($paniers)) 21 if (is_array($paniers)) { 20 22 $paniers = array_map('reset', $paniers); 21 23 } 24 22 25 // S'il y a bien des paniers à supprimer 23 if ($paniers) {26 if ($paniers) { 24 27 // Le in 25 28 $in = sql_in('id_panier', $paniers); 26 29 27 30 // On supprime d'abord les liens 28 31 sql_delete( … … 30 33 $in 31 34 ); 32 35 33 36 // Puis les paniers 34 37 $nombre = intval(sql_delete( … … 39 42 40 43 $flux['data'] += $nombre; 44 41 45 return $flux; 42 46 } 43 47 44 48 // La CSS pour le panier 45 function paniers_insert_head_css($flux) {46 $css = timestamp(find_in_path('css/paniers.css'));49 function paniers_insert_head_css($flux) { 50 $css = timestamp(find_in_path('css/paniers.css')); 47 51 $flux .= "<link rel='stylesheet' type='text/css' media='all' href='$css' />\n"; 52 48 53 return $flux; 49 54 } 50 51 55 52 56 /** 53 57 * Sur une transformation de commande en attente 54 58 * on supprime le panier source si besoin 59 * 55 60 * @param $flux 61 * 56 62 * @return @flux 57 63 */ 58 function paniers_post_edition($flux) {64 function paniers_post_edition($flux) { 59 65 60 66 // Si on est dans le cas d'une commande qui passe de attente/en cours=>paye/livre/erreur 61 if ($flux['args']['table'] =='spip_commandes'62 AND $id_commande=$flux['args']['id_objet']63 AND $flux['args']['action']=='instituer'64 65 AND !in_array($flux['data']['statut'],array('attente','encours'))66 AND in_array($flux['args']['statut_ancien'],array('attente','encours'))67 AND $commande = sql_fetsel('id_commande, source', 'spip_commandes', 'id_commande='.intval($id_commande))){67 if ($flux['args']['table'] == 'spip_commandes' 68 AND $id_commande = $flux['args']['id_objet'] 69 AND $flux['args']['action'] == 'instituer' 70 AND isset($flux['data']['statut']) 71 AND !in_array($flux['data']['statut'], array('attente', 'encours')) 72 AND in_array($flux['args']['statut_ancien'], array('attente', 'encours')) 73 AND $commande = sql_fetsel('id_commande, source', 'spip_commandes', 'id_commande=' . intval($id_commande))) { 68 74 69 if (preg_match(",^panier#(\d+)$,", $commande['source'],$m)){70 $id_panier = intval($m[1]);75 if (preg_match(",^panier#(\d+)$,", $commande['source'], $m)) { 76 $id_panier = intval($m[1]); 71 77 $supprimer_panier = charger_fonction('supprimer_panier', 'action/'); 72 78 $supprimer_panier($id_panier); 73 79 74 80 // nettoyer une eventuelle double commande du meme panier 75 sql_updateq("spip_commandes", array('source'=>''),"source=".sql_quote($commande['source']));81 sql_updateq("spip_commandes", array('source' => ''), "source=" . sql_quote($commande['source'])); 76 82 #spip_log('suppression panier '.$id_panier,'paniers'); 77 83 }
Note: See TracChangeset
for help on using the changeset viewer.