From 93eaf8aaf2f616d48ad040991ed4bc0f7c59dc29 Mon Sep 17 00:00:00 2001 From: Steve Dibb Date: Sat, 30 Jan 2010 20:54:49 +0000 Subject: import bugs directly, dont use copy git-svn-id: file:///var/svn/portage@74 3218660a-b0cf-4799-a991-8ddcc5b9e0f3 --- import.bugzilla.php | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/import.bugzilla.php b/import.bugzilla.php index 0688ad7..88f4353 100644 --- a/import.bugzilla.php +++ b/import.bugzilla.php @@ -37,6 +37,8 @@ $arr_categories = $tree->getCategories(); + $arr_keys = array('bug_id', 'bug_severity', 'priority', 'op_sys', 'assigned_to', 'bug_status', 'resolution', 'short_short_desc'); + foreach($arr_categories as $category_name) { if($debug) @@ -45,10 +47,12 @@ $url = "http://bugs.gentoo.org/buglist.cgi?bug_file_loc=&bug_file_loc_type=allwordssubstr&bug_id=&bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&bugidtype=include&chfieldfrom=&chfieldto=Now&chfieldvalue=&email1=&email2=&emailtype1=exact&emailtype2=substring&field-1-0-0=product&field-1-1-0=bug_status&field-1-2-0=short_desc&field0-0-0=assigned_to&field0-1-0=assigned_to&field0-2-0=short_desc&keywords=&keywords_type=allwords&long_desc=&long_desc_type=allwordssubstr&product=Gentoo%20Linux&query_format=advanced&remaction=&short_desc=$category_name%2F&short_desc_type=allwordssubstr&status_whiteboard=&status_whiteboard_type=allwordssubstr&type-1-0-0=anyexact&type-1-1-0=anyexact&type-1-2-0=allwordssubstr&type0-0-0=notequals&type0-1-0=notequals&type0-2-0=notsubstring&value-1-0-0=Gentoo%20Linux&value-1-1-0=UNCONFIRMED%2CNEW%2CASSIGNED%2CREOPENED&value-1-2-0=media-video%2F&value0-0-0=maintainer-wanted%40gentoo.org&value0-1-0=maintainer-needed%40gentoo.org&value0-2-0=new%20package&votes=&ctype=csv"; $ch = curl_init($url); - // FIXME write to a *new* temporary file - // FIXME Make sure the CSV is non-empty - $fp = fopen("/tmp/bugs.csv", "w"); + + $filename = tempnam("/tmp", "bugzilla"); + + $fp = fopen($filename, "w"); + // FIXME check for curl errors curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); @@ -56,16 +60,34 @@ curl_close($ch); fclose($fp); - $sql = "COPY bugzilla FROM '/tmp/bugs.csv' DELIMITER ',' CSV HEADER;"; - $db->query($sql); - + if(filesize($filename)) { + + $row = 1; + + if (($handle = fopen($filename, "r")) !== false) { + + while(($data = fgetcsv($handle, 0, ",")) !== false) { + + if($row > 1) { + $arr_insert = array_combine($arr_keys, $data); + $db->autoExecute('bugzilla', $arr_insert, MDB2_AUTOQUERY_INSERT); + } + + $row++; + + } + fclose($handle); + } + + } + } // FIXME this query takes a while to run // FIXME Have this run after each category is imported, and query for that $cp. That'll go much faster. $sql = "INSERT INTO package_bugs (bug, package, description, status) SELECT b.bug_id AS bug, p.id AS package, b.short_short_desc, 1 FROM package p INNER JOIN category c ON p.category = c.id INNER JOIN bugzilla b ON b.short_short_desc LIKE ('%' || c.name || '/' || p.name || '%');"; $db->query($sql); - + } else { if($verbose) -- cgit v1.2.3-65-gdbad