summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'import.categories.php')
-rw-r--r--import.categories.php46
1 files 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