From f1ca33de3bce194c10cfa9b7fbc588fbf6b3014d Mon Sep 17 00:00:00 2001 From: x2000habouzit Date: Mon, 31 Jul 2006 11:35:15 +0000 Subject: [PATCH] simpler database and session. git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@745 839d8a87-29fc-0310-9880-83ba4fa771e5 --- bin/connect.db.inc.php | 2 ++ bin/cron/notifs.birthday.php | 8 ++++---- bin/search.rebuild_db.php | 6 ++++-- classes/Page.php | 2 +- classes/XDB.php | 40 ++++++++++++++++++++++++++++++++++----- htdocs/xnet.php | 1 + htdocs/xorg.php | 1 + include/newsletter.inc.php | 1 - include/platal/globals.inc.php.in | 15 ++++++++++----- include/xnet/globals.inc.php | 3 --- include/xorg/globals.inc.php | 3 --- 11 files changed, 58 insertions(+), 24 deletions(-) diff --git a/bin/connect.db.inc.php b/bin/connect.db.inc.php index db6e379..e6cbe2a 100644 --- a/bin/connect.db.inc.php +++ b/bin/connect.db.inc.php @@ -24,4 +24,6 @@ ini_set('include_path','/usr/share/php:'.dirname(__FILE__).'/../include'); require_once('xorg.inc.php'); require_once('xorg.misc.inc.php'); +require_once dirname(__FILE__).'/../classes/XDB.php'; + ?> diff --git a/bin/cron/notifs.birthday.php b/bin/cron/notifs.birthday.php index 7a6098a..86631d0 100755 --- a/bin/cron/notifs.birthday.php +++ b/bin/cron/notifs.birthday.php @@ -26,10 +26,10 @@ $date = date('Y-m-d', time() + 7 * 24*60*60); $stamp = date('Ymd000000'); $like = date('%-m-d', time() + 7 * 24*60*60); -$globals->db->query("INSERT INTO watch_ops (uid, cid, known, date) - SELECT user_id, 4, $stamp, '$date' - FROM auth_user_md5 - WHERE naissance LIKE '$like' AND deces=0"); +XDB::execute("INSERT INTO watch_ops (uid, cid, known, date) + SELECT user_id, 4, $stamp, '$date' + FROM auth_user_md5 + WHERE naissance LIKE '$like' AND deces=0"); ?> diff --git a/bin/search.rebuild_db.php b/bin/search.rebuild_db.php index ad8d3b3..5c77822 100755 --- a/bin/search.rebuild_db.php +++ b/bin/search.rebuild_db.php @@ -28,11 +28,13 @@ XDB::execute('DELETE FROM search_name'); $res = XDB::iterRow('SELECT auth_user_md5.user_id, nom, prenom, nom_usage, profile_nick FROM auth_user_md5 LEFT JOIN auth_user_quick USING(user_id)'); $i = 0; -$muls = array(1,1,1,0.2); +$muls = array(1, 1, 1, 0.2); while ($tmp = $res->next()) { $uid = array_shift($tmp); _user_reindex($uid, $tmp, $muls); - printf ("%02.2f %%\n", ++$i*100/$res->total()); + printf("\r%u / %u", ++$i, $res->total()); } +print "done\n"; + ?> diff --git a/classes/Page.php b/classes/Page.php index 935f36b..1f45385 100644 --- a/classes/Page.php +++ b/classes/Page.php @@ -118,7 +118,7 @@ class PlatalPage extends Smarty } if ($globals->debug & 1) { - $this->assign('db_trace', $globals->db->trace_format($this, 'database-debug.tpl')); + $this->assign('db_trace', XDB::trace_format($this, 'database-debug.tpl')); } $this->assign('validate', true); diff --git a/classes/XDB.php b/classes/XDB.php index 7e157ce..6c52afd 100644 --- a/classes/XDB.php +++ b/classes/XDB.php @@ -21,6 +21,8 @@ class XDB { + var $_trace_data = array(); + // {{{ function _prepare function _prepare($args) { @@ -30,6 +32,30 @@ class XDB } // }}} + + function _query($query) { + global $globals; + + if ($globals->debug & 1) { + $_res = mysql_query("EXPLAIN $query"); + $explain = array(); + while ($row = @mysql_fetch_assoc($_res)) { + $explain[] = $row; + } + $trace_data = array('query' => $query, 'explain' => $explain); + @mysql_free_result($_res); + } + + $res = mysql_query($query); + + if ($globals->debug & 1) { + $trace_data['error'] = mysql_error(); + $GLOBALS['XDB::trace_data'][] = $trace_data; + } + + return $res; + } + // {{{ function query function &query() @@ -40,9 +66,9 @@ class XDB // }}} // {{{ function execute() - function execute() { - global $globals; - return $globals->db->query(XDB::_prepare(func_get_args())); + function execute() + { + return XDB::_query(XDB::_prepare(func_get_args())); } // }}} @@ -99,6 +125,11 @@ class XDB } // }}} + + function trace_format(&$page, $template = 'database-debug.tpl') { + $page->assign('trace_data', $GLOBALS['XDB::trace_data']); + return $page->fetch($template); + } } class XOrgDBResult @@ -112,9 +143,8 @@ class XOrgDBResult function XOrgDBResult($query) { - global $globals; if (strpos($query, 'SQL_CALC_FOUND_ROWS') === false) { - $this->_res = $globals->db->query($query); + $this->_res = XDB::_query($query); } else { $this->_res = mysql_query($query); } diff --git a/htdocs/xnet.php b/htdocs/xnet.php index 53ecd71..0b06746 100644 --- a/htdocs/xnet.php +++ b/htdocs/xnet.php @@ -21,6 +21,7 @@ $GLOBALS['IS_XNET_SITE'] = true; +require_once dirname(__FILE__).'/../classes/XDB.php'; require_once dirname(__FILE__).'/../classes/Xnet.php'; require_once dirname(__FILE__).'/../classes/PLModule.php'; require_once dirname(__FILE__).'/../classes/CoreLogger.php'; diff --git a/htdocs/xorg.php b/htdocs/xorg.php index e966de3..077faba 100644 --- a/htdocs/xorg.php +++ b/htdocs/xorg.php @@ -21,6 +21,7 @@ // $GLOBALS['IS_XNET_SITE'] = true; +require_once dirname(__FILE__).'/../classes/XDB.php'; require_once dirname(__FILE__).'/../classes/Platal.php'; require_once dirname(__FILE__).'/../classes/PLModule.php'; require_once dirname(__FILE__).'/../classes/CoreLogger.php'; diff --git a/include/newsletter.inc.php b/include/newsletter.inc.php index 32fd34a..712573e 100644 --- a/include/newsletter.inc.php +++ b/include/newsletter.inc.php @@ -22,7 +22,6 @@ // {{{ requires + defines require_once("xorg.misc.inc.php"); -require_once("diogenes/diogenes.misc.inc.php"); if (isset($page)) { $page->addCssLink('nl.css'); diff --git a/include/platal/globals.inc.php.in b/include/platal/globals.inc.php.in index e539595..660176e 100644 --- a/include/platal/globals.inc.php.in +++ b/include/platal/globals.inc.php.in @@ -19,16 +19,12 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ -require_once('diogenes/diogenes.core.globals.inc.php'); -require_once('diogenes/diogenes.database.inc.php'); -require_once dirname(__FILE__).'/../../classes/XDB.php'; - class CoreConfig { var $locale = 'fr_FR'; } -class PlatalGlobals extends DiogenesCoreGlobals +class PlatalGlobals { var $page = 'XorgPage'; var $session; @@ -49,6 +45,9 @@ class PlatalGlobals extends DiogenesCoreGlobals var $table_log_sessions = 'logger.sessions'; var $table_log_events = 'logger.events'; + /** The class to use for session handling. */ + var $session = 'DiogenesCoreSession'; + /** logger */ var $tauth = array('native'=>'auth_user_md5'); var $tlabel = array('native'=>'X.Org'); @@ -66,6 +65,12 @@ class PlatalGlobals extends DiogenesCoreGlobals $this->spoolroot = dirname(dirname(dirname(__FILE__))); } + function dbconnect() + { + @mysql_connect($this->dbhost, $this->dbuser, $this->dbpwd); + @mysql_select_db($this->dbdb); + } + function read_config() { $array = parse_ini_file($this->spoolroot.'/configs/platal.ini', true); diff --git a/include/xnet/globals.inc.php b/include/xnet/globals.inc.php index b1aec4a..c36f80d 100644 --- a/include/xnet/globals.inc.php +++ b/include/xnet/globals.inc.php @@ -38,9 +38,6 @@ class XnetGlobals extends PlatalGlobals $globals->read_config(); $globals->dbconnect(); - if ($globals->debug & 1) { - $globals->db->trace_on(); - } } function asso($key=null) diff --git a/include/xorg/globals.inc.php b/include/xorg/globals.inc.php index 03ef9c5..1a9fe1f 100644 --- a/include/xorg/globals.inc.php +++ b/include/xorg/globals.inc.php @@ -38,9 +38,6 @@ class XorgGlobals extends PlatalGlobals $globals->read_config(); $globals->dbconnect(); - if ($globals->debug & 1) { - $globals->db->trace_on(); - } } } -- 2.1.4