| 1 |
Copyright (C) 2003 David Schmitter, Dataflow Solutions GmbH <schmitt@dataflow.ch> |
|---|
| 2 |
|
|---|
| 3 |
Quotas |
|---|
| 4 |
****** |
|---|
| 5 |
|
|---|
| 6 |
Overview |
|---|
| 7 |
-------- |
|---|
| 8 |
With Midgard Quotas, you can define per-sitegroup restrictions on |
|---|
| 9 |
a) the number of records for each table |
|---|
| 10 |
b) the maximum content size in each table, where you can define which fields count as content |
|---|
| 11 |
c) the maximum size for attachments. |
|---|
| 12 |
d) the maximum content size for all objects of a sitegroup. |
|---|
| 13 |
If you try to create / update a record, and the quota for the table is reached, error MGD_ERR_QUOTA ("Quota reached") is triggered. |
|---|
| 14 |
The same happens if you open an attachment and the maximum attachment size is reached. |
|---|
| 15 |
|
|---|
| 16 |
Installation |
|---|
| 17 |
------------ |
|---|
| 18 |
./configure --with-quota |
|---|
| 19 |
Create the quota table using quota.sql in /data |
|---|
| 20 |
|
|---|
| 21 |
Configuration |
|---|
| 22 |
------------- |
|---|
| 23 |
New apache configuration directive: |
|---|
| 24 |
MidgardCheckQuota (On|Off) default: Off |
|---|
| 25 |
|
|---|
| 26 |
Class + function reference |
|---|
| 27 |
-------------------------- |
|---|
| 28 |
|
|---|
| 29 |
New object |
|---|
| 30 |
class Quota { |
|---|
| 31 |
var $id; |
|---|
| 32 |
var $sitegroup; // sitegroup |
|---|
| 33 |
var $tablename; // table or special name 'blobsdata' for filesystem blobs or special name 'wholesg' for all objects of the SG |
|---|
| 34 |
var $spacefields; // the fields that count as content for this table |
|---|
| 35 |
var $number; // max number of records |
|---|
| 36 |
var $space; // max length of content fields or max disk space for filesystem blobs (both in KB) |
|---|
| 37 |
var $eff_number; // effective number of objects for which this quota is defined |
|---|
| 38 |
var $eff_space; // effective size of objects for which this quota is defined |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
New functions: |
|---|
| 42 |
mgd_list_quotas(); |
|---|
| 43 |
mgd_get_quota([int id]); |
|---|
| 44 |
mgd_get_quota_by_tablename(string tablename); |
|---|
| 45 |
mgd_get_quota_info_by_tablename(string tablename, [int sitegroup]); |
|---|
| 46 |
mgd_create_quota(int sitegroup, string tablename, string spacefields, int number, int space); |
|---|
| 47 |
mgd_update_quota(int id, int sitegroup, string tablename, string spacefields, int number, int space); |
|---|
| 48 |
mgd_delete_quota(int id); |
|---|
| 49 |
|
|---|
| 50 |
Example |
|---|
| 51 |
------- |
|---|
| 52 |
/* as $midgard->root: */ |
|---|
| 53 |
|
|---|
| 54 |
/* The total size of all content fields of table page_i may not exceed 1000 KB for sitegroup $sg */ |
|---|
| 55 |
mgd_create_quota($sg, 'page_i', 'content', 0, 1000); |
|---|
| 56 |
|
|---|
| 57 |
/* The total size of all value fields of table pageelement_i may not exceed 1000 KB for sitegroup $sg */ |
|---|
| 58 |
mgd_create_quota($sg, 'pageelement_i', 'content', 0, 1000); |
|---|
| 59 |
|
|---|
| 60 |
/* The total size of all content & abstract fields of table article_i may not exceed 1000 KB for sitegroup $sg */ |
|---|
| 61 |
mgd_create_quota($sg, 'article_i', 'content,abstract', 0, 1000); |
|---|
| 62 |
|
|---|
| 63 |
/* The total size of all value fields of table element_i may not exceed 1000 KB for sitegroup $sg */ |
|---|
| 64 |
mgd_create_quota($sg, 'element_i', 'value', 0, 1000); |
|---|
| 65 |
|
|---|
| 66 |
/* The total size of all code fields of table element_i may not exceed 1000 KB for sitegroup $sg */ |
|---|
| 67 |
mgd_create_quota($sg, 'snippet_i', 'code', 0, 1000); |
|---|
| 68 |
|
|---|
| 69 |
/* The total size of all extra & pgpkey fields of table person may not exceed 1000 KB for sitegroup $sg */ |
|---|
| 70 |
mgd_create_quota($sg, 'person', 'extra,pgpkey', 0, 1000); |
|---|
| 71 |
|
|---|
| 72 |
/* The total size of all attachments may not exceed 10000 KB for sitegroup $sg */ |
|---|
| 73 |
mgd_create_quota($sg, 'blobsdata', '', 0, 10000); |
|---|
| 74 |
|
|---|
| 75 |
/* The total size of all table fields and blobs data defined above may not exceed 10000 KB for sitegroup $sg */ |
|---|
| 76 |
mgd_create_quota($sg, 'wholesg', '', 0, 12000); |
|---|
| 77 |
|
|---|
| 78 |
/* The total number of articles may not exceed 1000 for sitegroup $sg */ |
|---|
| 79 |
mgd_create_quota($sg, 'article', '', 1000, 0); |
|---|
| 80 |
|
|---|
| 81 |
/* ... */ |
|---|
| 82 |
/* as normal user: */ |
|---|
| 83 |
|
|---|
| 84 |
$qinfo = mgd_get_quota_info_by_tablename('blobsdata'); |
|---|
| 85 |
$qinfosg = mgd_get_quota_info_by_tablename('wholesg'); |
|---|
| 86 |
|
|---|
| 87 |
/* Test if file $filename could be written into an attachment according to quota rules */ |
|---|
| 88 |
if ($qinfo->eff_space + (filesize($filename) / 1024) >= $qinfo->space or $qinfosg->eff_space + (filesize($filename) / 1024) >= $qinfosg->space) { |
|---|
| 89 |
echo "File too big"; |
|---|
| 90 |
} |
|---|
| 91 |
|
|---|