Gossamer Forum
Home : Products : DBMan : Customization :

Verify Records Exist

Quote Reply
Verify Records Exist
I am starting a new post for this the other was getting very long.

I have implemented the code for verifying that a record exists for every account within the .pass file - and if not it returns a listing of those ID's to the screen.

However, when I run this the listing returned indicates that all 1149 userID's in the database do NOT have a record associated with the ID.

Here is the code I used from http://www.gossamer-threads.com/scripts/forum/resources/Forum12/HTML/000617.html :

sub html_verify_accounts {
# --------------------------------------------------------

&html_print_headers;
$page_title = "Accounts Without Records";
&html_page_top;

open (PASSWD, "<$auth_pw_file") or &cgierr("unable to open password file. Reason: $!\n");
@passwds = <PASSWD>;
close PASSWD;
foreach $pass (@passwds) {
@data = split ":",$pass;
print $data[0];
undef %rec;
%rec = &get_record($data[0]);
if (!%rec) {
push (@list,$data[0]);
}
}
unless ($list[0]) {
print "All users have records in the database";
}
else {
print "The following users do not have records in the database:<BR>";
foreach $user (@list) {
print "$user<BR>";
}
}
&html_footer
&html_page_bottom;
}
Quote Reply
Re: Verify Records Exist In reply to
Carol - that worked ! It was the db_key - I had it set on 'ID' instead of 'UserID'.

Thanks!
----------------
donm
Quote Reply
Re: Verify Records Exist In reply to
Since I started answering questions at the bottom of the list, I answered your question before I saw this one.

Is your $db_key field the same as your userid field?

Are you logged on with "admin" permissions?


------------------
JPD





Quote Reply
Re: Verify Records Exist In reply to
Ooooops - spoke too soon. Yes, this does cause the Verify Records code to work - however, it has caused other problems within our DB.

Our db_key has always been 'ID' rather than 'UserID' because we allow our users to create their own userid's. The 'ID' field is filled in by the default.count insuring that each record has a unique number.

When changing the db_key from 'ID' to 'UserID' we no longer get a number but the UserID which is something we don't want to use.

Will this only work using the UserID as the db_key?

Nevermind - I see in the default.pass that it is looking to the 'UserID' field there. Hmmmmm.... looks like we won't be able to use this.... or we could change the db_key to 'UserID' just long enough to get the listing and then change it back to 'ID'... ok..yes, I am rambling. (g)

Thanks!
-------------------
donm

[This message has been edited by donm (edited September 25, 1999).]

[This message has been edited by donm (edited September 25, 1999).]
Quote Reply
Re: Verify Records Exist In reply to
Well, you can do work it another way, but it will be slower.

Instead of

Code:
%rec = &get_record($data[0]);
if (!%rec) {
push (@list,$data[0]);
}

use

Code:
$in{$db_cols[$auth_user_field]} = $data[0];
$status,@hits = &query("view");
unless ($status eq "ok") {
push (@list,$data[0]);
}

This does require that you have an $auth_user_field. If you don't at least have that, you won't be able to use the mod.

BTW, you can delete the lines

print $data[0];
undef %rec;




------------------
JPD





Quote Reply
Re: Verify Records Exist In reply to
Carol - what is it in the codes that determine if there is a record or not?

-------------
donm
Quote Reply
Re: Verify Records Exist In reply to
Code:
unless ($status eq "ok") {

The script does a search for a record with an associated userid. If it finds one, then the variable $status = "ok." If not, it will be "no matching records." For our purposes, we just need to know that it didn't find a record with that userid. If it didn't, the userid is added to the @list array and then printed out.


------------------
JPD





Quote Reply
Re: Verify Records Exist In reply to
I apologize for asking so many questions - but I am trying to get a better understanding of how things work.

.... and what does this line do?

$status,@hits = &query("view");

Also - I tried this and it timed out - nothing returned?

Here is the code:

sub html_verify_accounts {
# --------------------------------------------------------

&html_print_headers;
$page_title = "Accounts Without Records";
&html_page_top;

open (PASSWD, "<$auth_pw_file") or &cgierr("unable to open password file. Reason: $!\n");
@passwds = <PASSWD>;
close PASSWD;
foreach $pass (@passwds) {
@data = split ":",$pass;
$in{$db_cols[$auth_user_field]} = $data[0];
$status,@hits = &query("view");
unless ($status eq "ok") {
push (@list,$data[0]);
}
}
unless ($list[0]) {
print "All users have records in the database";
}
else {
print "The following users do not have records in the database:<BR>";
foreach $user (@list) {
print "$user<BR>";
}
}
&html_footer
&html_page_bottom;
}

------------------------------

and then in default.cfg I have this in the
authorization options:

# Auth user field. This is the field position in the database used for storing
# the userid who owns the record. Set to -1 if not used.
$auth_user_field = 16;
$auth_email_field = 10;

-----------------------
donm

[This message has been edited by donm (edited September 25, 1999).]
Quote Reply
Re: Verify Records Exist In reply to
That's okay. I like it when folks are trying to understand the code rather than just pasting it in.

Here's the explanation of each line in the code I just gave you:

Code:
$in{$db_cols[$auth_user_field]} = $data[0];
# Sets a value for searching the database.
# $db_cols[$auth_user_field] would be the name of the field for the userid
# $data[0] is the userid from the .pass file

$status,@hits = &query("view");
# Does the search.
# sub query returns two variables
# $status is either "ok," "no matching records" or "no search terms defined"
# @hits contains the actual values from the search. We don't use them in this mod, but
# we need to account for them.

unless ($status eq "ok") {
# I explained this one earlier

push (@list,$data[0]);
# add the userid to the @list array

}

Does that help?


------------------
JPD


[This message has been edited by JPDeni (edited September 25, 1999).]
Quote Reply
Re: Verify Records Exist In reply to
Yes - that helps. I thought maybe we were searching for records that had "view" permissions when I saw that line, and not all accounts have view permissions.

I think you and I both posted at the same time - did you see that I edited the post above your last?

----------------
donm
Quote Reply
Re: Verify Records Exist In reply to
We must have been simulposting. I hadn't seen your addition to your previous post.

I have another idea of how to do this, but it might time out, too. The only way I can envision the mod working is to take the .pass file, one line at a time and then search through the .db file to see if there's a matching record.

This other way might take less time, though.

Code:
&html_print_headers;
$page_title = "Accounts Without Records";
&html_page_top;

open (PASSWD, "<$auth_pw_file") or &cgierr("unable to open password file. Reason:$!\n");
@passwds = <PASSWD>;
close PASSWD;

foreach $pass (@passwds) {
@data = split ":",$pass;
open (DB, "<$db_file_name") or &cgierr("unable to open database: $db_file_name.\nReason: $!");
@lines = <DB>;
close DB;

$found = 0;
foreach $line (@lines) {
(/^#/) and next;
(/^\s*$/) and next;
chomp ($line);
@values = &split_decode($line);

if ($values[$auth_user_field] eq $data[0]) {
$found = 1;
last;
}
}
unless ($found) {
push (@list,$data[0]);
}
}
unless ($list[0]) {
print "All users have records in the database";
}
else {
print "The following users do not have records in the database:<BR>";
foreach $user (@list) {
print "$user<BR>";
}
}
&html_footer;
&html_page_bottom;

This code will stop the search after one record is found that matches the userid. Or at least, it should. Smile


------------------
JPD





Quote Reply
Re: Verify Records Exist In reply to
Wow - that search runs pretty fast compared to the last. However, it returns ALL userid's whether they have a record or not.

-------------
donm
Quote Reply
Re: Verify Records Exist In reply to
Try changing

unless ($found) {

to

unless ($found == 1) {



------------------
JPD





Quote Reply
Re: Verify Records Exist In reply to
Looks like nothing is being found. I added the code you specified in your last post and all I receive back is:

The following users do not have records in the database:
#UserID
(and then it lists every userid in the .pass file)
Quote Reply
Re: Verify Records Exist In reply to
Carol - it still returns ALL userid's whether they have a record in the database or not.

---------------
donm
Quote Reply
Re: Verify Records Exist In reply to
Long-distance debugging is really difficult. But I'll give it a shot.

First let's see if anything is being found.

After

$found = 1;

Add

print "Found $data[0]<BR>";

See if you get any results from that. It should print out

Found fred
Found Wilma
Found JPDeni



------------------
JPD





Quote Reply
Re: Verify Records Exist In reply to
Okay, let's try something else, then.

First off, there's no point in having it check for #Userid as a userid.

After

foreach $pass (@passwds) {

add

Code:
if ($pass =~ /^#/) { next; }

Hmmmm. That could be part of the other problem, too.

Try changing

(/^#/) and next;
(/^\s*$/) and next;

to

Code:
if ($line =~ /^#/) { next; }
if ($line =~ /^\s*$/) { next; }

See if that does anything.

If not, I don't know what to do. I can't figure out how to do any more long-distance debugging.

------------------
JPD





Quote Reply
Re: Verify Records Exist In reply to
Whoooo Hooooo looks like you did it ! Now it first prints out the userid's it finds records for, then it prints out the list of userid's without associated records.

Thanks so much Carol !
-----------------------
donm
Quote Reply
Re: Verify Records Exist In reply to
We both learned something, Don. Smile

You can take out the line

print "Found $data[0]<BR>";

if you don't want the ones that do have records to be printed out.

(I really didn't have much hope when I wrote my last post. It sure is nice to be wrong sometimes. Smile )


------------------
JPD





Quote Reply
Re: Verify Records Exist In reply to
Carol - Sometimes I like it when people are wrong. :-) Especially in this case.

BTW - I took out the line that you specified in the last post and it would not work. I put it back in and everything works fine again.

Do you know of an easy way to delete the accounts without records? I don't want anyone to spend alot of time on it - because I can delete them manually.

Thanks so much again for your help - you are much appreciated !
-------------------
donm
Quote Reply
Re: Verify Records Exist In reply to
It would take some time to work out an automatic delete of users without records.

I'm surprised that taking out

print "Found $data[0]<BR>";

would cause the script not to work. But then I was surprised earlier, so this is something I should expect. Smile


------------------
JPD





Quote Reply
Re: Verify Records Exist In reply to
Carol - no problem. I think we would rather delete them manually anyway now that I think about it. Just to make sure that we are not deleting something that we need.

Again thanks for your help !

-------------------
donm
Quote Reply
Re: Verify Records Exist In reply to
Here is the corrected code from this thread. Note that it is set up to be used with the "user-friendly" html.pl file.

Code:
sub html_verify_accounts {
# --------------------------------------------------------

&html_print_headers;
$page_title = "Accounts Without Records";
&html_page_top;

open (PASSWD, "<$auth_pw_file") or &cgierr("unable to open password file. Reason: $!\n");
@passwds = <PASSWD>;
close PASSWD;

foreach $pass (@passwds) {
@data = split ":",$pass;
open (DB, "<$db_file_name") or &cgierr("unable to open database: $db_file_name.\nReason: $!");
@lines = <DB>;
close DB;

$found = 0;
foreach $line (@lines) {
if ($line =~ /^#/) { next; }
if ($line =~ /^\s*$/) { next; }
chomp ($line);
@values = &split_decode($line);

if ($values[$auth_user_field] eq $data[0]) {
$found = 1;
last;
}
}
unless ($found == 1) {
push (@list,$data[0]);
}
}
unless ($list[0]) {
print "All users have records in the database";
}
else {
print "The following users do not have records in the database:<BR>";
foreach $user (@list) {
print "$user<BR>";
}
}
&html_footer;
&html_page_bottom;
}

The best way to get the code is to click the "Edit" button on this message and copy the code between the [code] and [/code] tags.

------------------
JPD






Quote Reply
Re: Verify Records Exist In reply to
THANK YOU, THANK YOU, THANK YOU JPD.

Lot better. Thx.

JR