delete swp
[webpac2] / sql / pgbits.pl
index af9431b..4ce17a5 100755 (executable)
@@ -11,9 +11,10 @@ my $self = {
        user => 'dpavlin',
        passwd => '',
        catalog => {
-               path => '/rest/references/PgGeneratBits/bits',
-               title   => 'PostgreSQL General Bits',
+               name    => 'PostgreSQL General Bits',
+               path    => '/rest/references/PgGeneratBits/bits',
                uri     => 'http://www.varlena.com/varlena/GeneralBits/archive.php',
+               type    => 'pgbits',
        },
 };
 
@@ -28,8 +29,8 @@ my $l = Class::DBI::Loader->new(
        relationships   => 1,
 );
 
-my $this_catalog = $l->find_class('catalog_webarchive')->find_or_create( $self->{catalog} );
-$this_catalog->dbi_commit;
+my $top = $l->find_class('topics_webarchive')->find_or_create( $self->{catalog} );
+$top->dbi_commit;
 
 sub issue {
        my $file = shift || die;
@@ -43,19 +44,16 @@ sub issue {
                $issue_date = $1;
 print "## issue $issue_no on $issue_date [$file]\n";
 
-               $this_entry = $l->find_class('entries_pgbits')->find_or_create(
+               $issue = $l->find_class('topics_pgbits')->find_or_create(
+                       name => "issue $issue_no",
                        date => $issue_date,
-                       issue => $issue_no,
                        path => $file,
-                       title => $self->{catalog}->{title} . " :: $issue_no",
+                       issue => $issue_no,
+                       type => 'pgbits',
+                       parent_id => $top->id,
                );
-               $this_entry->dbi_commit;
+               $issue->dbi_commit;
 
-               $l->find_class('catalog_entry')->find_or_create(
-                       catalog_id => $this_catalog->id,
-                       entry_id => $this_entry->id,
-                       e_type => 'pgbits',
-               )->dbi_commit;
        } else {
                warn "can't find issue number and date in $file, skipping\n";
                return;
@@ -64,7 +62,7 @@ print "## issue $issue_no on $issue_date [$file]\n";
 
        while($html =~ s#^.*?<!-- IKEY="([^"]+)" -->.+?<MYTITLE>\s*([^<]+)\s*</MYTITLE>.+?<ITITLE>\s*([^<]+)\s*</ITITLE>.+?<IDATE>\s*([^<]+)\s*</IDATE>.+?</TABLE>\s*(.+?)\s*<ICONT>\s*(.+?)\s*</ICONT>##si){
                my $row = {
-                       title => $1 . ( $2 ? " :: $2" : ""),
+                       name => $2 . ( $3 ? " :: $3" : ""),
 
                        ikey => $1,
                        mytitle => $2,
@@ -73,12 +71,17 @@ print "## issue $issue_no on $issue_date [$file]\n";
                        html => $5,
                        contributors => $6,
 
-                       entry_id => $this_entry->id,
-                       i_type => 'pgbits',
+                       type => 'pgbits',
                };
-       
-               print $row->{title}," ", $row->{date},"\n";
-               $l->find_class('items_pgbits')->find_or_create( $row )->dbi_commit;
+
+               print $row->{name}," ", $row->{date},"\n";
+               my $article = $l->find_class('items_pgbits')->find_or_create( $row );
+               $article->dbi_commit;
+
+               $l->find_class('item_topics')->find_or_create(
+                       topic_id => $issue->id,
+                       item_id => $article->id,
+               )->dbi_commit;
        }
 }