Guest User

Untitled

a guest
Apr 27th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use DBI;
  6. use POSIX qw(strftime);
  7.  
  8. # MySQL
  9. our $DB_NAME = "YOUR_DB_NAME";
  10. our $DB_USER = "YOUR_DB_USER";
  11. our $DB_PASS = "YOUR_DB_PASS";
  12. our $DB_HOST = "YOUR_DB_HOST";
  13. our $DB_PORT = "3306";
  14.  
  15. #MT User ID
  16. my $mt_id = 1;
  17.  
  18. 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";
  19.  
  20. my $blog_id = $ARGV[0];
  21.  
  22. my $replace_text = {
  23. 'RSS Feed' => '<$MTInclude module="RSS_Feed"$>',
  24. };
  25.  
  26. my $date = strftime( "%Y-%m-%d %H:%M:%S" , localtime());
  27.  
  28. 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";
  29.  
  30. if ($blog_id && $blog_id =~ /^[0-9]+$/){
  31. my $template = $dbh->prepare("select template_name, template_text, template_linked_file from mt_template where template_blog_id = $blog_id;");
  32. $template->execute();
  33. my $update = $dbh->prepare($up_sql);
  34.  
  35. while (my $ary_ref = $template->fetchrow_arrayref) {
  36. my($name, $text, $link) = @$ary_ref;
  37.  
  38. foreach my $key(keys %$replace_text){
  39. if ($name eq $key) {
  40. $update->bind_param(1,$replace_text->{$key});
  41. $update->bind_param(2,'');
  42. $update->bind_param(3,$date);
  43. $update->bind_param(4,$name);
  44. $update->execute();
  45. print "$key | The record has been updated successfully!\n";
  46. }
  47. }
  48. }
  49. $update->finish;
  50. $template->finish;
  51. } else {
  52. print "Error ブログIDを数字で指定して下さい\n";
  53. }
  54.  
  55. $dbh->disconnect;
Add Comment
Please, Sign In to add comment