Skip to content

Commit

Permalink
Merge pull request #42 from TheDragonCode/2.x
Browse files Browse the repository at this point in the history
Removed timestamp suffix when generating anonymous actions
  • Loading branch information
Andrey Helldar authored Feb 4, 2022
2 parents 28dcad9 + c826d7b commit f655f5d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,33 @@ If a git repository is found in the main folder, then the name of the current ac
```bash
php artisan make:migration:action

### Before Laravel 8.37
# 2022_01_28_184116_main_1643384476.php
# 2022_01_28_184117_main_1643384477.php
# 2022_01_28_184118_crm_2345_1643384478.php
# 2022_01_28_184119_crm_2345_1643384479.php

### Laravel 8.37 or higher
# 2022_01_28_184116_main.php
# 2022_01_28_184117_main.php
# 2022_01_28_184118_crm_2345.php
# 2022_01_28_184119_crm_2345.php
```

If the git repository is not found, then the default prefix will be used:

```bash
php artisan make:migration:action

### Before Laravel 8.37
# 2022_01_28_184116_auto_1643384476.php
# 2022_01_28_184117_auto_1643384477.php
# 2022_01_28_184118_auto_1643384478.php

### Laravel 8.37 or higher
# 2022_01_28_184116_auto.php
# 2022_01_28_184117_auto.php
# 2022_01_28_184118_auto.php
```

If you are using Laravel prior to version [8.37](https://github.com/laravel/framework/releases/tag/v8.37.0), then to ensure backward compatibility, if the current git repository
Expand Down
13 changes: 12 additions & 1 deletion src/Concerns/Argumentable.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
/** @mixin \Illuminate\Console\Command */
trait Argumentable
{
use Anonymous;

protected $auto_prefix = 'auto';

protected $branch_prefix = 'branch';
Expand All @@ -17,6 +19,15 @@ protected function argumentName(): string
return trim($name);
}

return $this->makeName();
}

protected function makeName(): string
{
if ($this->allowAnonymous()) {
return $this->getAutoPrefix();
}

return $this->getAutoPrefix() . '_' . time();
}

Expand All @@ -31,7 +42,7 @@ protected function getGitBranchName(): ?string

preg_match('/^\d.*$/', $name, $output);

if (! empty($output)) {
if (! empty($output) && $this->disallowAnonymous()) {
return $this->branch_prefix . '_' . $name;
}

Expand Down
4 changes: 3 additions & 1 deletion tests/Commands/MakeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public function testMakingFiles()

public function testAutoName()
{
$filename = date('Y_m_d_His') . '_auto_' . time() . '.php';
$filename = $this->allowAnonymous()
? date('Y_m_d_His') . '_auto.php'
: date('Y_m_d_His') . '_auto_' . time() . '.php';

$path = database_path('actions/' . $filename);

Expand Down

0 comments on commit f655f5d

Please sign in to comment.