From 4a8bde0304bbeacee9ad299fb0e89e0d04af0a2d Mon Sep 17 00:00:00 2001 From: Benjamin Sonntag Date: Sat, 25 Aug 2012 15:44:50 +0000 Subject: [PATCH] fixing quota class, sorry boys <3 --- bureau/class/m_quota.php | 124 +++++++++++++++++++-------------------- 1 file changed, 62 insertions(+), 62 deletions(-) diff --git a/bureau/class/m_quota.php b/bureau/class/m_quota.php index ac82499e..0261d6aa 100644 --- a/bureau/class/m_quota.php +++ b/bureau/class/m_quota.php @@ -1,40 +1,40 @@ alternc_quota_check($uid) that -* may by exported by each service class.
-* each class may also export a function alternc_quota_names() -* that returns an array with the quotas names managed by this class. -* -*/ + * Class for hosting quotas management + * + * This class manages services' quotas for each user of AlternC. + * The available quotas for each service is stored in the system.quotas + * mysql table. The used value is computed by the class using a + * callback function alternc_quota_check($uid) that + * may by exported by each service class.
+ * each class may also export a function alternc_quota_names() + * that returns an array with the quotas names managed by this class. + * + */ class m_quota { var $disk=Array( /* disk resource for which we will manage quotas */ @@ -127,49 +127,49 @@ class m_quota { return array("t"=>0, "u"=>0); } else { while ($db->next_record()) { - $ttmp[]=$db->Record; - } + $ttmp[]=$db->Record; + } // TODO: old hook method FIXME: remove when unused - foreach ($ttmp as $tt) { - if (! isset( $this->clquota[$tt["name"]] )) continue; - if (method_exists($GLOBALS[$this->clquota[$tt["name"]]],"alternc_get_quota")) { - $this->quotas[$tt["name"]] = - array( - "t"=>$tt["total"], - "u"=> $GLOBALS[$this->clquota[$tt["name"]]]->alternc_get_quota($tt["name"]) - ); - } - } - foreach ($ttmp as $tt) { - $res=$hooks->invoke("",$tt["name"]); - foreach($res as $r) { - if ($r) { - $this->quotas[$tt["name"]]=array("t"=>$tt["total"],"u"); + foreach ($ttmp as $tt) { + if (! isset( $this->clquota[$tt["name"]] )) continue; + if (method_exists($GLOBALS[$this->clquota[$tt["name"]]],"alternc_get_quota")) { + $this->quotas[$tt["name"]] = + array( + "t"=>$tt["total"], + "u"=> $GLOBALS[$this->clquota[$tt["name"]]]->alternc_get_quota($tt["name"]) + ); } } + foreach ($ttmp as $tt) { + $res=$hooks->invoke("",$tt["name"]); + foreach($res as $r) { + if ($r) { + $this->quotas[$tt["name"]]=array("t"=>$tt["total"],"u"); + } + } + } + reset($this->disk); + while (list($key,$val)=each($this->disk)) { + $a=array(); + exec("/usr/lib/alternc/quota_get ".$cuid ,$a); + $this->quotas[$val]=array("t"=>$a[1],"u"=>$a[0]); + } + $get_quota_cache[$cuid] = $this->quotas; } - reset($this->disk); - while (list($key,$val)=each($this->disk)) { - $a=array(); - exec("/usr/lib/alternc/quota_get ".$cuid ,$a); - $this->quotas[$val]=array("t"=>$a[1],"u"=>$a[0]); - } - $get_quota_cache[$cuid] = $this->quotas; } - + if ($ressource) { if (isset($this->quotas[$ressource]) ) { - return $this->quotas[$ressource]; + return $this->quotas[$ressource]; } else { - return 0; + return 0; } } else { return $this->quotas; } } - - - + + /* ----------------------------------------------------------------- */ /** Set the quota for a user (and for a ressource) * @param string $ressource ressource to set quota of @@ -184,7 +184,7 @@ class m_quota { exec("/usr/lib/alternc/quota_edit $cuid $size &> /dev/null &"); // Now we check that the value has been written properly : exec("/usr/lib/alternc/quota_get $cuid &> /dev/null &",$a); - if ($size!=$a[1]) { + if ($size!=$a[1]) { $err->raise("quota",1); return false; } @@ -192,9 +192,9 @@ class m_quota { // We check that this ressource exists for this client : $db->query("SELECT * FROM quotas WHERE uid='$cuid' AND name='$ressource'"); if ($db->num_rows()) { - $db->query("UPDATE quotas SET total='$size' WHERE uid='$cuid' AND name='$ressource';"); + $db->query("UPDATE quotas SET total='$size' WHERE uid='$cuid' AND name='$ressource';"); } else { - $db->query("INSERT INTO quotas (uid,name,total) VALUES ('$cuid','$ressource','$size');"); + $db->query("INSERT INTO quotas (uid,name,total) VALUES ('$cuid','$ressource','$size');"); } return true; }