Open Source Content Management System

Quota in Midgard

  1. Installation
  2. Configuration
  3. Initialization
  4. Midgard Quota API functions
    1. Undocumented and depreciated functions
    2. MidgardQuota object
    3. Example

With Midgard Quota, you can define per-sitegroup restrictions on

  • the number of records for each table
  • the maximum content size in each table, where you can define which fields count as content
  • the maximum size for attachments.
  • the maximum content size for all objects of a sitegroup.

If you try to create / update a record, and the quota for the table is reached, error MGD_ERR_QUOTA (Quota reached) is triggered.
The same happens if you open an attachment and the maximum attachment size is reached.

Installation

./configure --with-quota

Create the quota table using quota.sql in /data.

As of Midgard 1.7, the Quota features are set up automatically. It is also good idea to make database update using datagard with every new Midgard release installed.

Configuration

Apache configuration directive:

MidgardCheckQuota (On|Off) default: Off

Quota limits will be checked for every object created or updated with VirtualHost which uses this directive set to On. Alternative option is mgd_check_quota function which may be used per request without any need to reload httpd server when configuration should be changed and quota limits check shouldn't be defined globally.

Initialization

<?php

$sgid = 1234;

$q = new midgard_quota();
$q->sg = $sgid;  /* Required for legacy quota */
$q->typename = ""; /* empty name is set for all types */
$q->tablename = "wholesg"; /* required for legacy quota */
$q->sgsizelimit = 1000; /* quota limit in bytes */
$q->space = 1000;  /* quota limits in bytes for legacy quota */
$q->spacefields = ""; /* deprecated but required by legacy quota */
$q->number = 0;  /* legacy quota */

/* Midgard 1.8 */
/* $q->sitegroup = $sgid;*/

$q->create();

/* Midgard 1.7 */ 

$q->sitegroup = $sgid;
$q->update();

?>

Midgard Quota API functions

Undocumented and depreciated functions

  • mgd_get_quota_by_tablename (string tablename)
  • mgd_get_quota_info_by_tablename (string tablename, int sitegroup)

MidgardQuota object

 class Quota
 {  
      var $id;  
      var $sitegroup; // sitegroup   
      var $tablename; // table or special name 'blobsdata' for           
                      // filesystem blobs or special name  
                      // 'wholesg' for all objects of the SG  
      var $spacefields; // the fields that count as content 
                        // for this table  
      var $number; // max number of records  
      var $space; // max length of content fields or max disk 
                  //space for filesystem blobs (both in KB)  
      var $eff_number; // effective number of objects for 
                       //which this quota is defined  
      var $eff_space; // effective size of objects for which 
                      // this quota is defined  
 }

Example

 /* as $midgard->root: */  

 /* The total size of all content fields of table page_i may      not exceed 1000 KB for sitegroup $sg */  
 mgd_create_quota($sg, 'page_i', 'content', 0, 1000);   

 /* The total size of all value fields of table pageelement_i may not exceed 1000 KB for sitegroup $sg */  
 mgd_create_quota($sg, 'pageelement_i', 'content', 0, 1000);  

 /* The total size of all content & abstract fields of table article_i may not exceed 1000 KB for sitegroup $sg */  
 mgd_create_quota($sg, 'article_i', 'content,abstract', 0, 1000);  

 /* The total size of all value fields of table element_i may not exceed 1000 KB for sitegroup $sg */  
 mgd_create_quota($sg, 'element_i', 'value', 0, 1000);  

 /* The total size of all code fields of table element_i may not exceed 1000 KB for sitegroup $sg */  
 mgd_create_quota($sg, 'snippet_i', 'code', 0, 1000);  

 /* The total size of all extra & pgpkey fields of table person may not exceed 1000 KB for sitegroup $sg */  
 mgd_create_quota($sg, 'person', 'extra,pgpkey', 0, 1000);   

 /* The total size of all attachments may not exceed 10000 KB for sitegroup $sg */  
 mgd_create_quota($sg, 'blobsdata', '', 0, 10000);  

 /* The total size of all table fields and blobs data defined above may not exceed 10000 KB for sitegroup $sg */  
 mgd_create_quota($sg, 'wholesg', '', 0, 12000);  

 /* The total number of articles may not exceed 1000 for sitegroup $sg */  
 mgd_create_quota($sg, 'article', '', 1000, 0);  

 /* ... */  
 /* as normal user: */  

 $qinfo = mgd_get_quota_info_by_tablename('blobsdata');  
 $qinfosg = mgd_get_quota_info_by_tablename('wholesg');  

 /* Test if file $filename could be written into an attachment      according to quota rules */  
 if ($qinfo->eff_space + (filesize($filename) / 1024) >=  $qinfo->space or $qinfosg->eff_space + (filesize($filename) / 1024) >= $qinfosg->space) {   
      echo "File too big";  
 }
Designed by Nemein, hosted by Anykey