Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check laravel version before symlink storage #1246

Conversation

lucasmezencio
Copy link
Contributor

Since Laravel 5.2 doesn't have artisan storage:link command, we can't call on versions below 5.3.

Q A
Bug fix? No
New feature? Yes
BC breaks? No
Deprecations? No
Fixed tickets N/A

Do not forget to add notes about your changes to CHANGELOG.md

Since Laravel 5.2 does not have `artisan storage:link` command, we can't call it.
@@ -105,7 +105,20 @@

desc('Execute artisan storage:link');
task('artisan:storage:link', function () {
run('{{bin/php}} {{release_path}}/artisan storage:link');
if (get('laravel_version') > 5.2) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

});

desc('Get Laravel version');
task('artisan:version', function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better define a as callback:

set('laravel_version', function () {
    ...
});

@lucasmezencio
Copy link
Contributor Author

@antonmedv done, man. :)

CHANGELOG.md Outdated
@@ -5,6 +5,8 @@

### Fixed
- Fixed upload / download with optional rsync ssh options [#1227]
- Fixed storage link error when deploying Laravel < 5.3.
- Helps [#1153]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is helps?) Add link also in bottom of document.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@antonmedv this PR helps that issue. Sure, I will do that.


$version = $matches[1][0] ?? 5.4;

return (float) $version;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version_compare expects a string, no need to cast to float. Can only cause rounding errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@barryvdh maybe I can change the regex to return the right version, but I did this because 5.2.13 > 5.2, so we can get a false positive. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the docs on http://php.net/manual/en/function.version-compare.php
That is specifically created to handle those situations.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See https://3v4l.org/a0jb5 for examples

set('laravel_version', function () {
$result = run('{{bin/php}} {{release_path}}/artisan --version');

preg_match_all('/version\ (.+?)$/', $result, $matches);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does 'version' come from? My result is Laravel Framework 5.4.12

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@barryvdh hmmm. Make sense! In Laravel 5.2, --version param come with 'version' string. I will change it. Thanks.

Copy link
Contributor

@barryvdh barryvdh May 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Laravel 4: Laravel Framework version 4.2.22
Laravel 5.1: Laravel Framework version 5.1.35 (LTS)
Laravel 5.2: Laravel Framework version 5.2.45
Laravel 5.3: Laravel Framework version 5.3.30
Laravel 5.4: Laravel Framework 5.4.22
Lumen: Laravel Framework version Lumen (5.1.7) (Laravel Components 5.1.*)

Something like this? ([0-9.]+)
http://regexr.com/3g2ep

@antonmedv
Copy link
Member

And please rebase.

@@ -105,7 +115,9 @@

desc('Execute artisan storage:link');
task('artisan:storage:link', function () {
run('{{bin/php}} {{release_path}}/artisan storage:link');
if (version_compare(get('laravel_version'), 5.2, '>')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And as you say in the docs, you want to check if the version is >= 5.3 or NOT < 5.3

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@barryvdh sure sure! You are right! I will do the changes. Thanks, man!

@lucasmezencio
Copy link
Contributor Author

@antonmedv @barryvdh can you check please? :)

@antonmedv antonmedv merged commit 120dae4 into deployphp:master May 31, 2017
@antonmedv
Copy link
Member

@lucasmezencio nice work!

set('laravel_version', function () {
$result = run('{{bin/php}} {{release_path}}/artisan --version');

preg_match_all('/([0-9\.])$/', $result, $matches);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong, should be '/([0-9.]+)/'. You want to match ALL numbers/dots, not just 1. And it doesn't have to match the end of string.

@lucasmezencio lucasmezencio deleted the check-laravel-version-before-symlink-storage branch June 2, 2017 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants