Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Statamic 5 #441

Merged
merged 17 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ jobs:

strategy:
matrix:
php: [8.3, 8.2, 8.1]
laravel: [10.*]
statamic: [^4.0]
testbench: [8.*]
php: [8.3, 8.2]
laravel: [11.*]
statamic: [^5.0]
os: [ubuntu-latest]

name: ${{ matrix.php }} - ${{ matrix.statamic }} - ${{ matrix.laravel }}
Expand All @@ -32,8 +31,8 @@ jobs:

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "statamic/cms:${{ matrix.statamic }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer require "laravel/framework:${{ matrix.laravel }}" "statamic/cms:${{ matrix.statamic }}" --no-interaction --no-update
composer install --no-interaction

- name: Run PHPUnit
run: composer test
run: vendor/bin/phpunit
12 changes: 4 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,17 @@
"require": {
"php": "^8.1",
"doctrine/dbal": "^3.7",
"laravel/prompts": "^0.1.17",
"laravel/framework": "^10.25.0 || ^11.0",
"pixelfear/composer-dist-plugin": "^0.1.5",
"statamic/cms": "^4.44"
"statamic/cms": "^5.0"
},
"require-dev": {
"laravel/pint": "^1.0",
"nunomaduro/collision": "^6.1",
"spatie/test-time": "^1.2",
"orchestra/testbench": "^8.0",
"orchestra/testbench": "^8.0 || ^9.0",
"phpunit/phpunit": "^10.0"
},
"scripts": {
"test": [
"php -d memory_limit=-1 ./vendor/bin/phpunit"
]
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
Expand Down
9 changes: 6 additions & 3 deletions docs/blueprints.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,12 @@ $table->json('values')->nullable();
And the cast defined on the model:

```php
protected $casts = [
'values' => 'array', // or 'json', AsArrayObject::class
];
protected function casts(): array
{
return [
'values' => 'array', // or 'json', AsArrayObject::class
];
}
```

:::note Note!
Expand Down
6 changes: 3 additions & 3 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ title: 'Installation'

## System Requirements

- PHP 8.1 & above
- Statamic v4
- Laravel 10 & above
- Statamic 5
- Laravel 11
- PHP 8.2 or above

## Installing via Composer

Expand Down
16 changes: 15 additions & 1 deletion docs/upgrade-guides/v6-x-to-v7-0.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,21 @@ php artisan view:clear

## Changes

TODO
### High: Support for Statamic 4 has been dropped

Runway v7 has dropped support for Statamic 4. In order to update Runway, you will need to [upgrade to Statamic 5](https://statamic.dev/upgrade-guide/4-0-to-5-0).

By keeping up-to-date with major Statamic versions, it removes the risk of any compatibility issues between Statamic 4 and 5.

### High: Support for Laravel 10 has been dropped

Runway v7 has dropped support for Laravel 10. In order to update Runway, you will need to [upgrade to Laravel 11](https://laravel.com/docs/11.x/upgrade).

If you wish, you can automate the upgrade process using [Laravel Shift](https://laravelshift.com/upgrade-laravel-10-to-laravel-11).

### Medium: Support for PHP 8.1 has been dropped

Runway v7 has dropped support for PHP 8.1. In order to update Runway, you should update the version of PHP you're using, both locally and on production. The latest version of PHP is 8.3.

## Previous upgrade guides

Expand Down
8 changes: 4 additions & 4 deletions src/Console/Commands/GenerateBlueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function __construct()
*/
public function handle()
{
$this->info('Generating blueprints...');
$this->components->info('Generating blueprints...');
$this->line('');

$resources = [];
Expand All @@ -143,7 +143,7 @@ public function handle()
$this->generateForResource($resource);
}

$this->info('✔️ Done');
$this->components->info('✔️ Done');
}

protected function generateForResource(Resource $resource)
Expand Down Expand Up @@ -171,13 +171,13 @@ protected function generateForResource(Resource $resource)
$this->generateNewBlueprint($resource, $fields);

if (count($errorMessages) === 0) {
$this->line("✔️ {$resource->name()}");
$this->components->info("✔️ {$resource->name()}");
$this->line('');
} else {
$this->line("❌ {$resource->name()}");

foreach ($errorMessages as $errorMessage) {
$this->comment($errorMessage);
$this->components->error($errorMessage);
}

$this->line('');
Expand Down
6 changes: 4 additions & 2 deletions src/Console/Commands/GenerateMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use StatamicRadPack\Runway\Runway;
use Symfony\Component\Process\Process;

use function Laravel\Prompts\confirm;

class GenerateMigration extends Command
{
use RunsInPlease;
Expand Down Expand Up @@ -181,7 +183,7 @@ public function __construct()
*/
public function handle()
{
$this->info('Generating migrations...');
$this->components->info('Generating migrations...');
$this->line('');

$resources = [];
Expand All @@ -201,7 +203,7 @@ public function handle()
$this->generateForResource($resource);
}

if ($this->ask('Should we run your migrations?', 'yes') === 'yes') {
if (confirm('Should we run your migrations?')) {
Artisan::call('migrate');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Console/Commands/ListResources.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct()
public function handle()
{
if (! Runway::allResources()->count()) {
return $this->error("Your application doesn't have any resources.");
return $this->components->error("Your application doesn't have any resources.");
}

$this->table(
Expand Down
40 changes: 25 additions & 15 deletions src/Console/Commands/RebuildUriCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
use Illuminate\Console\Command;
use Illuminate\Support\Str;
use Statamic\Console\RunsInPlease;
use Statamic\View\Antlers\Parser;
use Statamic\Facades\Antlers;
use StatamicRadPack\Runway\Resource;
use StatamicRadPack\Runway\Routing\RunwayUri;
use StatamicRadPack\Runway\Runway;

use function Laravel\Prompts\confirm;
use function Laravel\Prompts\progress;

class RebuildUriCache extends Command
{
use RunsInPlease;
Expand Down Expand Up @@ -47,7 +50,7 @@ public function __construct()
public function handle()
{
if (! $this->option('force')) {
$confirm = $this->confirm(
$confirm = confirm(
'You are about to rebuild your entire URI cache. This may take part of your site down while running. Are you sure you want to continue?'
);

Expand All @@ -60,29 +63,36 @@ public function handle()

Runway::allResources()
->each(function (Resource $resource) {
$this->newLine(2);
$this->info("Building {$resource->name()} URIs");

if (! $resource->hasRouting()) {
$this->warn("Skipping {$resource->name()}, routing not configured.");
$this->components->warn("Skipping {$resource->name()}, routing not configured.");

return;
}

$query = $resource->model()->newQuery();
$query->when($query->hasNamedScope('runwayRoutes'), fn ($query) => $query->runwayRoutes());

$this->withProgressBar($query->get(), function ($model) use ($resource) {
$uri = (new Parser())
->parse($resource->route(), $model->toAugmentedArray())
->__toString();
if (! $query->exists()) {
$this->components->warn("Skipping {$resource->name()}, no models to cache.");

$uri = Str::start($uri, '/');
return;
}

$model->runwayUri()->create([
'uri' => $uri,
]);
});
progress(
label: "Caching {$resource->name()} URIs",
steps: $query->get(),
callback: function ($model) use ($resource) {
$uri = Antlers::parser()
->parse($resource->route(), $model->toAugmentedArray())
->__toString();

$uri = Str::start($uri, '/');

$model->runwayUri()->create([
'uri' => $uri,
]);
}
);
});
}
}
4 changes: 2 additions & 2 deletions src/Routing/Traits/RunwayRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use Illuminate\Database\Eloquent\Relations\MorphOne;
use Illuminate\Support\Str;
use Statamic\Facades\Antlers;
use Statamic\StaticCaching\Cacher;
use Statamic\Support\Arr;
use Statamic\View\Antlers\Parser;
use StatamicRadPack\Runway\Routing\Routable;
use StatamicRadPack\Runway\Routing\RoutingModel;
use StatamicRadPack\Runway\Routing\RunwayUri;
Expand Down Expand Up @@ -80,7 +80,7 @@ public static function bootRunwayRoutes()
return;
}

$uri = (new Parser())
$uri = Antlers::parser()
->parse($resource->route(), $model->toAugmentedArray())
->__toString();

Expand Down
10 changes: 5 additions & 5 deletions tests/Console/Commands/GenerateBlueprintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ public function can_generate_blueprint()
->once();

$this->artisan('runway:generate-blueprints', ['resource' => 'post'])
->expectsOutput('Generating blueprints...')
->expectsOutput('✔️ Done')
->expectsOutputToContain('Generating blueprints...')
->expectsOutputToContain('✔️ Done')
->assertExitCode(0);
}

Expand Down Expand Up @@ -149,10 +149,10 @@ public function can_generate_resource_with_column_that_can_not_be_matched_to_a_f
->once();

$this->artisan('runway:generate-blueprints', ['resource' => 'post'])
->expectsOutput('Generating blueprints...')
->expectsOutputToContain('Generating blueprints...')
->expectsOutput('❌ Posts')
->expectsOutput('Column [blob] could not be matched with a fieldtype.')
->expectsOutput('✔️ Done')
->expectsOutputToContain('Column [blob] could not be matched with a fieldtype.')
->expectsOutputToContain('✔️ Done')
->assertExitCode(0);
}
}
16 changes: 8 additions & 8 deletions tests/Console/Commands/GenerateMigrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function can_generate_migrations_for_multiple_resources()

$this
->artisan('runway:generate-migrations')
->expectsQuestion('Should we run your migrations?', 'no')
->expectsQuestion('Should we run your migrations?', false)
->execute();

$this->assertFileExists(
Expand Down Expand Up @@ -122,7 +122,7 @@ public function can_generate_migration_for_single_resource()
->artisan('runway:generate-migrations', [
'resource' => 'food',
])
->expectsQuestion('Should we run your migrations?', 'no')
->expectsQuestion('Should we run your migrations?', false)
->execute();

$this->assertFileExists(
Expand Down Expand Up @@ -163,7 +163,7 @@ public function cant_generate_migration_where_table_already_exists()
->artisan('runway:generate-migrations', [
'resource' => 'food',
])
->expectsQuestion('Should we run your migrations?', 'no')
->expectsQuestion('Should we run your migrations?', false)
->expectsOutput('Table [foods] already exists. Runway is not smart enough yet to update existing migrations. Sorry!')
->execute();

Expand Down Expand Up @@ -193,7 +193,7 @@ public function can_generate_migration_and_run_them_afterwards()
->artisan('runway:generate-migrations', [
'resource' => 'food',
])
->expectsQuestion('Should we run your migrations?', 'yes')
->expectsQuestion('Should we run your migrations?', true)
->execute();

$this->assertFileExists(database_path().'/migrations/'.now()->format('Y_m_d_His').'_create_foods_table.php');
Expand Down Expand Up @@ -226,7 +226,7 @@ public function can_generate_migration_and_ensure_normal_field_is_correct()
->artisan('runway:generate-migrations', [
'resource' => 'food',
])
->expectsQuestion('Should we run your migrations?', 'no')
->expectsQuestion('Should we run your migrations?', false)
->execute();

$this->assertFileExists(
Expand Down Expand Up @@ -275,7 +275,7 @@ public function can_generate_migration_and_ensure_max_items_1_field_is_correct()
->artisan('runway:generate-migrations', [
'resource' => 'food',
])
->expectsQuestion('Should we run your migrations?', 'no')
->expectsQuestion('Should we run your migrations?', false)
->execute();

$this->assertFileExists(
Expand Down Expand Up @@ -320,7 +320,7 @@ public function can_generate_migration_and_ensure_field_is_nullable_if_required_
->artisan('runway:generate-migrations', [
'resource' => 'food',
])
->expectsQuestion('Should we run your migrations?', 'no')
->expectsQuestion('Should we run your migrations?', false)
->execute();

$this->assertFileExists(
Expand Down Expand Up @@ -355,7 +355,7 @@ public function can_generate_migration_and_ensure_field_is_not_nullable_if_requi
->artisan('runway:generate-migrations', [
'resource' => 'food',
])
->expectsQuestion('Should we run your migrations?', 'no')
->expectsQuestion('Should we run your migrations?', false)
->execute();

$this->assertFileExists(
Expand Down
2 changes: 1 addition & 1 deletion tests/Console/Commands/ListResourcesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public function it_outputs_error_when_no_resources_exist()

$this
->artisan('runway:resources')
->expectsOutput("Your application doesn't have any resources.");
->expectsOutputToContain("Your application doesn't have any resources.");
}
}
2 changes: 1 addition & 1 deletion tests/Console/Commands/RebuildUriCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function skips_resources_without_routing_configured()
'You are about to rebuild your entire URI cache. This may take part of your site down while running. Are you sure you want to continue?',
'yes'
)
->expectsOutput('Skipping Author, routing not configured.');
->expectsOutputToContain('Skipping Author, routing not configured.');

$this->assertCount(0, RunwayUri::all());
}
Expand Down
Loading
Loading