Skip to content

Commit

Permalink
fix publish first config media then migration by dependent of config …
Browse files Browse the repository at this point in the history
…, fix create symlink exists
  • Loading branch information
waadmawlood authored Oct 22, 2023
1 parent 0b1d3e9 commit c9f843a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 22 deletions.
28 changes: 24 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,27 @@ To install
composer require waad/media
```

You can publish the `migration` and `config` with:
**first** :
publish the `config` with command:

```sh
php artisan vendor:publish --provider="Waad\Media\MediaServiceProvider"
php artisan vendor:publish --provider="Waad\Media\MediaServiceProvider" --tag="media-config"
```

configration from `config/media.php`
configration from `config/media.php` sure from `uuid`, `shortcut` in config media

⚠️ clear cache important, before publish migrations
```sh
php artisan optimize
```

----

**Second** :
publish the `migrations` with command:

```sh
php artisan vendor:publish --provider="Waad\Media\MediaServiceProvider" --tag="media-migrations"
```

#### You can migration

Expand All @@ -54,6 +66,14 @@ php artisan migrate

#### You can make a link shortcut by disk from `config.media.shortcut` array of disks

```js
'shortcut' => [
'public' => 'media',
// disk => shortcut name
],
```


```sh
php artisan media:link
```
Expand Down
10 changes: 8 additions & 2 deletions src/Commands/MediaLinkCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,18 @@ public function handle()
{
$links = $this->links();

foreach($links as $value){
foreach ($links as $value) {
$link = $value['path'];
$shortcut = $value['shortcut'];

if (file_exists(public_path($shortcut)) && !$this->isRemovableSymlink($link, $this->option('force'))) {
$this->error("The [{$shortcut}] link already exists.");
if ($this->option('force')) {
unlink(public_path($shortcut));
$this->info("The existing [{$shortcut}] link has been removed.");
} else {
$this->error("The [{$shortcut}] link already exists. Use the --force option to recreate it.");
continue;
}
}

if (is_link(public_path($shortcut))) {
Expand Down
33 changes: 17 additions & 16 deletions src/MediaServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,32 @@ class MediaServiceProvider extends ServiceProvider
*/
public function boot()
{
// $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'media');
}

/**
* Register the application services.
*/
public function register()
{
if ($this->app->runningInConsole()) {
$this->commands([
MediaLinkCommand::class,
MediaPrune::class,
]);
if (!$this->app->runningInConsole()) {
return;
}

$this->publishes([
__DIR__ . '/../config/config.php' => config_path('media.php'),
], 'config');
], 'media-config');

$is_uuid = config('media.uuid', false);
$path = $is_uuid ? '/../database/migrations/create_media_uuid_table.php.stub' : '/../database/migrations/create_media_table.php.stub';
if (!class_exists('CreateMediaTable')) {
if (empty(glob(database_path('migrations/*_create_media_table.php')))) {
$this->publishes([
__DIR__ . $path => database_path('migrations/' . date('Y_m_d_His', time()) . '_create_media_table.php'),
], 'migrations');
], 'media-migrations');
}
}

/**
* Register the application services.
*/
public function register()
{
$this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'media');
$this->commands([
MediaLinkCommand::class,
MediaPrune::class,
]);
}
}

0 comments on commit c9f843a

Please sign in to comment.