Skip to content
15 changes: 2 additions & 13 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@ jobs:

strategy:
matrix:
php: [8.1, 8.2, 8.3, 8.4]
laravel: [10.*, 11.*, 12.*]
php: [8.3, 8.4]
laravel: [11.*, 12.*]
stability: [prefer-lowest, prefer-stable]
os: [ubuntu-latest]
include:
- os: windows-latest
php: 8.3
laravel: 10.*
stability: prefer-stable
- os: windows-latest
php: 8.3
laravel: 11.*
Expand All @@ -29,13 +25,6 @@ jobs:
php: 8.4
laravel: 11.*
stability: prefer-stable
exclude:
- php: 8.1
laravel: 11.*
- php: 8.1
laravel: 12.*
- php: 8.4
laravel: 10.*

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"mustangostang/spyc": "dev-master#dfd9aadc1f5224065d55b42b712c7e99a50a3f4d"
},
"require-dev": {
"statamic/cms": "^5.41",
"statamic/cms": "^v6.0.0-alpha.3",
"mockery/mockery": "^1.4.4",
"orchestra/testbench": "^8.28 || ^9.6.1 || ^10.0",
"orchestra/testbench": "^9.6.1 || ^10.0",
"phpunit/phpunit": "^10.5.35 || ^11.0"
},
"autoload": {
Expand Down Expand Up @@ -41,6 +41,6 @@
"pixelfear/composer-dist-plugin": true
}
},
"minimum-stability": "stable",
"minimum-stability": "dev",
"prefer-stable": true
}
17 changes: 17 additions & 0 deletions src/ContentMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Statamic\Migrator;

use Carbon\Carbon;
use Illuminate\Filesystem\Filesystem;
use Statamic\Fieldtypes\Date;
use Statamic\Migrator\Exceptions\EmptyValueException;
use Statamic\Support\Arr;
use Statamic\Support\Str;
Expand Down Expand Up @@ -207,6 +209,21 @@ protected function migrateField($handle, $value, $config = null)
return $value;
}

protected function migrateDateField($handle, $value, $config)
{
if (($originalTimezone = $this->getSetting('system.timezone', 'UTC')) !== 'UTC') {
$value = Carbon::parse($value, $originalTimezone)
->utc()
->format($config['format'] ?? Date::DEFAULT_DATETIME_FORMAT);

if (is_numeric($value)) {
$value = (int) $value;
}
}

return $value;
}

/**
* Migrate assets field.
*
Expand Down
27 changes: 4 additions & 23 deletions src/GlobalSetMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,8 @@ protected function migrateGlobalSetSchema()
->forget('fieldset')
->forget('id');

$meta = $this->set->only($metaKeys);
$data = $this->set->except($metaKeys);

if ($this->isMultisite()) {
$this->set = $meta;
$this->localizedSets = $this->migrateLocalizedSets($data);
} else {
$this->set = $meta->put('data', $this->migrateSetData($data));
}
$this->localizedSets = $this->migrateLocalizedSets($this->set->except($metaKeys));
$this->set = $this->set->only($metaKeys);

return $this;
}
Expand Down Expand Up @@ -125,24 +118,12 @@ protected function migrateSetData($data)
* @return $this
*/
protected function saveMigratedSet()
{
if ($this->isMultisite()) {
$this->saveLocalizedSets();
}

return $this->saveMigratedYaml($this->set);
}

/**
* Save migrated localized sets.
*
* @return $this
*/
protected function saveLocalizedSets()
{
collect($this->localizedSets)->each(function ($set, $locale) {
$this->saveMigratedYaml($set, base_path("content/globals/{$locale}/{$this->handle}.yaml"));
});

return $this->saveMigratedYaml($this->set);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/SettingsMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ protected function migrateCp()

Configurator::file($configFile = 'statamic/cp.php')
->set('start_page', $this->migrateStartPage($cp['start_page'] ?? false))
->set('date_format', $cp['date_format'] ?? false)
->merge('widgets', $cp['widgets'] ?? [])
->set('pagination_size', $cp['pagination_size'] ?? false)
->ifNoChanges($this->throwNoChangesException($configFile));
Expand Down Expand Up @@ -125,6 +124,7 @@ protected function migrateSystem()

Configurator::file($configFile = 'statamic/system.php')
->set('multisite', count($sites) > 1)
->set('display_timezone', $system['timezone'] ?? null)
->ifNoChanges($this->throwNoChangesException($configFile));

return $this;
Expand Down
90 changes: 90 additions & 0 deletions tests/ContentMigratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,96 @@ public function it_can_migrate_assets_fields_without_container_url()
$this->assertEquals($expected, $content);
}

/** @test */
public function it_can_migrate_date_field()
{
$content = $this
->setFields([
'date_field' => [
'type' => 'date',
],
'date_field_with_format' => [
'type' => 'date',
'format' => 'Y/m/d',
],
'date_field_with_time' => [
'type' => 'date',
'allow_time' => true,
],
'date_field_with_time_and_format' => [
'type' => 'date',
'allow_time' => true,
'format' => 'Y/m/d H:i',
],
])
->migrateContent([
'date_field' => '2018-01-01',
'date_field_with_format' => '2018/01/01',
'date_field_with_time' => '2018-01-01 12:00',
'date_field_with_time_and_format' => '2018/01/01 12:00',
]);

$expected = [
'date_field' => '2018-01-01',
'date_field_with_format' => '2018/01/01',
'date_field_with_time' => '2018-01-01 12:00',
'date_field_with_time_and_format' => '2018/01/01 12:00',
'blueprint' => 'speaker'
];

$this->assertEquals($expected, $content);

$this->files->delete($this->sitePath('settings/system.yaml'));
}

/** @test */
public function it_can_migrate_date_field_when_previous_timezone_was_not_utc()
{
// -5-hour offset
$this->files->put($this->sitePath('settings/system.yaml'), <<<EOT
timezone: 'America/New_York'
EOT
);

$content = $this
->setFields([
'date_field' => [
'type' => 'date',
],
'date_field_with_format' => [
'type' => 'date',
'format' => 'Y/m/d',
],
'date_field_with_time' => [
'type' => 'date',
'allow_time' => true,
],
'date_field_with_time_and_format' => [
'type' => 'date',
'allow_time' => true,
'format' => 'Y/m/d H:i',
],
])
->migrateContent([
'date_field' => '2018-01-01',
'date_field_with_format' => '2018/01/01',
'date_field_with_time' => '2018-01-01 12:00',
'date_field_with_time_and_format' => '2018/01/01 12:00',
]);

$expected = [
'date_field' => '2018-01-01 05:00',
'date_field_with_format' => '2018/01/01',
'date_field_with_time' => '2018-01-01 17:00',
'date_field_with_time_and_format' => '2018/01/01 17:00',
'blueprint' => 'speaker'
];

$this->assertEquals($expected, $content);

$this->files->delete($this->sitePath('settings/system.yaml'));
}

/** @test */
public function it_can_migrate_term_fields()
{
Expand Down
30 changes: 21 additions & 9 deletions tests/MigrateGlobalSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ protected function newPath()
return Path::tidy(base_path('content/globals/main.yaml'));
}

protected function variablesPath()
{
return Path::tidy(base_path('content/globals/default/main.yaml'));
}

protected function blueprintPath()
{
return Path::tidy(resource_path('blueprints/globals/main.yaml'));
Expand All @@ -33,23 +38,26 @@ protected function blueprintPath()
private function migrateGlobalSet($globalSet)
{
$this->assertFileNotExists($this->newPath());
$this->assertFileNotExists($this->variablesPath());

$this->files->put($this->originalPath(), YAML::dump($globalSet));

$this->artisan('statamic:migrate:global-set', ['handle' => 'main']);

$this->assertFileExists($this->newPath());
$this->assertFileExists($this->variablesPath());

return YAML::parse($this->files->get($this->newPath()));
return [YAML::parse($this->files->get($this->newPath())), YAML::parse($this->files->get($this->variablesPath()))];
}

/** @test */
public function it_can_migrate_a_global_set()
{
$this->assertFileNotExists($this->newPath());
$this->assertFileNotExists($this->variablesPath());
$this->assertFileNotExists($this->blueprintPath());

$set = $this->migrateGlobalSet([
[$set, $variables] = $this->migrateGlobalSet([
'id' => '547c5873-ce9a-4b92-b6b8-a9c785f92fb4',
'title' => 'Global',
'fieldset' => 'globals',
Expand All @@ -60,14 +68,16 @@ public function it_can_migrate_a_global_set()

$this->assertEquals($set, [
'title' => 'Global',
'data' => [
'site_title' => 'Frederick\'s Swap Shop',
'author' => 'Frederick Schwap',
'fav_colour' => 'red',
],
]);

$this->assertEquals($variables, [
'site_title' => 'Frederick\'s Swap Shop',
'author' => 'Frederick Schwap',
'fav_colour' => 'red',
]);

$this->assertFileExists($this->newPath());
$this->assertFileExists($this->variablesPath());
$this->assertFileExists($this->blueprintPath());
}

Expand All @@ -76,7 +86,7 @@ public function it_can_implicitly_migrate_globals_blueprint()
{
$this->assertFileNotExists($this->blueprintPath());

$set = $this->migrateGlobalSet([
$this->migrateGlobalSet([
'id' => '547c5873-ce9a-4b92-b6b8-a9c785f92fb4',
'title' => 'Global',
'site_title' => 'Frederick\'s Swap Shop',
Expand All @@ -93,15 +103,17 @@ public function it_migrates_without_fieldset_when_one_does_not_exist()
$this->files->delete(base_path('site/settings/fieldsets/globals.yaml'));

$this->assertFileNotExists($this->newPath());
$this->assertFileNotExists($this->variablesPath());
$this->assertFileNotExists($this->blueprintPath());

$set = $this->migrateGlobalSet([
$this->migrateGlobalSet([
'title' => 'Global',
'site_title' => 'Frederick\'s Swap Shop',
'author' => 'Frederick Schwap',
]);

$this->assertFileExists($this->newPath());
$this->assertFileExists($this->variablesPath());
$this->assertFileNotExists($this->blueprintPath());
}
}
27 changes: 21 additions & 6 deletions tests/MigrateSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ public function it_migrates_cp_settings()
EOT
);

$this->assertConfigFileContains('cp.php', <<<'EOT'
'date_format' => 'Y-m-d',
EOT
);

$this->assertConfigFileContains('cp.php', <<<'EOT'
'widgets' => [
'getting_started',
Expand Down Expand Up @@ -160,6 +155,11 @@ public function it_migrates_routes()
/** @test */
public function it_migrates_system_settings()
{
$this->files->put($this->sitePath('settings/system.yaml'), <<<'EOT'
timezone: 'America/New_York'
EOT
);

$this->artisan('statamic:migrate:settings', ['handle' => 'system']);

$this->assertSameWithNormalizedLineEndings(File::get(resource_path('sites.yaml')),
Expand All @@ -171,6 +171,11 @@ public function it_migrates_system_settings()

$this->assertConfigFileContains('system.php', <<<'EOT'
'multisite' => false,
EOT
);

$this->assertConfigFileContains('system.php', <<<'EOT'
'display_timezone' => 'America/New_York',
EOT
);
}
Expand Down Expand Up @@ -281,11 +286,21 @@ protected function assertConfigFileContains($file, $content)
{
$config = config_path("statamic/{$file}");

$beginning = <<<'EOT'
if ($file === 'cp.php') {
$beginning = <<<'EOT'
<?php

use Statamic\CP\Color;

return [
EOT;
} else {
$beginning = <<<'EOT'
<?php

return [
EOT;
}

$end = '];';

Expand Down