Subversion Repositories Sites.tela-botanica.org

Rev

Rev 275 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

<?php
/*vim: set expandtab tabstop=4 shiftwidth=4: */
// +------------------------------------------------------------------------------------------------------+
// | PHP version 5.1                                                                                      |
// +------------------------------------------------------------------------------------------------------+
// | Copyright (C) 1999-2006 Tela Botanica (accueil@tela-botanica.org)                                    |
// +------------------------------------------------------------------------------------------------------+
// | This file is part of tela_botanica_v4.                                                                         |
// |                                                                                                      |
// | Foobar is free software; you can redistribute it and/or modify                                       |
// | it under the terms of the GNU General Public License as published by                                 |
// | the Free Software Foundation; either version 2 of the License, or                                    |
// | (at your option) any later version.                                                                  |
// |                                                                                                      |
// | Foobar is distributed in the hope that it will be useful,                                            |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                        |
// | GNU General Public License for more details.                                                         |
// |                                                                                                      |
// | You should have received a copy of the GNU General Public License                                    |
// | along with Foobar; if not, write to the Free Software                                                |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
// +------------------------------------------------------------------------------------------------------+
// CVS : $Id$
/**
* tela_botanica_v4 - nettoyage_wikini.php
*
* Description :
*
*@package tela_botanica_v4
//Auteur original :
*@author        Jean-Pascal MILCENT <jpm@tela-botanica.org>
//Autres auteurs :
*@author        Aucun
*@copyright     Tela-Botanica 1999-2007
*@version       $Revision$ $Date$
// +------------------------------------------------------------------------------------------------------+
*/

// +------------------------------------------------------------------------------------------------------+
// |                                            ENTÊTE du PROGRAMME                                       |
// +------------------------------------------------------------------------------------------------------+
define('CHEMIN_PEAR', '../api/pear/');
$GLOBALS['_NETTOYAGE_']['sites'] = array('http://www.tela-botanica.org', 'http://www.outils-reseaux.org');

// +------------------------------------------------------------------------------------------------------+
// |                                            CORPS du PROGRAMME                                        |
// +------------------------------------------------------------------------------------------------------+
echo '<h1>'.'Nettoyage des wikini de tela_prod_wikini'.'</h1>';
$Nettoyage = new Nettoyage();
echo '<pre>';
$Nettoyage->nettoyageGlobal();
echo '</pre>';
// +------------------------------------------------------------------------------------------------------+
// |                                           CLASSES du PROGRAMME                                       |
// +------------------------------------------------------------------------------------------------------+
class Nettoyage {
        private $bdd_principale = "tela_prod_wikini";
        private $bdd_options = array('debug' => 3);
        private $bdd_dsn = "mysql://utilisateur:mdp@localhost/tela_prod_wikini";
        
        public function __construct()
        {
//              $fichier_ini = 'bdd.ini';
//              $ok = $this->parserFichierIni($fichier_ini);
//              if (!$ok) {
//                      $e = 'Impossible de parser le fichier : '.$fichier_ini;
//                      trigger_error($e, E_USER_ERROR);
//              } else {
                        require_once CHEMIN_PEAR.'DB.php';
                        $this->connexion = DB::connect($this->bdd_dsn, $this->bdd_options);
                        if (PEAR::isError($this->connexion)) {
                                $e = $this->connexion->getMessage();
                                trigger_error($e, E_USER_ERROR);
                        }
//              }
        }
        
        public function nettoyageGlobal()
        {
                $res = $this->connexion->query('SHOW TABLES');
                if (PEAR::isError($res)) {
                        die($res->getMessage());
                }
                $tab_tables = array();
                $ligne = '';
                while ($res->fetchInto($ligne)) {
                        $tab_tables[] = $ligne[0];
                }

                foreach ($tab_tables as $table) {
                        echo "\n".$table."\n";

                        // Referrers
                        if (preg_match('/_referrers$/', $table)) {
                                $site_nbre = count($GLOBALS['_NETTOYAGE_']['sites']);
                                $site_0 = $GLOBALS['_NETTOYAGE_']['sites'][0];
                                $requete =      'DELETE FROM '.$table.' '.
                                                        'WHERE referrer NOT LIKE "'.$site_0.'%" ';
                                for ($i = 1; $i < $site_nbre; $i++) {
                                        $requete .= 'AND referrer NOT LIKE "'.$GLOBALS['_NETTOYAGE_']['sites'][$i].'%" ';
                                }
                                echo $requete."\n";
                                $res = $this->connexion->query($requete);
                                if (PEAR::isError($res)) {
                                        die($res->getMessage());
                                }
                        }

                        // Pages : commentaires
                        if (preg_match('/_pages$/', $table)) {
                                $requete =      'SELECT tag FROM '.$table.' '.
                                                        'WHERE tag LIKE "Comment%" ';
                                echo $requete."\n";
                                $aso_pages = $this->connexion->getAll($requete, null, DB_FETCHMODE_ASSOC);
                                if (PEAR::isError($aso_pages)) {
                                        die($aso_pages->getMessage());
                                }
                                if (count($aso_pages) > 0) {
                                        $tab_pages = array();
                                        foreach ($aso_pages as $page) {
                                                if (preg_match('/^Comment\d+$/', $page['tag'])){
                                                        $tab_pages[] = $page['tag'];
                                                }
                                        }
                                        if (count($tab_pages) > 0) {
                                                $requete =      'DELETE FROM '.$table.' '.
                                                                        'WHERE tag IN ("'.implode('","', $tab_pages).'") ';
                                                echo $requete."\n";
                                                $res = $this->connexion->query($requete);
                                                if (PEAR::isError($res)) {
                                                        die($res->getMessage());
                                                }
                                        }
                                }
                        }
                        
                        // ACLs : commentaires
                        if (preg_match('/_acls$/', $table)) {
                                $requete =      'DELETE FROM '.$table.' '.
                                                        'WHERE page_tag LIKE "Comment%" ';
                                echo $requete."\n";
                                $res = $this->connexion->query($requete);
                                if (PEAR::isError($res)) {
                                        die($res->getMessage());
                                }
                                
                                $requete =      'UPDATE '.$table.' '.
                                                        'SET list = "+" '.
                                                        'WHERE privilege = "comment" ';
                                echo $requete."\n";
                                $res = $this->connexion->query($requete);
                                if (PEAR::isError($res)) {
                                        die($res->getMessage());
                                }
                        }
                }
        }
        
        function parserFichierIni($fichier_ini)
        {
                if (file_exists($fichier_ini)) {
                        $aso_ini = parse_ini_file($fichier_ini);
                foreach ($aso_ini as $cle => $val) {
                        if (preg_match('/^php:(.+)$/', $val, $correspondances)) {
                                        eval('$this->$cle = '.$correspondances[1].';');
                                } else if (preg_match('/^php-static:(.+)$/', $val, $correspondances)) {
                                        eval('self::$'.$cle.' = '.$correspondances[1].';');
                                } else {
                                        $this->$cle = $val;
                                }
                        }
                } else {
                        return false;
                }
        }
}
/* +--Fin du code ----------------------------------------------------------------------------------------+
*
* $Log$
*
* +-- Fin du code ----------------------------------------------------------------------------------------+
*/
?>