2020/03/18 line-bot-sdk用コード削除作業

運用しているアプリケーションにおいて、LINEとTwitter両方を使えるようにしていたが、twitter側の機能が主流となり、LINEを使っているユーザはこの1年近く誰もいない状態となっている。

そもそもメンテも止めたので、現状動作もしないコードである。
そのため、これら関連ファイルを削除する。

LINEに対応するためプロジェクトのファイル構造がやや歪になっていたりもするので、そこも調整する。

不要なパッケージの削除

こちらの記事を参考に、以下のようにline-bot-sdkのpackageをremoveする。

$ composer remove --no-update linecorp/line-bot-sdk
$ composer update --dry-run
$ composer update

全部updateしたので、`twig`とか`twitterauth`とか、`aws-sdk-php`とかもバージョンが上がってしまいビビり倒したけど、挙動を確認したら大丈夫そうだった。

$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 0 installs, 9 updates, 1 removal
 - Removing linecorp/line-bot-sdk (3.13.0)
 - Updating abraham/twitteroauth (1.0.1 => 1.1.0): Loading from cache
 - Updating symfony/polyfill-ctype (v1.13.1 => v1.14.0): Downloading 
Downloading (100%)         
 - Updating symfony/polyfill-mbstring (v1.13.1 => v1.14.0): Downloadi
Downloading (100%)         
 - Updating twig/twig (v3.0.1 => v3.0.3):Downloading (100%)         )
 - Updating aws/aws-sdk-php (3.133.6 => 3.133.38): Downloading (conne
Downloading (100%)         
 - Updating webmozart/assert (1.6.0 => 1.7.0): Downloading (connectin
Downloading (100%)         
 - Updating phpdocumentor/type-resolver (1.0.1 => 1.1.0): Downloading
Downloading (100%)         
 - Updating phpdocumentor/reflection-docblock (4.3.4 => 5.1.0): Downl
Downloading (100%)         
 - Updating phpspec/prophecy (v1.10.2 => v1.10.3): Downloading (conne
Downloading (100%)         
Writing lock file
Generating autoload files

こういう現象を想定して、composer.jsonに記載するpackageはメジャーバージョン等についてキチンと指定をしておいてあげたい。

不要なファイルの削除と編集

不要となるファイルを削除していく。汚いコードとはいえ、当時一生懸命書いたコードなので何かこみ上げるものがある

$ git rm htdocs/index.php
rm 'htdocs/index.php'

$ git rm src/Event.php
rm 'src/Event.php'

LINEの認証情報を`Setting.php`に書いてあるので、これも削除する。
`dir`の情報はLINE関連でしか使っていない。
今はdirectoryのpathも変わってるのでそもそもこの情報は間違っていた。

$ git diff src/Setting_template.php
diff --git a/src/Setting_template.php b/src/Setting_template.php
index 36b962e..a726bda 100644
--- a/src/Setting_template.php
+++ b/src/Setting_template.php
@@ -20,11 +20,6 @@ class Setting
  public static function getSetting()
  {
    return [
-      'bot' => [
-        'channelToken' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
-        'channelSecret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
-      ],
-      'dir' => '/var/www/yukari/',
      'db' => [
        'username' => 'xxxx',
        'password' => 'xxxx',

`git add -A`して、変更をすべてcommitする

$ git add -A
[06:45 taro@taro-hida.tk twitter]
$ git status
On branch delete-LINE-modules
Changes to be committed:
 (use "git reset HEAD <file>..." to unstage)

       modified:   ../composer.json
       deleted:    ../htdocs/index.php
       deleted:    ../src/Event.php
       modified:   ../src/Setting_template.php

commit、githubにpushして、github側でpull requestを作成してmasterにmergeする

$ git commit -m 'delete line-bot-sdk files [kanashimino commit] 2020/03/18'
[delete-LINE-modules c395969] delete line-bot-sdk files [kanashimino commit] 2020/03/18

$ git push origin delete-LINE-modules

問題ないので作成したpull requestをmergeする。
最後に、本番環境上にmasterを忘れずにpullして、githubの状態を本番環境に反映させる。そしてbranchを削除。

$ git pull origin master
composer.json            |   1 -
htdocs/index.php         | 143 -----------------------------------------------------------------------------------------------------------------------------------------------
src/Event.php            |  30 ------------------------------
src/Setting_template.php |   5 -----
twitter/twitter-bot.php  |  14 +++++++++++++-
5 files changed, 13 insertions(+), 180 deletions(-)
delete mode 100644 htdocs/index.php
delete mode 100644 src/Event.php

$ git branch -d delete-LINE-modules 
Deleted branch delete-LINE-modules (was c395969).

作業報告(感想)

個人的にインパクトの大きな変更だったんだけど、30分くらいで、しかも特にトラブルもなく終わった。

LINEのコードがいなくなったことでprojectのフォルダ構成をもう少しきれいに整えることができるようになったと思うので、今後は構成をシンプルにしていきたい。

この記事が気に入ったらサポートをしてみませんか?