Piotras' blog: Archive

2005-11-01 - 2005-11-30

mgd_check_quota

Posted on 2005-11-16 15:27:26 UTC.

Warm up, new Midgard release is already planned.

Stable Midgard branch now includes improved quota support. MgdSchema technology used with quota made this feature faster and more precise.

How to start:

Follow old Midgard API function to create quota limits.

<?php
$sg = 1;
$tablename = "wholesg";
$spacefields = ""; /* define which content fields should be limited */
$number = 0; /* we set no limits for sitegroup's records , so set different number if you want to limit sg records usage */
$space = 50000; /* ( value as KB ) we set 50MB quota limit */

/* be logged in as SG0 admin */
mgd_create_quota (sitegroup, tablename, spacefields, number, space);

?>


Initialize limits check.

You may define quota check per vhost using midgard-apache directive.

MidgardCheckQuota On

or using midgard-php API function

<?php mgd_check_quota(); ?>

This function may be used everywhere in a code. In code-global, code-init or even in page or style element. Using this function you may check quota limits only in particular requests.

What happens next?

Nothing unusual ;).
Midgard returns MGD_ERR_QUOTA ( "Quota reached" ) error when you want to create new midgard object ( legacy or MgdSchema one ) and quota limit is reached.

Any time you may check quota usage ( whole sitegroup ) using new API function.

<?
/* You must be logged in as SG0 admin */
$size = mgd_get_sitegroup_size(int $sg);
print $size; /* Notice that value is returned in bytes */
?>



Midgard attachments

Posted on 2005-11-23 13:04:32 UTC.

I have just read Arttu's blog about attachments and images.
And I must say I am always a bit confused when I see how  attachments can and could be served.

There is well known way of serving images from MidCOM or  Aegir.

  • /attachment/[sitegroup GUID]/[attachment GUID]/attachment_name.ext to
  • /midcom-serveattachmentguid-[attachment GUID]/attachment_name.ext
The first one is inherited from old Nadmin Studio designed for Midgard 1.4.

Every time I see that kind of way to serve attachments I ask  myself : "how it is easy and fast to serve attachments like this for pages and styles?".

The answer is simple, not easy and not fast.

Consider few facts:

1. Style assigned to page doesn't use plenty of images.
( Well, 20 or 30 images attached to page is not plenty of me. 200 or 300 could be some number in such case )
2. Midgard Apache module is able to serve images attached to page without any special code or without any need to know  image's guid or id.
3. Midgard Apache module doesn't ( when serving image  attached to page ):
  • initialize,load style and page elements
  • initialize midgard preparser
  • load midgard-root file
  • make additional selects from database to parse page ( and elements ) and serve attachment
And I wonder what is faster ( I mean someone's work and page request time ) and easier?

1. Upload image ( myfavourite.png )  attaching it to some object. Find its guid. Write code:
    /attachment/[sitegroup GUID]/[attachment GUID]/myfavourite.png

2. Upload image ( my favourite.png ) attaching it to page and write html code :
    /page/myfavourite.png

Second case requires only 1 ( say : one ) select from database.

Isn't it fast and easy?

Join

Posted on 2005-11-23 14:04:49 UTC.

Very hot and fresh method for MidgardQueryBuilder.

$qb->join(string property, string join_classname, string join_property);
  • property , property name which is a member of class defined for Query Builder
  • join_classname , classname which should be joined
  • join_property, property name which is a member of joined classname
$qb = new MidgardQueryBuilder("midgard_article");
$qb->add_constraint("creator", "=", 10);
$qb->join("creator", "midgard_person", "id");
$qb->execute();

And query:

SELECT guid, article.sitegroup, metadata_creator, metadata_created, metadata_revisor, metadata_revised, metadata_revision, metadata_locker, metadata_locked, metadata_approver, metadata_approved, metadata_author, metadata_owner, metadata_schedule_start, metadata_schedule_end, metadata_hidden, metadata_nav_noentry, metadata_size, article.up AS up,locked,revision,extra3,view,extra2,print,article.author AS author,article.topic AS topic,name,extra1,approver,revised,creator,type,icon,calstart,approved,caldays,locker,score,revisor,article.created AS created,article.id AS id,sid,article_i.created AS contentcreated,article_i.author AS contentauthor,url,content,lang,abstract,title FROM article_i,article,person WHERE article.creator = 10 AND article.id=article_i.sid AND article_i.lang IN (0, 0) AND article.creator=person.id


Interesting? I think metadata fields are noticable :)

Let's try to use metadata with QB then:

$qb = new MidgardQueryBuilder("midgard_article");
$qb->add_constraint("name", "=", "index");
$qb->add_constraint("metadata.created", ">", 20050101);
$qb->add_order("metadata.created", "DESC");
$qb->execute();
And query:

SELECT guid, article.sitegroup, metadata_creator, metadata_created, metadata_revisor, metadata_revised, metadata_revision, metadata_locker, metadata_locked, metadata_approver, metadata_approved, metadata_author, metadata_owner, metadata_schedule_start, metadata_schedule_end, metadata_hidden, metadata_nav_noentry, metadata_size, article.up AS up,locked,revision,extra3,view,extra2,print,article.author AS author,article.topic AS topic,name,extra1,approver,revised,creator,type,icon,calstart,approved,caldays,locker,score,revisor,article.created AS created,article.id AS id,sid,article_i.created AS contentcreated,article_i.author AS contentauthor,url,content,lang,abstract,title FROM article_i,article WHERE (article.name = 'index' AND metadata_created > '20050101') AND article.id=article_i.sid AND article_i.lang IN (0, 0) ORDER BY metadata_created DESC

Join method requires some details to be changed in Query Builder, and should be documented soon.
As well as metadata properties.

QB get_guid

Posted on 2005-11-25 13:55:09 UTC.

Just implemented for MidgardQueryBuilder.

$qb->get_guid(void);

Nice method which returns only object's guids as an array ( on PHP level ) instead of full objects. With faster query and faster value "allocator".

$qb = new MidgardQueryBuilder("midgard_article");
$qb->add_constraint("topic", ">", 0);
$qb->add_constraint("name", "=", index);
$qb->get_guid();

And query:

SELECT article.guid FROM article_i,article WHERE (article.topic > 0 AND article.name = 'index') AND article.id=article_i.sid AND article_i.lang IN (0, 0)

Intersting and good thing is that this method if fully metadata, sitegroup and multilang aware. In near future ACL will be added to "aware" list :)

Back

Layout Copyright © 2006 Finnish Teleservice Center Ltd Oy - Site Powered by Midgard CMS