Created
July 9, 2015 05:01
-
-
Save ywindish/3929c722187915097380 to your computer and use it in GitHub Desktop.
Backlog Wiki をバックアップする
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Backlog Wikiをローカルにバックアップします | |
| * 要PHP5.3以降 | |
| * usage: php getwikis.php | |
| * ref: https://github.com/atomita/backlog-v2 | |
| * todo: ファイル周りのエラー処理がないので誰か直してください.. | |
| */ | |
| require "vendor/autoload.php"; | |
| use \atomita\Backlog; | |
| use \atomita\BacklogException; | |
| // スペース名を指定します。URL xxxx.backlog.jp の「xxxx」部分です。 | |
| define("SPACE_NAME", "xxxx"); | |
| // バックアップしたいプロジェクトのIDを設定します。 | |
| // プロジェクトのIDはBacklogで「プロジェクト設定」ページを表示するとURLに含まれます。 | |
| define("PROJECT_ID", "12345678"); | |
| // API KEYを指定します。 | |
| // Backlogの「APIの設定」から取得できます。 | |
| define("API_KEY", "xxxxxxxxxxxxxxxxxxxxx"); | |
| // ダウンロードしたWikiをファイル保存するフォルダです。 | |
| define("SAVE_DIR", "../wikis_backup"); | |
| // 保存したファイル名と実際のページ名の対応表を格納するファイル名です。 | |
| // ページ名がファイルシステムで許容される文字列とは限らないのでこのようにしています。 | |
| // ページ名=ファイル名にしたい場合は削除してください。 | |
| define("LIST_FILE", "list.txt"); | |
| // --------------------------------------------------- | |
| if (file_exists(SAVE_DIR) === FALSE) { | |
| mkdir(SAVE_DIR); | |
| } | |
| if (defined('LIST_FILE')) { | |
| $list = fopen(SAVE_DIR.'/'.LIST_FILE, "w"); | |
| } | |
| $backlog = new Backlog(SPACE_NAME, API_KEY); | |
| try { | |
| $wikis = $backlog->wikis(array('projectIdOrKey'=>PROJECT_ID)); | |
| foreach ($wikis as $wiki) { | |
| // wikiページを取得 | |
| $content = $backlog->param($wiki['id'])->get(); | |
| if (defined('LIST_FILE')) { | |
| // ページの中身・ページ名を保存 | |
| file_put_contents(SAVE_DIR.'/'.$wiki['id'], $content['content']); | |
| fputs($list, $wiki['id']."\t".$wiki['name'].PHP_EOL); | |
| } else { | |
| // ページをそのまま保存 (ページ名によってはエラーになります) | |
| file_put_contents(SAVE_DIR.'/'.$wiki['name'], $content['content']); | |
| } | |
| } | |
| } catch(Exception $e) { | |
| print $e->getMessage(); | |
| } | |
| if (defined('LIST_FILE')) { | |
| fclose($list); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
issue: Backlogの階層WikiNameに対応する