-
-
Notifications
You must be signed in to change notification settings - Fork 55
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
Use league/flysystem to abstract attachments #254
Conversation
mount manager: http://flysystem.thephpleague.com/mount-manager/ could came useful |
may even decide to use caching: http://flysystem.thephpleague.com/caching/ |
so the idea is to abstract
some questions arise:
@balsdorf WDYT? |
probably should just store attachments as
|
searched github for some existing adapters, mysql, pdo flysystem
looks to me phlib/flysystem-pdo is a win |
phlib/flysystem-pdo changes past last release include drop php 5.5 support we can perhaps also up min requirement to php 5.6, which leaves only 5.6, as 7.0 is not supported for eventum :) it also includes change license to LGPL-3, that's still ok with eventum right? |
phlib/flysystem-pdo seems usable. to simplify integration, should use it's provided table structure. to use for multiple purposes (besides attachments), we can play with "table_prefix". in this example i used default "flysystem", so that could be "attachment" for this use case.
and must use |
72b9c4c
to
b788f74
Compare
I'm good with upping requirement to php 5.6. License compatibility is a good question. Eventum is licenses as "GNU General Public License, version 2 or later (GPL-2+)". GPL2 is incompatible with LGPL3, but since it says "or later" you can deem it GPL3 which then means it is compatible with LGPL3. https://www.gnu.org/licenses/gpl-faq.html#AllCompatibility |
The issue with switching to using this adapter (which looks nice) is that all our current attachments in the DB will have to be migrated to the new table, which could be a huge job. |
For the filesystem, I like subdirectories and I'd use this:
EDIT: Removed $prj_id and info from path after doing some prototyping. $iss_id is redundant as well, but will help keep things organized. |
So I created a "LegacyAdapter" to read from our current, attachment stored files. From messing around with this, I think we should use MountManager to support multiple adapters at the same time. For the most part, I think we would just use `legacy://' and either 'pdo://' or 'local://' but the setup file could be used to be specify additional adapters. We would still use issue_attachment and issue_attachment_file with the addition of a iaf_flysystem_path field. We would continue to store meta data ourselves since we need to easily display it, but reading / writing the actual contents of the files would all be handled by flysystem. Old files would be read from We could also provide a migrate command to move files from legacy to the default adapter, but for users with large databases this could be quite painful. Thoughts? |
b788f74
to
9c8bb88
Compare
@balsdorf rebased against master to resolve conflicts. go ahead and push your changes out. your plan is probably fine. |
So I've just pushed my work on this. At first I tried to make minimal changes but wasn't happy with how messy it was so I pretty much redid all of the attachment system. Here are the key points. New class New class New class New class Adapter for old files in Since I was re-writing this I also added the ability to specify a minimum role for Currently, by default attachments are still stored in the database, just with the new PDO Adapter. I believe we should make this configurable in the admin and during installation. For the local adapter I used the subpath "storage/" but I'm open to better suggestions. As far as paths go, when files are first uploaded (before they are associated with an issue) the path is "unassociated/$iaf_id-$filename". When they are associated they are moved to "$issue_id/$iaf_id-$filename". TODO:
|
47cab69
to
020b21f
Compare
match what phlib/flysystem-pdo intended
Existing attachments are kept in the same table and accessed via the EventumLegacyAdapter but going forward only meta data will be stored in those tables. New attachments will be stored in either attachment_* table, the local filesystem or another 3rd party adapter.
I know it doesn't make sense, but getMimeType() and getTimeStamp() are supposed to return the whole array of meta data. At last that is what the LocalAdapter does. The migrate script uses the mount manager to move the file. Internally, that code copies the file and once the copy is confirmed deletes the old file. The only risk would be if for some reason the path in eventum cannot be updated. I do believe this is a small risk though and would only impact one file before erroring out. Considering this is an advanced script I think that is an acceptable risk. However, I did find one small bug I will fix and will also add some warnings to it and a note about OPTIMIZE TABLE. |
Thanks for those fixes BTW. I'll update the references to 5.6 in the code and update the wiki |
some nitpicking i considered: perhaps use touch to set filesystem file dates from database. could be useful for some cleanups or analyze tools that use file timestamps. as i understood flysystem stores such meta in it's database, but be useful to duplicate this on actual files as well. applies to migrate script mostly, but may have effect when move is used elsewhere. |
note to self: alter table issue_attachment add
`iat_status` enum('internal','public') NOT NULL DEFAULT 'public'; EDIT: added rollback support (
|
this method should not be used in production as data is already lost
@balsdorf i also wish you do the last 3.2 release, to see the validity of docs and maybe some ideas/issues you encounter! :) |
* Warning about data loss * Note about OPTIMIZE TABLE * Set filesystem timestamp to match value in database * Actually delete the file contents from issue_attachment_file when migrating from legacy adapter.
Good idea on touching the file, I've incorporated that into my changes to migration script. |
i probably want to relocate like for example: lib/eventum/class.setup.php:246 |
I was thinking about using a dynamic value from setup, but I didn't want
someone to change it and think all the files would be moved automatically.
However, I'll add that as it is better then you having to patch a bunch of
files.
…On Tue, Jul 25, 2017 at 12:54 AM Elan Ruusamäe ***@***.***> wrote:
i probably want to relocate APP_PATH . '/var/storage/' ->
/var/lib/eventum/storage when i deploy this using rpm package. should we
setup dynamic value for this using Setup or I should just patch every match
for direct use in codebase?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#254 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAHzdfzO1doLwot_xt7xofDZw5Slidrgks5sRYMygaJpZM4NQtTC>
.
|
When going to implement a path in setup for you I realized that no changes were needed, you just need to specify your own adapter:
This will override the "default" local file location. The only item you would have to patch is in the migration script, and only if you want to "touch" the files |
yay for merge! don't forget to update docs for 5.6 min requirement. thanks! wish me good luck rebasing #263 (it contained also changes (cleanups)) to attachment area :( |
@balsdorf found some error, the |
don't need schema files at runtime: phlib/flysystem-pdo/schema refs #254
no function changes with 0.0.3 phlib/flysystem-pdo@0.0.3...1.0.0 refs #254
easier to customize if need to change it refs #254
Move attachments out of the database #251
uses league/flysystem, requires php 5.5.9+
For upgrading from 3.2.3 -> 3.3.0 there should be no additional disk space required. The upgrade process just adds the new tables and columns but leaves existing attachments in the current table. New attachments will be inserted into the new table but unless you run migrate_storage_adapter.php it won't move anything.