Skip to content
Open
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
21 changes: 3 additions & 18 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,15 @@ jobs:

strategy:
matrix:
php: [8.1, 8.2, 8.3, 8.4]
laravel: [10.*, 11.*, 12.*]
php: [8.3, 8.4]
laravel: [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.*
stability: prefer-stable
- os: windows-latest
php: 8.4
laravel: 11.*
stability: prefer-stable
exclude:
- php: 8.1
laravel: 11.*
- php: 8.1
laravel: 12.*
- php: 8.4
laravel: 10.*
stability: prefer-stable

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,10 +7,10 @@
"mustangostang/spyc": "dev-master#dfd9aadc1f5224065d55b42b712c7e99a50a3f4d"
},
"require-dev": {
"statamic/cms": "^5.41",
"statamic/cms": "^v6.0.0-alpha.15",
"mockery/mockery": "^1.4.4",
"orchestra/testbench": "^8.28 || ^9.6.1 || ^10.0",
"phpunit/phpunit": "^10.5.35 || ^11.0"
"orchestra/testbench": "^10.0",
"phpunit/phpunit": "^11.0"
},
"autoload": {
"psr-4": {
Expand Down
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());
}
}
Loading