Gossamer Forum
Quote Reply
SQL Insert
Hi,

How do I insert www into URLS that are in the database like http://mysite.com using SQL Command?

Happy Holidays
Quote Reply
Re: [rascal] SQL Insert In reply to
Hi,

Give this script a go (upload to your admin folder, via FTP - and then run via SSH/Telnet, via the commands I will provide);

Code:
#!/usr/local/bin/perl

use strict;
use lib './';
use GT::Base;
use GT::Plugins qw/STOP CONTINUE/;
use Links qw/$CFG $IN $DB/;
use CGI::Carp qw(fatalsToBrowser);
use Data::Dumper;
use GT::SQL::Condition;

Links::init('./');

my $sth = $DB->table('Links')->select( ['ID','URL'], GT::SQL::Condition->new('isValidated','=','Yes','URL','LIKE','http://%') ) || die $GT::SQL::error;

while (my $link = $sth->fetchrow_hashref) {
if (length($link->{URL}) <= 7) { next; } # not valid one
if ($link->{URL} !~ m/^http:\/\/www\.(.*?)/i) {

if (check_if_is_a_sub_domain($link->{URL}) > 0) {
print qq|--- $link->{URL} seems to be a subdomain - not doing ---- \n|;
} else {
$link->{URL} =~ s|\Qhttp://\E|http://www.$1|sig;
print "New URL: (ID: $link->{ID}) $link->{URL} \n";
# $DB->table('Links')->update( { URL => $link->{URL} }, { ID => $link->{ID} } ) || die $GT::SQL::error;
}
}
}


sub check_if_is_a_sub_domain {

my $url = $_[0];
my @cut = split /\//, $url;
my $domain = $cut[2];
my @tmp2 = split /\./, $domain;

if ($#tmp2 > 1) {
#print qq|BLA BLA: $#tmp2 for $domain, $url \n|;
return 1;
}
return 0;
}

Uncomment the bit in red when you are happy it will do what you want :)

Run via SSH/Telnet with;

cd /path/to/your/admin/
perl file.cgi

That should be it :)

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] SQL Insert In reply to
Thanks Andy,

I tryed the script but all it did was print the Sub to the screen when ran by SSH.
Quote Reply
Re: [rascal] SQL Insert In reply to
Sorry for the previous post, it did work, I forgot to add my paths at the top of the script.

Thanks Andy.


One question, why is the script skipping placing www on sub domain names?