Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

File upload quotas


Go to End


3 Posts   2024 Views

Avatar
Motoma

Community Member, 7 Posts

16 December 2009 at 4:00am

Edited: 16/12/2009 4:02am

Hello all.

I'm looking to implement quotas that are given to individual users at the group level. I'm hoping someone would have some insight into the intricacies of this task.

My initial thoughts:

Create a DataObjectDecorator to extend the Group class
- Add a UserQuota field
- Add a userQuota() method

Create a DataObjectDecorator to extend the File class
- Add a CreatedBy field

Create a DataObjectDecorator to extend the Member class
-Add a withinQuota() method

My questions:
Will an Extension to the File class be inherited by other classes? Namely the Image class?
How can I set the CreatedBy field to the current user when files are uploaded?
Additionally, file uploads will need to check the member's withinQuota() method, how can this be accomplished?
Inside the withinQuota(), I will need to pull all Files owned by that user, how should this be done?

Thank you in advance for any insight you can provide.

Avatar
Willr

Forum Moderator, 5523 Posts

16 December 2009 at 9:22am

Edited: 16/12/2009 9:22am

Will an Extension to the File class be inherited by other classes? Namely the Image class?

Yes I believe it should be as long as no methods / field names clash with ones in Image.

How can I set the CreatedBy field to the current user when files are uploaded?

Files already have a OwnerID field which stores the value of who uploaded the file. I'm guessing that is the same as want you want to do with CreatedBy so you probably don't need to add that field

Additionally, file uploads will need to check the member's withinQuota() method, how can this be accomplished?

You can set limits on a per filefield basis by setting setAllowedMaxFileSize(). Not completely sure how to set it globally, there must be a way to do so but I can't seem to find it. Using setAllowedMaxFileSize() however you could set it like

$field->setAllowedMaxFileSize($member->withinQuota);

Inside the withinQuota(), I will need to pull all Files owned by that user, how should this be done?

Well because File has a OwnerID you can run a simple DataObject::get('File', "OwnerID = '$this->ID'"); which will return a set of files for that owner.

Avatar
Motoma

Community Member, 7 Posts

16 December 2009 at 9:24am

Thank you for the excellent response Willr. I will get to work on this right now.