|
| 1 | +# Upgrade Guide for Flarum 2.0 |
| 2 | + |
| 3 | +## AWS S3 Adapter Name Changes |
| 4 | + |
| 5 | +### Background |
| 6 | + |
| 7 | +In earlier versions of fof/upload, both `'aws-s3'` and `'awss3'` adapter names were registered, but only `'aws-s3'` had a corresponding method. This caused validation errors when trying to use the `'awss3'` adapter name. |
| 8 | + |
| 9 | +A fix was implemented to provide bidirectional compatibility: both adapter names now work and map to the same `awsS3()` method. This ensures backward compatibility for: |
| 10 | +- Old files in the database with `upload_method = 'awss3'` or `upload_method = 'aws-s3'` |
| 11 | +- Admin configurations forcing one variant while DB has the other |
| 12 | +- MIME type configurations using either variant |
| 13 | + |
| 14 | +### Changes for Flarum 2.0 |
| 15 | + |
| 16 | +For Flarum 2.0, we will standardize on `'aws-s3'` as the canonical adapter name and remove support for `'awss3'`. |
| 17 | + |
| 18 | +### Migration Steps |
| 19 | + |
| 20 | +#### 1. Database Migration |
| 21 | + |
| 22 | +Create a migration to update all existing records: |
| 23 | + |
| 24 | +```php |
| 25 | +<?php |
| 26 | + |
| 27 | +use Illuminate\Database\Schema\Builder; |
| 28 | + |
| 29 | +return [ |
| 30 | + 'up' => function (Builder $schema) { |
| 31 | + // Update files table |
| 32 | + $schema |
| 33 | + ->getConnection() |
| 34 | + ->table('fof_upload_files') |
| 35 | + ->where('upload_method', 'awss3') |
| 36 | + ->update(['upload_method' => 'aws-s3']); |
| 37 | + |
| 38 | + // Update MIME type settings |
| 39 | + $mimeConfiguration = $schema |
| 40 | + ->getConnection() |
| 41 | + ->table('settings') |
| 42 | + ->where('key', 'fof-upload.mimeTypes') |
| 43 | + ->value('value'); |
| 44 | + |
| 45 | + if ($mimeConfiguration) { |
| 46 | + $mimeConfiguration = json_decode($mimeConfiguration, true); |
| 47 | + |
| 48 | + foreach ($mimeConfiguration as $mime => &$config) { |
| 49 | + if (isset($config['adapter']) && $config['adapter'] === 'awss3') { |
| 50 | + $config['adapter'] = 'aws-s3'; |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + $schema |
| 55 | + ->getConnection() |
| 56 | + ->table('settings') |
| 57 | + ->where('key', 'fof-upload.mimeTypes') |
| 58 | + ->update(['value' => json_encode($mimeConfiguration)]); |
| 59 | + } |
| 60 | + }, |
| 61 | +]; |
| 62 | +``` |
| 63 | + |
| 64 | +#### 2. Code Changes |
| 65 | + |
| 66 | +Search for `TODO: Flarum 2.0` in the codebase and make the following changes: |
| 67 | + |
| 68 | +**src/Adapters/Manager.php:** |
| 69 | +- Line 55: Remove `'awss3' => class_exists(S3Client::class),` |
| 70 | +- Lines 76-83: Remove the bidirectional compatibility check block |
| 71 | +- Lines 89-92: Remove the normalization line, use `$adapter` directly |
| 72 | + |
| 73 | +**resources/locale/en.yml:** |
| 74 | +- Line 144: Remove `awss3: AWS S3` translation entry |
| 75 | + |
| 76 | +**Tests to Remove:** |
| 77 | +- `tests/unit/Adapters/ManagerTest.php`: |
| 78 | + - Line 72: Remove `'awss3'` assertion |
| 79 | + - Lines 102-138: Remove `instantiate_normalizes_awss3_to_aws_s3` test |
| 80 | + |
| 81 | +- `tests/integration/api/AdaptersExtenderTest.php`: |
| 82 | + - Lines 28-49: Remove `force_extender_limits_available_adapters_to_awss3` test |
| 83 | + - Lines 51-84: Remove `force_extender_allows_instantiation_of_forced_awss3_adapter` test |
| 84 | + - Line 177: Remove `'awss3'` assertion |
| 85 | + - Lines 186-228: Remove `force_aws_s3_when_db_has_awss3_configuration` test |
| 86 | + - Lines 230-272: Remove `force_awss3_when_db_has_aws_s3_configuration` test |
| 87 | + - Lines 274-311: Remove `awss3_instantiation_works_with_normalization` test |
| 88 | + |
| 89 | +#### 3. Update Documentation |
| 90 | + |
| 91 | +Update any user-facing documentation that references the `'awss3'` adapter name to use `'aws-s3'` instead. |
| 92 | + |
| 93 | +#### 4. Breaking Change Notice |
| 94 | + |
| 95 | +Add a breaking change notice in the changelog: |
| 96 | + |
| 97 | +```markdown |
| 98 | +### Breaking Changes |
| 99 | + |
| 100 | +- **AWS S3 Adapter:** The legacy `'awss3'` adapter name has been removed. The canonical name is now `'aws-s3'`. |
| 101 | + - If you were using `->force('awss3')` in your `extend.php`, change it to `->force('aws-s3')` |
| 102 | + - Database records are automatically migrated during upgrade |
| 103 | +``` |
| 104 | + |
| 105 | +### Testing |
| 106 | + |
| 107 | +After applying these changes: |
| 108 | + |
| 109 | +1. Run all unit tests: `composer test:unit` |
| 110 | +2. Run all integration tests: `composer test:integration` |
| 111 | +3. Verify that: |
| 112 | + - Files with `upload_method = 'aws-s3'` can be rendered |
| 113 | + - New uploads use `'aws-s3'` as the adapter name |
| 114 | + - Forcing `'aws-s3'` works correctly |
| 115 | + - Old references to `'awss3'` no longer exist in the codebase |
| 116 | + |
| 117 | +### Support Period |
| 118 | + |
| 119 | +The bidirectional compatibility (`'awss3'` ⇄ `'aws-s3'`) will be maintained until Flarum 2.0 is released. This gives administrators time to: |
| 120 | +- Update their `extend.php` configurations |
| 121 | +- Run the migration |
| 122 | +- Test their installations |
0 commit comments