Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Forteeをバージョンアップしてみた

Kanazawa Yuki
November 30, 2019

 Forteeをバージョンアップしてみた

Kanazawa Yuki

November 30, 2019
Tweet

More Decks by Kanazawa Yuki

Other Decks in Programming

Transcript

  1. 2019/11/30 大改修!PHPレガシーコードビフォーアフター Speaker Biography 2 Yuki Kanzawa Lancers, Inc. /

    Site Reliability Engineer (2013/11 -) Live in Tokyo, Japan Github:yKanazawa Twitter: @yakitori009 Language: C++, Java, PHP, Go Hobby: Shogi(Japanese Chess)
  2. 2019/11/30 大改修!PHPレガシーコードビフォーアフター Upgrade History (https://www.lancers.jp/) 1.3 -> 2.8 2.8 ->

    2.10 2.10 -> 3.x .. more 5.3 -> 5.6 5.6 -> 7.3 -> PHP5.6 requires 2017/6/6 2 months 1.7 year 2019/2/5 1.8 month 2019/3/27 2019/3/28 1 day 2019/5/28 2 months CakePHP2.10 requires PHP7.3 requires
  3. 2019/11/30 大改修!PHPレガシーコードビフォーアフター foteeのサーバー構成 php-cli smtp DB 3306 web ディレクトリ 共有

    SQLクライアント 開発環境(エディタ) PHP 7.2 CakePHP 3.5 MySQL 5.7 WWWブラウザ 80
  4. 2019/11/30 大改修!PHPレガシーコードビフォーアフター 開発環境 •セットアップ手順 •Windows環境で動かない ◦Docker for Windows ◦git for

    Windows ▪makeコマンドがない •Make for Windowsをインストール ▪Cypressが動かない •結局Macを使うことに。。。 git clone https://github.com/hasegawa-tomoki/fortee.git cd fortee cp config/.env.local config/.env make up make install make migrate docker-compose run web bin/cake records import all
  5. 2019/11/30 大改修!PHPレガシーコードビフォーアフター テスト環境 •PHPUnit •Cypress ◦E2Eテスト環境 % make test ...

    ..........W..........IIIIIIIR..IIIIIIII.FIII..RW..W...IIIRRRRIIII 65 / 86 ( 75%) I.IIIIIIIII.IIIIIIIII 86 / 86 (100%) ... FAILURES! Tests: 86, Assertions: 114, Failures: 1, Warnings: 3, Incomplete: 44, Risky: 6. make: *** [test] Error 1
  6. 2019/11/30 大改修!PHPレガシーコードビフォーアフター composer update - Updating symfony/filesystem (v3.4.11 => v4.3.8):

    Downloading (100%) - Updating symfony/config (v3.4.11 => v3.4.35): Downloading (100%) - Updating theseer/tokenizer (1.1.0 => 1.1.3): Downloading (100%) - Updating myclabs/deep-copy (1.8.1 => 1.9.3): Downloading (100%) - Updating friendsofcake/bootstrap-ui (1.4.0 => 1.4.1): Downloading (100%) - Updating twig/twig (v1.35.3 => v1.42.4): Downloading (100%) - Updating ajgl/breakpoint-twig-extension (0.3.1 => 0.3.4): Downloading (100%) - Updating wyrihaximus/twig-view (4.3.4 => 4.3.5): Downloading (100%) - Updating symfony/process (v3.4.11 => v4.3.8): Downloading (100%) - Updating symfony/finder (v3.4.11 => v4.3.8): Downloading (100%) - Updating seld/jsonlint (1.7.1 => 1.7.2): Downloading (100%) - Updating justinrainbow/json-schema (5.2.7 => 5.2.9): Downloading (100%) - Installing composer/xdebug-handler (1.4.0): Downloading (100%) - Updating composer/spdx-licenses (1.4.0 => 1.5.2): Downloading (100%) - Updating composer/semver (1.4.2 => 1.5.0): Downloading (100%) - Updating composer/ca-bundle (1.1.1 => 1.2.4): Downloading (100%) - Updating composer/composer (1.6.5 => 1.9.1): Downloading (100%) - Updating m1/env (2.1.1 => 2.1.2): Downloading (100%) - Removing seld/cli-prompt (1.0.3) - Removing doctrine/lexer (v1.0.1) - Removing doctrine/inflector (v1.2.0) - Removing doctrine/collections (v1.4.0) - Removing doctrine/annotations (v1.4.0) - Removing doctrine/common (v2.7.3) - Updating cakephp/plugin-installer (1.1.0 => 1.1.1): - Updating paragonie/random_compat (v2.0.15 => v2.0.18): Downloading (100%) - Installing ralouphie/getallheaders (3.0.3): Downloading (100%) - Updating guzzlehttp/psr7 (1.4.2 => 1.6.1): Downloading (100%) - Updating guzzlehttp/guzzle (6.3.3 => 6.4.1): Downloading (100%) - Updating league/oauth2-client (2.3.0 => 2.4.1): Downloading (100%) - Updating symfony/polyfill-mbstring (v1.8.0 => v1.12.0): Downloading (100%) - Updating symfony/polyfill-ctype (v1.11.0 => v1.12.0): Downloading (100%) - Updating symfony/dom-crawler (v3.4.11 => v4.3.8): Downloading (100%) - Updating symfony/css-selector (v3.4.11 => v4.3.8): Downloading (100%) - Updating symfony/browser-kit (v3.4.11 => v4.3.8): Downloading (100%) - Updating fabpot/goutte (v3.2.2 => v3.2.3): Downloading (100%) - Installing markbaker/matrix (1.2.0): Downloading (100%) - Installing markbaker/complex (1.4.7): Downloading (100%) - Updating phpoffice/phpspreadsheet (1.3.1 => 1.9.0): Downloading (100%) - Updating phpoffice/phpexcel (1.8.1 => 1.8.2): Downloading (100%) - Updating react/promise (v2.7.0 => v2.7.1): Downloading (100%) - Updating mpyw/cowitter (v1.0.3 => v1.0.5): Downloading (100%) - Updating fzaninotto/faker (v1.8.0 => v1.9.0): Downloading (100%) - Updating doctrine/cache (v1.6.2 => 1.9.1): Downloading (100%) - Installing doctrine/event-manager (1.1.0): Downloading (100%) - Updating doctrine/dbal (v2.5.13 => v2.10.0): Downloading (100%) - Updating lapaz/quick-brown-fox (0.1.2 => 0.1.3): Downloading (100%) - Updating symfony/yaml (v3.4.17 => v3.4.35): Downloading (100%) - Installing symfony/polyfill-php72 (v1.12.0): Downloading (100%) - Updating symfony/var-dumper (v3.4.11 => v4.3.8): Downloading (100%) - Updating zendframework/zend-diactoros (1.7.2 => 1.8.7): Downloading (100%) - Updating psr/log (1.0.2 => 1.1.2): Downloading (100%) - Updating cakephp/chronos (1.1.4 => 1.2.8): Downloading (100%) - Updating cakephp/cakephp (3.5.17 => 3.5.18): Downloading (100%) - Updating fusic/encount (2.0.5 => 2.0.9): Downloading (100%) - Updating jakub-onderka/php-console-color (0.1 => v0.2): Downloading (100%) - Updating jakub-onderka/php-console-highlighter (v0.3.2 => v0.4): Downloading (100%) - Updating nikic/php-parser (v4.0.2 => v4.3.0): Downloading (100%) - Updating symfony/debug (v3.4.11 => v4.3.8): Downloading (100%) - Updating symfony/console (v3.4.11 => v3.4.35): Downloading (100%) - Updating psy/psysh (v0.9.6 => v0.9.9): Downloading (100%) - Updating squizlabs/php_codesniffer (3.3.0 => 3.5.2): Downloading (100%) - Updating cakephp/cakephp-codesniffer (3.0.5 => 3.1.2): Downloading (100%) - Updating doctrine/instantiator (1.2.0 => 1.3.0): Downloading (100%) - Updating sebastian/exporter (3.1.0 => 3.1.2): Downloading (100%) - Updating webmozart/assert (1.4.0 => 1.5.0): Downloading (100%) - Updating phpdocumentor/reflection-common (1.0.1 => 2.0.0): Downloading (100%) - Updating phpdocumentor/type-resolver (0.4.0 => 1.0.1): Downloading (100%) - Updating phpdocumentor/reflection-docblock (4.3.0 => 4.3.2): Downloading (100%) - Updating phpspec/prophecy (1.8.0 => 1.9.0): Downloading (100%)
  7. 2019/11/30 大改修!PHPレガシーコードビフォーアフター PHPUnit •正常終了 ◦Twitterのテストだけスルー % make test ... ..........W..........IIIIIIIR..IIIIIIII.FIII..RW..W...IIIRRRRIIII

    65 / 86 ( 75%) I.IIIIIIIII.IIIIIIIII 86 / 86 (100%) ... FAILURES! Tests: 86, Assertions: 114, Failures: 1, Warnings: 3, Incomplete: 44, Risky: 6. make: *** [test] Error 1
  8. 2019/11/30 大改修!PHPレガシーコードビフォーアフター 修正内容 •composer.jsonの修正 •composer update Downloading (100%) - Updating

    cakephp/migrations (1.7.2 => 1.8.1): Downloading (100%) - Updating cakephp/debug_kit (3.14.2 => 3.16.7): Downloading (100%) - Updating wyrihaximus/twig-view (4.3.5 => 4.3.8): Downloading (100%) - Updating cakephp/bake (1.6.4 => 1.8.7): Downloading (100%)
  9. 2019/11/30 大改修!PHPレガシーコードビフォーアフター PHPUnit Encount¥Error¥EncountErrorHandler::handleError() - ROOT/vendor/fusic/encount/src/Error/EncountErrorHandler.php, line 22 deprecationWarning -

    CORE/src/Core/functions.php, line 311 Cake¥Core¥Plugin::routes() - CORE/src/Core/Plugin.php, line 306 Cake¥Core¥Plugin::routes() - CORE/src/Core/Plugin.php, line 310 include - ROOT/config/routes.php, line 326 Cake¥Routing¥Router::_loadRoutes() - CORE/src/Routing/Router.php, line 1170 Cake¥Routing¥Router::url() - CORE/src/Routing/Router.php, line 610 App¥Classes¥MisocaCore::__construct() - APP/Classes/MisocaCore.php, line 28 App¥Test¥TestCase¥Classes¥MisocaCoreTest::setUp() - ROOT/tests/TestCase/Classes/MisocaCoreTest.php, line 23 ... You can disable deprecation warnings by setting `Error.errorLevel` to `E_ALL & ~E_USER_DEPRECATED` in your config/app.php •正常終了 ◦以下のdeprecationWarningが出力されるようになった
  10. 2019/11/30 大改修!PHPレガシーコードビフォーアフター Cypress 2019-11-17 18:43:12 Notice: Deprecated (16384): You no

    longer need to call `Plugin::routes()` after upgrading to use Http¥Server. See https://book.cakephp.org/3.0/en/development/application.html#adding-the-new-http- stack-to-an-existing-application for upgrade information. - /var/www/html/config/routes.php, line: 326 2019-11-17 18:43:18 Notice: Deprecated (16384): Accessing url as a property will be removed in 4.0.0. Use getPath() instead. - /var/www/html/src/Classes/UsersCore.php, line: 192 2019-11-17 18:43:20 Notice: Deprecated (16384): Router::parse() is deprecated. Use Router::parseRequest() instead. This will require adopting the Http¥Server library. - /var/www/html/src/Classes/UsersCore.php, line: 195 2019-11-17 18:43:20 Notice: Deprecated (16384): Response::type() is deprecated. Use setTypeMap(), getType() or withType() instead. - /var/www/html/src/Controller/AppController.php, line: 219 … •正常終了 ◦debug.logにNoticeが出力されるようになった
  11. 2019/11/30 大改修!PHPレガシーコードビフォーアフター 修正内容 •composer.jsonの修正 •composer update Downloading (100%) - Updating

    cakephp/debug_kit (3.16.7 => 3.21.0): Downloading (100%) - Updating cakephp/bake (1.8.7 => 1.10.1): Downloading (100%)
  12. 2019/11/30 大改修!PHPレガシーコードビフォーアフター PHPUnit •正常終了 ◦Twitterのテストだけスルー % make test ... ..........W..........IIIIIIIR..IIIIIIII.FIII..RW..W...IIIRRRRIIII

    65 / 86 ( 75%) I.IIIIIIIII.IIIIIIIII 86 / 86 (100%) ... FAILURES! Tests: 86, Assertions: 114, Failures: 1, Warnings: 3, Incomplete: 44, Risky: 6. make: *** [test] Error 1
  13. 2019/11/30 大改修!PHPレガシーコードビフォーアフター Cypress •error.log •以下のcontainをコメントアウトすれば発生しない。。。 ◦スポンサープラングループ(親要素)をselect ◦ついでに子要素(スポンサープラン)をselect ▪そのorderを取得する処理 public function

    index() { $sponsorPlanGroups = $this->SponsorPlanGroups->find() // ->contain(['SponsorPlans' => function (¥Cake¥ORM¥Query $q) { // return $q->where(['SponsorPlans.sort' => 'asc']); // }]) ->where(['SponsorPlanGroups.conference_id' => $this->activeConference->id]) ->order(['SponsorPlanGroups.sort' => 'asc']); $this->set(compact('sponsorPlanGroups')); } Error: [InvalidArgumentException] Cannot convert value of type `string` to integer
  14. 2019/11/30 大改修!PHPレガシーコードビフォーアフター 修正内容 •composer.jsonの修正 •composer update Package operations: 0 installs,

    2 updates, 0 removals - Updating cakephp/cakephp (3.7.9 => 3.8.6Loading from cache - Updating cakephp/bake (1.10.1 => 1.11.2): Loading from cache
  15. 2019/11/30 大改修!PHPレガシーコードビフォーアフター PHPUnit •正常終了 ◦Twitterのテストだけスルー % make test ... ..........W..........IIIIIIIR..IIIIIIII.FIII..RW..W...IIIRRRRIIII

    65 / 86 ( 75%) I.IIIIIIIII.IIIIIIIII 86 / 86 (100%) ... FAILURES! Tests: 86, Assertions: 114, Failures: 1, Warnings: 3, Incomplete: 44, Risky: 6. make: *** [test] Error 1
  16. 2019/11/30 大改修!PHPレガシーコードビフォーアフター PHPUnit •正常終了 ◦Twitterのテストだけスルー % make test ... ..........W..........IIIIIIIR..IIIIIIII.FIII..RW..W...IIIRRRRIIII

    65 / 86 ( 75%) I.IIIIIIIII.IIIIIIIII 86 / 86 (100%) ... FAILURES! Tests: 86, Assertions: 114, Failures: 1, Warnings: 3, Incomplete: 44, Risky: 6. make: *** [test] Error 1
  17. 2019/11/30 大改修!PHPレガシーコードビフォーアフター Composerのdeprecatedライブラリ •mpyw/twistoauth ◦Use mpyw/cowitter instead •phpoffice/phpexcel ◦Use phpoffice/phpspreadsheet

    instead •phpunit/phpunit-mock-objects ◦No replacement was suggested Package mpyw/twistoauth is abandoned, you should avoid using it. Use mpyw/cowitter instead. Package phpoffice/phpexcel is abandoned, you should avoid using it. Use phpoffice/phpspreadsheet instead. Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.
  18. 2019/11/30 大改修!PHPレガシーコードビフォーアフター CakePHP4のインストール "require": { "php": ">=7.2", "cakephp/cakephp": "4.x-dev", "cakephp/plugin-installer":

    "^1.0", "mobiledetect/mobiledetectlib": "2.*" }, "require-dev": { "cakephp/bake": "4.x-dev", "cakephp/cakephp-codesniffer": "dev-next", "cakephp/debug_kit": "4.x-dev", "cakephp/migrations": "4.x-dev", "josegonzalez/dotenv": "3.*", "phpunit/phpunit": "^8.0", "psy/psysh": "@stable" }, •依存関係が複雑 ◦https://github.com/cakephp/app/blob/4.x/composer.json をベースにcompser.json作り直し ◦CakePHP4に対応してなかったライブラリ "adayth/cakephp-cipher-behavior": "^1.0", "fusic/encount": "^2.0", "pgbi/cakephp3-soft-delete": "^1.3", "sizuhiko/cake_fabricate": "^0.2.2"
  19. 2019/11/30 大改修!PHPレガシーコードビフォーアフター CakePHP Upgrade toolを使う •CakePHP Upgrade tool ◦https://github.com/cakephp/upgrade ▪4.xブランチに切り替え

    •実行 ◦/src/Template → /templates に移動 ◦ctp → phpに変更 root@localhost:~/upgrade# ./bin/cake filename locales /var/www/html … root@localhost:~/upgrade# ./bin/cake templates locales /var/www/html Moving sub directories of /var/www/html/templatesfatal: source directory is empty, source=templates/Layout/Email, destination=templates/Layout/email_fatal: bad source, source=templates/Layout/email_, destination=templates/Layout/email/email_fatal: source directory is empty, source=templates/Element/Flash, destination=templates/Element/flash_fatal: bad source, source=templates/Element/flash_, destination=templates/Element/flash/flash_ …
  20. 2019/11/30 大改修!PHPレガシーコードビフォーアフター Rectorを使う •実行 ◦失敗。ここで時間切れ。。。 root@localhost:/var/www/html# ./bin/cake upgrade rector src/

    [27-Nov-2019 17:46:37 Asia/Tokyo] PHP Fatal error: Declaration of App¥Application::middleware($middlewareQueue) must be compatible with Cake¥Http¥BaseApplication::middleware(Cake¥Http¥MiddlewareQueue $middleware): Cake¥Http¥MiddlewareQueue in /var/www/html/src/Application.php on line 30 Fatal error: Declaration of App¥Application::middleware($middlewareQueue) must be compatible with Cake¥Http¥BaseApplication::middleware(Cake¥Http¥MiddlewareQueue $middleware): Cake¥Http¥MiddlewareQueue in /var/www/html/src/Application.php on line 30
  21. 2019/11/30 大改修!PHPレガシーコードビフォーアフター PHP7.4 •PHP7.4 ◦2019/11/28リリース •php-7.4-apache コンテナ ◦2019/11/29リリース •修正内容 2

    0 1 9 /1 1 /3 0 大改修!PHPレガシーコードビフォーアフター PHP7.4 •PHP7.4 ◦2019/11/28リリース •php-7.4-apache コンテナ ◦2019/11/29リリース •修正内容
  22. 2019/11/30 大改修!PHPレガシーコードビフォーアフター PHPUnit •エラーが1つ増えた。。 •imagecreatefromjpeg 関数が見つからない ◦php-gdが正しく入っていない? % make test

    ... ..........W..........IIIIIIIR..IIIIIIII.FIII..RW..W...IIIRRRRIIII 65 / 86 ( 75%) I.IIIIIIIII.IIIIIIIII 86 / 86 (100%) ... ERRORS! Tests: 87, Assertions: 99, Errors: 2, Failures: 1, Warnings: 3, Incomplete: 43, Risky: 6. make: *** [test] Error 2 There were 2 errors: 1) App¥Test¥TestCase¥Classes¥ForteeUtilTest::testCrop Error: Call to undefined function App¥Classes¥imagecreatefromjpeg() /var/www/html/src/Classes/ForteeUtil.php:118 /var/www/html/tests/TestCase/Classes/ForteeUtilTest.php:64 2) App¥Test¥TestCase¥Classes¥OctavCoreTest::testImport Error: Call to undefined function App¥Classes¥imagecreatefromjpeg()