From aabae445999af9844cd462d9ace6b088a2daa255 Mon Sep 17 00:00:00 2001 From: Steve Dibb Date: Sun, 14 Feb 2010 18:13:07 +0000 Subject: cleanup git-svn-id: file:///var/svn/portage@87 3218660a-b0cf-4799-a991-8ddcc5b9e0f3 --- import.categories.php | 46 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/import.categories.php b/import.categories.php index d4dcd63..880fb8e 100644 --- a/import.categories.php +++ b/import.categories.php @@ -11,6 +11,15 @@ $table = 'category'; + $sql = "SELECT COUNT(1) FROM category;"; + $count = $db->getOne($sql); + + // If no categories, reset the sequence + if($count === "0") { + $sql = "ALTER SEQUENCE category_id_seq RESTART WITH 1;"; + $db->query($sql); + } + $arr = $tree->getCategories(); $arr_diff = importDiff($table, $arr); @@ -27,7 +36,25 @@ foreach($arr_diff['insert'] as $name) { $arr_insert = array('name' => $name); $db->autoExecute($table, $arr_insert, MDB2_AUTOQUERY_INSERT); + + $category_id = $db->lastInsertID(); + + $c = new PortageCategory($name); + + foreach($c->getDescriptions() as $lingua => $description) { + + $arr_insert = array( + 'category' => $category_id, + 'lingua' => $lingua, + 'description' => $description, + ); + + $db->autoExecute('category_description', $arr_insert, MDB2_AUTOQUERY_INSERT); + + } + } + } // FIXME I should check the mtimes of the directories @@ -40,14 +67,15 @@ $sql = "SELECT name, id FROM category;"; $arr = $db->getAssoc($sql); - foreach($arr as $category_name => $category) { - - $db_category = new DBCategory($category); - $c = new PortageCategory($category_name); - - if($db_category->description != $c->description['en']) - $db_category->description = $c->description['en']; - - } + // FIXME work with linguas +// foreach($arr as $category_name => $category) { +// +// $db_category = new DBCategory($category); +// $c = new PortageCategory($category_name); +// +// if($db_category->description != $c->description['en']) +// $db_category->description = $c->description['en']; +// +// } ?> \ No newline at end of file -- cgit v1.2.3-65-gdbad