Skip to content

Commit 2694cd2

Browse files
authored
Cleanup installation (#35)
1 parent f4d4159 commit 2694cd2

File tree

5 files changed

+61
-16
lines changed

5 files changed

+61
-16
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ composer require statamic/eloquent-driver
1414
Publish the config file:
1515

1616
```
17-
php artisan vendor:publish --provider="Statamic\Eloquent\ServiceProvider"
17+
php artisan vendor:publish --tag="statamic-eloquent-config"
1818
```
1919

2020
Since Statamic uses UUIDs within content files by default, we provide two solutions depending on whether you need to use existing content.
@@ -26,15 +26,15 @@ If you're starting from scratch, we can use traditional incrementing integers fo
2626

2727
- Delete `content/collections/pages/home.md`
2828
- Change the structure `tree` in `content/collections/pages.yaml` to `{}`.
29-
- Copy the `create_entries_table` migration into `database/migrations`.
29+
- Run `php artisan vendor:publish --tag="statamic-eloquent-entries-table"`.
3030
- Run `php artisan migrate`.
3131

3232
### Starting from an existing site (using UUIDs)
3333

3434
If you're planning to use existing content, we can use the existing UUIDs. This will prevent you from needing to update any data or relationships.
3535

36-
- In the `config/statamic-eloquent-driver.php` file, change `model` to `UuidEntryModel`.
37-
- Copy the `create_entries_table_with_strings` migration into `database/migrations`.
36+
- In the `config/statamic/eloquent-driver.php` file, change `model` to `UuidEntryModel`.
37+
- Run `php artisan vendor:publish --tag="statamic-eloquent-entries-table-with-string-ids"`.
3838
- Run `php artisan migrate`.
3939
- Import entries into database with `php please eloquent:import-entries`.
4040

database/migrations/2020_01_01_000000_create_entries_table_with_strings.php renamed to database/migrations/create_entries_table_with_string_ids.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use Illuminate\Database\Schema\Blueprint;
55
use Illuminate\Support\Facades\Schema;
66

7-
class CreateEntriesTableWithStrings extends Migration
7+
class CreateEntriesTableWithStringIds extends Migration
88
{
99
/**
1010
* Run the migrations.

src/ServiceProvider.php

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,36 @@ class ServiceProvider extends AddonServiceProvider
1616
{
1717
protected $config = false;
1818

19+
protected $updateScripts = [
20+
\Statamic\Eloquent\Updates\MoveConfig::class,
21+
];
22+
1923
public function boot()
2024
{
2125
parent::boot();
2226

23-
$this->mergeConfigFrom($config = __DIR__.'/../config/eloquent-driver.php', 'statamic-eloquent-driver');
24-
25-
if ($this->app->runningInConsole()) {
26-
$this->publishes([$config => config_path('statamic-eloquent-driver.php')]);
27+
$this->mergeConfigFrom($config = __DIR__.'/../config/eloquent-driver.php', 'statamic.eloquent-driver');
2728

28-
$this->commands([ImportEntries::class]);
29+
if (! $this->app->runningInConsole()) {
30+
return;
2931
}
30-
}
3132

32-
public function register()
33-
{
34-
$this->registerEntries();
33+
$this->publishes([
34+
$config => config_path('statamic/eloquent-driver.php'),
35+
], 'statamic-eloquent-config');
36+
37+
$this->publishes([
38+
__DIR__.'/../database/migrations/create_entries_table.php' => $this->migrationsPath('create_entries_table'),
39+
], 'statamic-eloquent-entries-table');
40+
41+
$this->publishes([
42+
__DIR__.'/../database/migrations/create_entries_table_with_string_ids.php' => $this->migrationsPath('create_entries_table_with_string_ids'),
43+
], 'statamic-eloquent-entries-table-with-string-ids');
44+
45+
$this->commands([ImportEntries::class]);
3546
}
3647

37-
protected function registerEntries()
48+
public function register()
3849
{
3950
Statamic::repository(EntryRepositoryContract::class, EntryRepository::class);
4051
Statamic::repository(CollectionRepositoryContract::class, CollectionRepository::class);
@@ -46,7 +57,14 @@ protected function registerEntries()
4657
});
4758

4859
$this->app->bind('statamic.eloquent.entries.model', function () {
49-
return config('statamic-eloquent-driver.entries.model');
60+
return config('statamic.eloquent-driver.entries.model');
5061
});
5162
}
63+
64+
protected function migrationsPath($filename)
65+
{
66+
$date = date('Y_m_d_His');
67+
68+
return database_path("migrations/{$date}_{$filename}.php");
69+
}
5270
}

src/Updates/MoveConfig.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Statamic\Eloquent\Updates;
4+
5+
use Statamic\UpdateScripts\UpdateScript;
6+
7+
class MoveConfig extends UpdateScript
8+
{
9+
public function shouldUpdate($newVersion, $oldVersion)
10+
{
11+
return $this->isUpdatingTo('0.2.0');
12+
}
13+
14+
public function update()
15+
{
16+
$oldPath = config_path('statamic-eloquent-driver.php');
17+
$newPath = config_path('statamic/eloquent-driver.php');
18+
19+
if ($this->files->exists($newPath) || ! $this->files->exists($oldPath)) {
20+
return;
21+
}
22+
23+
$this->files->move($oldPath, $newPath);
24+
25+
$this->console()->info('Eloquent driver config successfully moved to [config/statamic/eloquent-driver.php]!');
26+
}
27+
}

0 commit comments

Comments
 (0)