[5.7] Command to create custom filesystem links#26194
[5.7] Command to create custom filesystem links#26194browner12 wants to merge 3 commits intolaravel:5.7from browner12:links
Conversation
this command will generate OS links in the filesystem, based on a simple configuration array.
|
Could you also update the documentation? |
|
once it gets accepted. |
| if ($links = $this->laravel['config']['filesystems.links']) { | ||
| foreach ($links as $link => $target) { | ||
| if (file_exists($link)) { | ||
| $this->error("The [$link] directory already exists."); |
There was a problem hiding this comment.
This could be confusing, if the location is not a directory. Perhaps do an is_file check to provide a more useful error message? That is, to tell the user if there is a file or a directory already there.
There was a problem hiding this comment.
Sorry, I'm a little confused. This is checking for the existence of the link, not the target. Would something like "The [$link] link already exists." make more sense?
|
Eh, I think this sounds more like a package. |
|
Sorry, but I would have to disagree with this suggestion. We're taking an existing framework functionality (creating links) and making it user customizable, rather than only working with the one pre-defined link decided on by the framework. This is very similar to what we've done other places in the FW where we've taken a manual part of deployment and tuned it into code, so we can consistently and automatically deploy it. For example, rather that SSHing into a server and updating CRON entries, we turned it into code. Rather than logging into MySQL and creating tables and fields, we write migrations. This is exactly the same. Rather than SSHing into the server and creating the links, or using something like Envoyer to create the links in a manual and inconsistent manner, we have the links in code and add the command to our deploy process. This is along the lines of infrastructure as code, which I think is a great thing because it makes things consistent and automated. |
Currently we have the ability to generate a filesystem link from
/public/storageto/storage/app/publicusing thestorage:linkartisan command. AFAIK, any other links would need to be created with a manual process, or a custom script.This PR gives the programmer the ability to define all the links they would like created in their application programmatically. Links and their targets are defined in the
config/filesystems.phpfile.These links will be generated using the new
links:generatecommand, which the programmer can make a part of their deployment process.This change is better for the user because it gives them full control over the generation of links, rather than being stuck with only the default
public_path('storage') => storage_path('app/public'). Also, for better or worse, the user can opt to use relative links over absolute links if they so choose ('public/storage' => 'storage/app/public').Originally I was going to adapt the
StorageLinkCommandfor these changes, but I felt the naming would not appropriately reflect what it now does, so I opted for a completely new command. Also, this allows us to add it to 5.7 instead of 5.8, because we will not affect current users. My intention is theStorageLinkCommandwill be removed in 5.8 in favor of this.Obviously open to changing any naming.
If this PR is accepted, I would like to go back and add an option to force the deletion and recreation of the link, in case an existing link is updated to point to a new target. Something like: