Guest User

Untitled

a guest
Apr 27th, 2018
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use DBI;
  6.  
  7. # MySQL
  8. our $DB_NAME = "YOUR_DB_NAME";
  9. our $DB_USER = "YOUR_DB_USER";
  10. our $DB_PASS = "YOUR_DB_PASS";
  11. our $DB_HOST = "YOUR_DB_HOST";
  12. our $DB_PORT = "3306";
  13.  
  14. 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";
  15.  
  16. # get blog path
  17. my $blog = $dbh->prepare("select blog_parent_id ,blog_site_path from mt_blog where blog_site_path like 'service/_' OR blog_site_path like 'service/__';");
  18. # get website path
  19. my $web = $dbh->prepare("select blog_id , blog_site_path from mt_blog where blog_class = 'website' AND blog_id = ANY (select blog_parent_id from mt_blog where blog_site_path like 'service/_' OR blog_site_path like 'service/__')");
  20.  
  21. $blog->execute();
  22. $web->execute();
  23.  
  24. my $website;
  25. while (my $ary_web_ref = $web->fetchrow_arrayref) {
  26. my($web_id, $web_path) = @$ary_web_ref;
  27. $web_path =~ s!/([0-9]{1,})$!/$1/!g;
  28. $website->{$web_id} = $web_path;
  29. }
  30.  
  31. while (my $ary_ref = $blog->fetchrow_arrayref) {
  32. my ($blog_parent_id, $blog_path) = @$ary_ref;
  33. my $blog_path_m = $blog_path;
  34. $blog_path =~ s!/([0-9]{1,})$!/$1/index.html!g;
  35. $blog_path =~ s!/([0-9]{1,})/$!/$1/index.html!g;
  36.  
  37. $blog_path_m =~ s!/([0-9]{1,})$!/$1/m/index.php!g;
  38. $blog_path_m =~ s!/([0-9]{1,})/$!/$1/m/index.php!g;
  39.  
  40. foreach my $key(keys $website){
  41. if ($blog_parent_id == $key) {
  42. if (unlink "$website->{$key}$blog_path") {
  43. print "'$website->{$key}$blog_path'は削除されました。\n";
  44. } else {
  45. print "'$website->{$key}$blog_path'は削除できませんでした。\n";
  46. }
  47. if (unlink "$website->{$key}$blog_path_m") {
  48. print "'$website->{$key}$blog_path_m'は削除されました。\n";
  49. } else {
  50. print "'$website->{$key}$blog_path_m'は削除できませんでした。\n";
  51. }
  52. }
  53. }
  54. }
  55.  
  56. $blog->finish;
  57. $web->finish;
  58. $dbh->disconnect;
Add Comment
Please, Sign In to add comment