Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use DBI;
- use POSIX qw(strftime);
- # MySQL
- our $DB_NAME = "YOUR_DB_NAME";
- our $DB_USER = "YOUR_DB_USER";
- our $DB_PASS = "YOUR_DB_PASS";
- our $DB_HOST = "YOUR_DB_HOST";
- our $DB_PORT = "3306";
- #MT User ID
- my $mt_id = 1;
- my $dbh = DBI->connect("dbi:mysql:dbname=$DB_NAME;host=$DB_HOST;port=$DB_PORT","$DB_USER","$DB_PASS") or die "$!\n Error: failed to connect to DB.\n";
- my $blog_id = $ARGV[0];
- my $replace_text = {
- 'RSS Feed' => '<$MTInclude module="RSS_Feed"$>',
- };
- my $date = strftime( "%Y-%m-%d %H:%M:%S" , localtime());
- my $up_sql = "UPDATE mt_template SET template_text = ?, template_linked_file = ?, template_modified_on = ?, template_modified_by = $mt_id WHERE template_name = ? AND template_blog_id = $blog_id";
- if ($blog_id && $blog_id =~ /^[0-9]+$/){
- my $template = $dbh->prepare("select template_name, template_text, template_linked_file from mt_template where template_blog_id = $blog_id;");
- $template->execute();
- my $update = $dbh->prepare($up_sql);
- while (my $ary_ref = $template->fetchrow_arrayref) {
- my($name, $text, $link) = @$ary_ref;
- foreach my $key(keys %$replace_text){
- if ($name eq $key) {
- $update->bind_param(1,$replace_text->{$key});
- $update->bind_param(2,'');
- $update->bind_param(3,$date);
- $update->bind_param(4,$name);
- $update->execute();
- print "$key | The record has been updated successfully!\n";
- }
- }
- }
- $update->finish;
- $template->finish;
- } else {
- print "Error ブログIDを数字で指定して下さい\n";
- }
- $dbh->disconnect;
Add Comment
Please, Sign In to add comment