Skip to content

Commit 2260a0e

Browse files
committed
fix pubilsh migration
1 parent 96d6900 commit 2260a0e

File tree

2 files changed

+36
-39
lines changed

2 files changed

+36
-39
lines changed

src/Console/Commands/InstallPackageCommand.php

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Console\Command;
66
use Illuminate\Support\Facades\File;
7+
use Illuminate\Support\Facades\Artisan;
78

89
class InstallPackageCommand extends Command
910
{
@@ -29,48 +30,55 @@ public function handle()
2930
$this->info("config published");
3031
}
3132

33+
if (!empty(File::glob(database_path('migrations\*_create_attachmentables_tables.php')))) {
3234

33-
// //migration
34-
// if (File::exists(database_path("migrations/"))) {
35-
// $confirm = $this->confirm("migration file already exist. Do you want to overwrite?");
36-
// if ($confirm) {
37-
// $this->publishMigration();
38-
// $this->info("migration overwrite finished");
39-
// } else {
40-
// $this->info("skipped migration publish");
41-
// }
42-
// } else {
43-
// $this->publishMigration();
44-
// $this->info("migration published");
45-
// }
46-
47-
$this->publishMigration();
48-
49-
// $this->call('migrate');
50-
51-
35+
$list = File::glob(database_path('migrations\*_create_attachmentables_tables.php'));
36+
collect($list)->each(function ($item) {
37+
File::delete($item);
38+
});
5239

40+
$this->publishMigration();
41+
} else {
42+
$this->publishMigration();
43+
}
5344

5445
$this->info("Attachmentable Successfully Installed.\n");
5546
$this->info("\t\tStar me on Github");
5647
}
5748

58-
private function publishConfig()
49+
private function publishMigration()
5950
{
6051
$this->call('vendor:publish', [
6152
'--provider' => "Laravelir\Attachmentable\Providers\AttachmentableServiceProvider",
62-
'--tag' => 'attachmentable-config',
53+
'--tag' => 'attachmentable-migrations',
6354
'--force' => true
6455
]);
6556
}
6657

67-
68-
private function publishMigration()
58+
private function publishConfig()
6959
{
7060
$this->call('vendor:publish', [
7161
'--provider' => "Laravelir\Attachmentable\Providers\AttachmentableServiceProvider",
72-
'--tag' => 'attachmentable-migrations',
62+
'--tag' => 'attachmentable-config',
7363
'--force' => true
7464
]);
7565
}
66+
67+
// protected function publishMigrations()
68+
// {
69+
// if (empty(File::glob(database_path('migrations/*_create_attachmentables_tables.php')))) {
70+
71+
// $this->publishes([
72+
// __DIR__ . '/../../database/migrations/create_attachmentables_table.stub.php' => database_path() . "/migrations//" . date('Y_m_d_His', time()) . "_create_attachmentables_tables.php",
73+
// ], 'attachmentable-migrations');
74+
// } else {
75+
// $list = File::glob(database_path('migrations\*_create_attachmentables_tables.php'));
76+
// collect($list)->each(function ($item) {
77+
// File::delete($item);
78+
// dd("delete");
79+
// });
80+
81+
// Artisan::call('php artisan vendor:publish --provider=Laravelir\\Attachmentable\\Providers\\AttachmentableServiceProvider --tag=attachmentable-migrations --force');
82+
// }
83+
// }
7684
}

src/Providers/AttachmentableServiceProvider.php

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Laravelir\Attachmentable\Providers;
44

5+
use Illuminate\Support\Facades\Artisan;
56
use Illuminate\Support\Facades\File;
67
use Illuminate\Support\ServiceProvider;
78
use Laravelir\Attachmentable\Facades\AttachmentableFacade;
@@ -56,20 +57,8 @@ public function publishConfig()
5657

5758
protected function publishMigrations()
5859
{
59-
if (empty(File::glob(database_path('migrations/*_create_attachmentables_tables.php')))) {
60-
$timestamp = date('Y_m_d_His', time());
61-
62-
$this->publishes([
63-
__DIR__ . '/../../database/migrations/create_attachmentables_table.stub.php' => database_path() . "/migrations/{$timestamp}_create_attachmentables_tables.php",
64-
], 'attachmentable-migrations');
65-
66-
} else {
67-
$list = File::glob(database_path('migrations\*_create_attachmentables_tables.php'));
68-
collect($list)->each(function ($item) {
69-
File::delete($item);
70-
});
71-
72-
$this->publishMigrations();
73-
}
60+
$this->publishes([
61+
__DIR__ . '/../../database/migrations/create_attachmentables_table.stub.php' => database_path() . "/migrations//" . date('Y_m_d_His', time()) . "_create_attachmentables_tables.php",
62+
], 'attachmentable-migrations');
7463
}
7564
}

0 commit comments

Comments
 (0)