ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilDiskQuotaChecker Class Reference

Class ilDiskQuotaChecker. More...

+ Collaboration diagram for ilDiskQuotaChecker:

Public Member Functions

 __construct ()
 

Static Public Member Functions

static _lookupDiskQuota ($a_user_id)
 Gets the disk quota info for the specified user account. More...
 
static _lookupDiskUsage ($a_user_id)
 Gets the disk usage info for the specified user account. More...
 
static _fetchDiskQuotaReport ($a_usage_filter=3, $a_access_filter=1, $a_order_column='disk_usage', $a_order_by='desc')
 Reads disk quota/disk usage report of the user accounts. More...
 
static _updateDiskUsageReport ()
 Updates the disk usage info of all user accounts. More...
 
static _sendSummaryMails ()
 
static _sendReminderMails ()
 Sends reminder e-mails to all users who have access and who have exceeded their disk quota and who haven't received a reminder mail in the past 7 days. More...
 
static _lookupDiskUsageReportLastUpdate ()
 Returns the SQL datetime of the last update of the disk usage report. More...
 
static _lookupPersonalWorkspaceDiskQuota ($a_user_id)
 

Static Private Member Functions

static __updateDiskUsageReportOfType ($a_access_obj, $a_type)
 Updates the disk usage report of the specified object type for all user accounts. More...
 
static __saveUserData ($a_user_id, $a_type, $a_size, $a_count)
 Save disk quota for user. More...
 
static __updateDiskUsageReportOfTypeHelper ($a_access_obj, $a_objects, &$a_result)
 for each objects of an owner, count the number of objects and sum up the size More...
 
static __getRepositoryObjectsByType ($a_type)
 get all objects of the desired type which are in the repository ordered by owner More...
 
static __getWorkspaceObjectsByType ($a_type)
 get all objects of the desired type which are in the personal workspace ordered by owner More...
 
static __updateDiskUsageReportOfUsers ($a_access_obj, $a_type)
 Updates the disk usage report of the specified object type for all user accounts. More...
 

Detailed Description

Class ilDiskQuotaChecker.

Author
Werner Randelshofer, Hochschule Luzern, werne.nosp@m.r.ra.nosp@m.ndels.nosp@m.hofe.nosp@m.r@hsl.nosp@m.u.ch
Version
$Id$

Definition at line 33 of file class.ilDiskQuotaChecker.php.

Constructor & Destructor Documentation

◆ __construct()

ilDiskQuotaChecker::__construct ( )

Definition at line 35 of file class.ilDiskQuotaChecker.php.

36  {
37  }

Member Function Documentation

◆ __getRepositoryObjectsByType()

static ilDiskQuotaChecker::__getRepositoryObjectsByType (   $a_type)
staticprivate

get all objects of the desired type which are in the repository ordered by owner

Parameters
type$a_type
Returns
DB result object

Definition at line 474 of file class.ilDiskQuotaChecker.php.

References $a_type, $DIC, and $ilDB.

475  {
476  global $DIC;
477  $ilDB = $DIC['ilDB'];
478 
479  return $ilDB->query(
480  "SELECT DISTINCT d.obj_id, d.owner " .
481  "FROM object_data d " .
482  "JOIN object_reference r ON d.obj_id=r.obj_id " .
483  "JOIN tree t ON t.child=r.ref_id " .
484  "WHERE d.type = " . $ilDB->quote($a_type, "text") . " " .
485  "AND t.tree=1 " .
486  "ORDER BY d.owner"
487  );
488  }
global $DIC
Definition: saml.php:7
$a_type
Definition: workflow.php:92
global $ilDB

◆ __getWorkspaceObjectsByType()

static ilDiskQuotaChecker::__getWorkspaceObjectsByType (   $a_type)
staticprivate

get all objects of the desired type which are in the personal workspace ordered by owner

Parameters
type$a_type
Returns
DB result object

Definition at line 497 of file class.ilDiskQuotaChecker.php.

References $a_type, $DIC, and $ilDB.

498  {
499  global $DIC;
500  $ilDB = $DIC['ilDB'];
501 
502  return $ilDB->query(
503  "SELECT DISTINCT d.obj_id, d.owner " .
504  "FROM object_data d " .
505  "JOIN object_reference_ws r ON d.obj_id=r.obj_id " .
506  "JOIN tree_workspace t ON t.child=r.wsp_id " .
507  "WHERE d.type = " . $ilDB->quote($a_type, "text") . " " .
508  "AND t.tree=d.owner " .
509  "ORDER BY d.owner"
510  );
511  }
global $DIC
Definition: saml.php:7
$a_type
Definition: workflow.php:92
global $ilDB

◆ __saveUserData()

static ilDiskQuotaChecker::__saveUserData (   $a_user_id,
  $a_type,
  $a_size,
  $a_count 
)
staticprivate

Save disk quota for user.

Parameters
int$a_user_id
string$a_type
int$a_size
int$a_count

Definition at line 420 of file class.ilDiskQuotaChecker.php.

References $a_type, $DIC, and $ilDB.

421  {
422  global $DIC;
423  $ilDB = $DIC['ilDB'];
424 
425  if ($a_user_id && $a_size != null && $a_count != null) {
426  $ilDB->manipulate("INSERT INTO usr_pref " .
427  "(usr_id, keyword, value) " .
428  "VALUES " .
429  "(" . $ilDB->quote($a_user_id, 'integer') . ", " .
430  $ilDB->quote('disk_usage.' . $a_type . '.size') . ", " .
431  $ilDB->quote($a_size, 'integer') . ")");
432 
433  $ilDB->manipulate(
434  "INSERT INTO usr_pref " .
435  "(usr_id, keyword, value) " .
436  "VALUES " .
437  "(" . $ilDB->quote($a_user_id, 'integer') . ", " .
438  $ilDB->quote('disk_usage.' . $a_type . '.count') . ", " .
439  $ilDB->quote($a_count, 'integer') . ")"
440  );
441  }
442  }
global $DIC
Definition: saml.php:7
$a_type
Definition: workflow.php:92
global $ilDB

◆ __updateDiskUsageReportOfType()

static ilDiskQuotaChecker::__updateDiskUsageReportOfType (   $a_access_obj,
  $a_type 
)
staticprivate

Updates the disk usage report of the specified object type for all user accounts.

The results are stored in table usr_pref. For each user which owns files the following rows are inserted:

Parameters
$a_access_objObject A access object, such as ilObjFileAccess.
$a_typestring The type of the access object, such as 'file'.

Keyword Value Description 'disk_usage.file.count' integer The number of files owned by the user 'disk_usage.file.usage' integer The disk usage of the files

Definition at line 392 of file class.ilDiskQuotaChecker.php.

References $a_type, $data, and $res.

393  {
394  $data = array();
395 
396  // repository
397  $res = self::__getRepositoryObjectsByType($a_type);
398  self::__updateDiskUsageReportOfTypeHelper($a_access_obj, $res, $data);
399 
400  // personal workspace
401  $res = self::__getWorkspaceObjectsByType($a_type);
402  self::__updateDiskUsageReportOfTypeHelper($a_access_obj, $res, $data);
403 
404  // saving result to DB
405  if ($data) {
406  foreach ($data as $owner => $item) {
407  self::__saveUserData($owner, $a_type, $item["size"], $item["count"]);
408  }
409  }
410  }
$a_type
Definition: workflow.php:92
foreach($_POST as $key=> $value) $res
$data
Definition: bench.php:6

◆ __updateDiskUsageReportOfTypeHelper()

static ilDiskQuotaChecker::__updateDiskUsageReportOfTypeHelper (   $a_access_obj,
  $a_objects,
$a_result 
)
staticprivate

for each objects of an owner, count the number of objects and sum up the size

Parameters
object$a_access_obj
object$a_objects
array$a_result

Definition at line 452 of file class.ilDiskQuotaChecker.php.

References $row, and ilDBConstants\FETCHMODE_OBJECT.

453  {
454  while ($row = $a_objects->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
455  if ($row->owner != null) {
456  if (!array_key_exists($row->owner, $a_result)) {
457  // initialize values
458  $a_result[$row->owner] = array("size" => 0, "count" => 0);
459  }
460 
461  $a_result[$row->owner]["size"] += $a_access_obj->_lookupDiskUsage($row->obj_id);
462  $a_result[$row->owner]["count"]++;
463  }
464  }
465  }
$row

◆ __updateDiskUsageReportOfUsers()

static ilDiskQuotaChecker::__updateDiskUsageReportOfUsers (   $a_access_obj,
  $a_type 
)
staticprivate

Updates the disk usage report of the specified object type for all user accounts.

The results are stored in table usr_pref. For each user which owns files the following rows are inserted:

Parameters
$a_access_objObject A access object, such as ilObjFileAccess.
$a_typestring The type of the access object, such as 'file'.

Keyword Value Description 'disk_usage.file.count' integer The number of files owned by the user 'disk_usage.file.usage' integer The disk usage of the files

Definition at line 526 of file class.ilDiskQuotaChecker.php.

References $a_type, $data, $DIC, $ilDB, $res, $row, and ilDBConstants\FETCHMODE_OBJECT.

527  {
528  global $DIC;
529  $ilDB = $DIC['ilDB'];
530 
531  // get all users
532  $res = $ilDB->query("SELECT usr_id FROM usr_data");
533 
534  // for each user count the number of objects and sum up the size
535  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
536  $data = $a_access_obj->_lookupDiskUsageOfUser($row->usr_id);
537  self::__saveUserData($row->usr_id, $a_type, $data["size"], $data["count"]);
538  }
539  }
global $DIC
Definition: saml.php:7
$a_type
Definition: workflow.php:92
foreach($_POST as $key=> $value) $res
$row
global $ilDB
$data
Definition: bench.php:6

◆ _fetchDiskQuotaReport()

static ilDiskQuotaChecker::_fetchDiskQuotaReport (   $a_usage_filter = 3,
  $a_access_filter = 1,
  $a_order_column = 'disk_usage',
  $a_order_by = 'desc' 
)
static

Reads disk quota/disk usage report of the user accounts.

Returns an array or associative arrays with information about the disk usage of each user account.

Parameters
stringusage filter values: 1 = all users 2 = only users who don't use disk space 3 = only users who use disk space 4 = only users who have exceeded their quota
stringaccess filter values: 1 = all users 2 = only users who have access 4 = only users who have no access
Returns
array { array { 'usr_id'=>integer, // the user id 'login'=>string, // the login '...'=>..., // all other fields of table usr_data

'disk_usage'=>integer, // the disk usage in bytes 'disk_quota'=>integer, // the disk quota in bytes } }

Definition at line 222 of file class.ilDiskQuotaChecker.php.

References $data, $DIC, $ilDB, $res, $row, and ilDBConstants\FETCHMODE_ASSOC.

Referenced by ilObjFileAccessSettingsGUI\viewDiskQuotaReport().

223  {
224  $data = array();
225  global $DIC;
226  $ilDB = $DIC['ilDB'];
227 
228  if (!$a_order_column) {
229  $a_order_column = 'disk_usage';
230  }
231 
232  switch ($a_usage_filter) {
233  case 1: // all users
234  $where_clause = '';
235  break;
236  case 2: // only users who don't use disk space
237  $where_clause = 'WHERE (p2.value IS NULL) ';
238  break;
239  case 3: // only users who use disk space
240  default:
241  $where_clause = 'WHERE (p2.value+0 > 0) ';
242  break;
243  case 4: // only users who have exceeded their disk quota
244  // #8554 / #10301
245  $where_clause = 'WHERE (((p1.value+0 > rq.role_disk_quota OR rq.role_disk_quota IS NULL) AND p2.value+0 > p1.value+0) OR
246  ((rq.role_disk_quota > p1.value+0 OR p1.value IS NULL) AND p2.value+0 > rq.role_disk_quota)) ';
247  break;
248  }
249  switch ($a_access_filter) {
250  case 1: // all users
251  $where_clause .= '';
252  break;
253  case 2: // only users who have access
254  default:
255  $where_clause .= ($where_clause == '' ? 'WHERE ' : ' AND ') .
256  '(u.active=1 AND (u.time_limit_unlimited = 1 OR ' . $ilDB->unixTimestamp() . ' BETWEEN u.time_limit_from AND u.time_limit_until)) ';
257  break;
258  case 3: // only users who don't have access
259  $where_clause .= ($where_clause == '' ? 'WHERE ' : ' AND ') .
260  '(u.active=0 OR (u.time_limit_unlimited IS NULL AND ' . $ilDB->unixTimestamp() . ' NOT BETWEEN u.time_limit_from AND u.time_limit_until)) ';
261  break;
262  }
263 
264  $res = $ilDB->queryf(
265  "SELECT u.usr_id,u.firstname,u.lastname,u.login,u.email,u.last_login,u.active," .
266  "u.time_limit_unlimited, " . $ilDB->fromUnixtime("u.time_limit_from") . ", " . $ilDB->fromUnixtime("u.time_limit_until") . "," .
267 
268  // Inactive users get the date 0001-01-01 so that they appear
269  // first when the list is sorted by this field. Users with
270  // unlimited access get the date 9999-12-31 so that they appear
271  // last.
272  "CASE WHEN u.active = 0 THEN '0001-01-01' ELSE CASE WHEN u.time_limit_unlimited=1 THEN '9999-12-31' ELSE " . $ilDB->fromUnixtime("u.time_limit_until") . " END END access_until," .
273 
274  "CASE WHEN " . $ilDB->unixTimestamp() . " BETWEEN u.time_limit_from AND u.time_limit_until THEN 0 ELSE 1 END expired," .
275  "rq.role_disk_quota, system_role.rol_id role_id, " .
276  "p1.value+0 user_disk_quota," .
277  "p2.value+0 disk_usage, " .
278  "p3.value last_update, " .
279  "p4.value last_reminder, " .
280 
281  // We add 0 to some of the values to convert them into a number.
282  // This is needed for correct sorting.
283  "CASE WHEN rq.role_disk_quota>p1.value+0 OR p1.value IS NULL THEN rq.role_disk_quota ELSE p1.value+0 END disk_quota " .
284  "FROM usr_data u " .
285 
286  // Fetch the role with the highest disk quota value.
287  "JOIN (SELECT u.usr_id usr_id,MAX(rd.disk_quota) role_disk_quota " .
288  "FROM usr_data u " .
289  "JOIN rbac_ua ua ON ua.usr_id=u.usr_id " .
290  "JOIN rbac_fa fa ON fa.rol_id=ua.rol_id AND fa.parent=%s " .
291  "JOIN role_data rd ON rd.role_id=ua.rol_id WHERE u.usr_id=ua.usr_id GROUP BY u.usr_id) rq ON rq.usr_id=u.usr_id " .
292 
293  // Fetch the system role in order to determine whether the user has unlimited disk quota
294  "LEFT JOIN rbac_ua system_role ON system_role.usr_id=u.usr_id AND system_role.rol_id = %s " .
295 
296  // Fetch the user disk quota from table usr_pref
297  "LEFT JOIN usr_pref p1 ON p1.usr_id=u.usr_id AND p1.keyword = 'disk_quota' " .
298 
299  // Fetch the disk usage from table usr_pref
300  "LEFT JOIN usr_pref p2 ON p2.usr_id=u.usr_id AND p2.keyword = 'disk_usage' " .
301 
302  // Fetch the last update from table usr_pref
303  "LEFT JOIN usr_pref p3 ON p3.usr_id=u.usr_id AND p3.keyword = 'disk_usage.last_update' " .
304 
305  // Fetch the date when the last disk quota reminder was sent from table usr_pref
306  "LEFT JOIN usr_pref p4 ON p4.usr_id=u.usr_id AND p4.keyword = 'disk_quota_last_reminder' " .
307 
308  $where_clause .
309  "ORDER BY " . $a_order_column . " " . ($a_order_by == 'asc'?' ASC':' DESC') . ", " .
310  "lastname, firstname, login",
311  array('integer','integer'),
312  array(ROLE_FOLDER_ID, SYSTEM_ROLE_ID)
313  );
314  $previous_usr_id = null;
315  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
316  if ($previous_usr_id != $row['usr_id']) {
317  $data[] = $row;
318  $previous_usr_id = $row['usr_id'];
319  }
320  }
321  return $data;
322  }
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
$row
global $ilDB
$data
Definition: bench.php:6
+ Here is the caller graph for this function:

◆ _lookupDiskQuota()

static ilDiskQuotaChecker::_lookupDiskQuota (   $a_user_id)
static

Gets the disk quota info for the specified user account.

Returns an associative array with information about the disk quota of this user account.

Parameters
integeruser id
Returns
array { "role"=>role_id, // the id of the role which defines the highest // quota for the specified user account "role_title"=>string, // the title of the role

"role_disk_quota"=>integer or positive infinity, // the disk quota specified by the role in bytes. // the disk quota is positive infinity if // the user has the system administrator role

"user_disk_quota"=>integer // the disk quota specified on the user account // form.

"disk_quota"=>integer or positive infinity // the disk quota which is in effect. This is // either role_quota or user_quota whichever // is higher.

"last_reminder"=>string or null // the SQL datetime the last time a disk quota // reminder was sent to the user }

Definition at line 70 of file class.ilDiskQuotaChecker.php.

References $DIC, $ilDB, $info, $res, $row, and ilDBConstants\FETCHMODE_OBJECT.

Referenced by ilObjUserGUI\getValues().

71  {
72  $info = array();
73 
74  global $DIC;
75  $ilDB = $DIC['ilDB'];
76 
77  $res = $ilDB->queryf(
78  "SELECT keyword, value " .
79  "FROM usr_pref " .
80  "WHERE usr_id = %s " .
81  "AND keyword IN ('disk_quota', 'disk_quota_last_reminder')",
82  array('integer'),
83  array($a_user_id)
84  );
85 
86  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
87  switch ($row->keyword) {
88  case 'disk_quota':
89  $info['user_disk_quota'] = $row->value;
90  break;
91  case 'disk_quota_last_reminder':
92  $info['last_reminder'] = $row->value;
93  break;
94  }
95  }
96 
97 
98  // Note: we order by role_id ASC here, in the assumption that
99  // the system role has the lowest ID of all roles.
100  // this way, if a user has the system role, this role
101  // will always returned first.
102  $ilDB->setLimit(1);
103  $res = $ilDB->queryf(
104  "SELECT rd.role_id, rd.disk_quota, od.title " .
105  "FROM rbac_ua ua " .
106  "JOIN rbac_fa fa ON fa.rol_id=ua.rol_id AND fa.parent = %s " .
107  "JOIN role_data rd ON ua.rol_id=rd.role_id " .
108  "JOIN object_data od ON od.obj_id=rd.role_id " .
109  "WHERE ua.usr_id = %s " .
110  "ORDER BY disk_quota DESC, role_id ASC",
111  array('integer','integer'),
112  array(ROLE_FOLDER_ID, $a_user_id)
113  );
114 
116  $info['role_id'] = $row->role_id;
117  $info['role_title'] = $row->title;
118 
119  // Note: Users with the system role have an infinite disk quota
120  // We calculate positive infinity by negating the logarithm of 0.
121  $info['role_disk_quota'] = ($row->role_id == SYSTEM_ROLE_ID) ? -log(0) : $row->disk_quota;
122  $info['disk_quota'] = max($info['user_disk_quota'], $info['role_disk_quota']);
123 
124  return $info;
125  }
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
$row
global $ilDB
$info
Definition: index.php:5
+ Here is the caller graph for this function:

◆ _lookupDiskUsage()

static ilDiskQuotaChecker::_lookupDiskUsage (   $a_user_id)
static

Gets the disk usage info for the specified user account.

Returns an associative array with information about the disk usage of this user account.

Parameters
integeruser id
Returns
array { 'last_update'=>datetime, // SQL datetime of the last update // if this is null, the disk usage is unkown

'disk_usage'=>integer, // the disk usage in bytes

'details' array(array('type'=>string,'count'=>integer,'size'=>integer),...) // an associative array with the disk // usage in bytes for each object type

Definition at line 144 of file class.ilDiskQuotaChecker.php.

References $DIC, $ilDB, $info, $key, $res, $row, $type, and ilDBConstants\FETCHMODE_OBJECT.

Referenced by ilObjUserGUI\getValues(), and ilDiskQuotaSummaryNotification\send().

145  {
146  $info = array();
147  $details = array();
148 
149  global $DIC;
150  $ilDB = $DIC['ilDB'];
151 
152  $res = $ilDB->query(
153  "SELECT keyword, value " .
154  "FROM usr_pref " .
155  "WHERE usr_id = " . $ilDB->quote($a_user_id, 'integer') . " " .
156  "AND " . $ilDB->like("keyword", "text", 'disk\\_usage%')
157  );
158 
159  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
160  switch ($row->keyword) {
161  case 'disk_usage.last_update':
162  $info['last_update'] = $row->value;
163  break;
164 
165  case 'disk_usage':
166  $info['disk_usage'] = $row->value;
167  break;
168 
169  default:
170  // The following preg_match is used to extract the type
171  // and the keys 'count' and 'size' from the keywords:
172  // disk_usage.type.count
173  // disk_usage.type.size
174  $matches = array();
175  preg_match('/^disk_usage\\.([^.]+)\\.([^.]+)/', $row->keyword, $matches);
176  $type = $matches[1];
177  $key = $matches[2];
178  if ($type) {
179  $detail_data = $details[$type];
180  if ($detail_data == null) {
181  $detail_data = array('type' => $type);
182  }
183  $detail_data[$key] = $row->value;
184  }
185  $details[$type] = $detail_data;
186  break;
187  }
188  }
189  $info['details'] = $details;
190 
191 
192  //ilDiskQuotaChecker::_updateDiskUsageReport();
193 
194  return $info;
195  }
$type
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
$row
global $ilDB
$info
Definition: index.php:5
$key
Definition: croninfo.php:18
+ Here is the caller graph for this function:

◆ _lookupDiskUsageReportLastUpdate()

static ilDiskQuotaChecker::_lookupDiskUsageReportLastUpdate ( )
static

Returns the SQL datetime of the last update of the disk usage report.

Returns null, if the disk usage report has never been made.

Definition at line 659 of file class.ilDiskQuotaChecker.php.

References $DIC, $ilDB, $res, $row, and ilDBConstants\FETCHMODE_ASSOC.

Referenced by ilObjFileAccessSettingsGUI\viewDiskQuotaReport().

660  {
661  global $DIC;
662  $ilDB = $DIC['ilDB'];
663 
664  require_once 'Services/Mail/classes/class.ilDiskQuotaReminderMail.php';
665  $mail = new ilDiskQuotaReminderMail();
666 
667  $res = $ilDB->query("SELECT MAX(value) last_update " .
668  "FROM usr_pref WHERE keyword='disk_usage.last_update'");
670  return ($row != null) ? $row['last_update'] : null;
671  }
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
$row
Class ilDiskQuotaReminderMail.
global $ilDB
+ Here is the caller graph for this function:

◆ _lookupPersonalWorkspaceDiskQuota()

static ilDiskQuotaChecker::_lookupPersonalWorkspaceDiskQuota (   $a_user_id)
static

Definition at line 673 of file class.ilDiskQuotaChecker.php.

References $DIC, $ilDB, $info, $res, $row, and ilDBConstants\FETCHMODE_OBJECT.

Referenced by ilDiskQuotaHandler\getStatusLegend(), ilObjUserGUI\getValues(), and ilDiskQuotaHandler\isUploadPossible().

674  {
675  global $DIC;
676  $ilDB = $DIC['ilDB'];
677 
678  $info = array();
679 
680  $res = $ilDB->queryf(
681  "SELECT keyword, value " .
682  "FROM usr_pref " .
683  "WHERE usr_id = %s " .
684  "AND keyword = %s ",
685  array('integer', 'text'),
686  array($a_user_id, "wsp_disk_quota")
687  );
688 
690  $info['user_wsp_disk_quota'] = $row->value;
691 
692 
693  // Note: we order by role_id ASC here, in the assumption that
694  // the system role has the lowest ID of all roles.
695  // this way, if a user has the system role, this role
696  // will always returned first.
697  $ilDB->setLimit(1);
698  $res = $ilDB->queryf(
699  "SELECT rd.role_id, rd.wsp_disk_quota, od.title " .
700  "FROM rbac_ua ua " .
701  "JOIN rbac_fa fa ON fa.rol_id=ua.rol_id AND fa.parent = %s " .
702  "JOIN role_data rd ON ua.rol_id=rd.role_id " .
703  "JOIN object_data od ON od.obj_id=rd.role_id " .
704  "WHERE ua.usr_id = %s " .
705  "ORDER BY wsp_disk_quota DESC, role_id ASC",
706  array('integer','integer'),
707  array(ROLE_FOLDER_ID, $a_user_id)
708  );
709 
711  $info['role_id'] = $row->role_id;
712  $info['role_title'] = $row->title;
713 
714  // Note: Users with the system role have an infinite disk quota
715  // We calculate positive infinity by negating the logarithm of 0.
716  $info['role_wsp_disk_quota'] = ($row->role_id == SYSTEM_ROLE_ID) ? -log(0) : $row->wsp_disk_quota;
717  $info['disk_quota'] = max($info['user_wsp_disk_quota'], $info['role_wsp_disk_quota']);
718 
719  return $info;
720  }
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
$row
global $ilDB
$info
Definition: index.php:5
+ Here is the caller graph for this function:

◆ _sendReminderMails()

static ilDiskQuotaChecker::_sendReminderMails ( )
static

Sends reminder e-mails to all users who have access and who have exceeded their disk quota and who haven't received a reminder mail in the past 7 days.

Definition at line 561 of file class.ilDiskQuotaChecker.php.

References $DIC, $ilDB, $res, $row, and ilDBConstants\FETCHMODE_ASSOC.

Referenced by ilDAVCronDiskQuota\run().

562  {
563  global $DIC;
564  $ilDB = $DIC['ilDB'];
565 
566  require_once 'Services/Mail/classes/class.ilDiskQuotaReminderMail.php';
567  $mail = new ilDiskQuotaReminderMail();
568 
569  $res = $ilDB->queryf(
570  "SELECT u.usr_id,u.gender,u.firstname,u.lastname,u.login,u.email,u.last_login,u.active," .
571  "u.time_limit_unlimited, " . $ilDB->fromUnixtime("u.time_limit_from") . ", " . $ilDB->fromUnixtime("u.time_limit_until") . "," .
572 
573  // Inactive users get the date 0001-01-01 so that they appear
574  // first when the list is sorted by this field. Users with
575  // unlimited access get the date 9999-12-31 so that they appear
576  // last.
577  "CASE WHEN u.active = 0 THEN '0001-01-01' ELSE CASE WHEN u.time_limit_unlimited=1 THEN '9999-12-31' ELSE " . $ilDB->fromUnixtime("u.time_limit_until") . " END END access_until," .
578 
579  " CASE WHEN " . $ilDB->unixTimestamp() . " BETWEEN u.time_limit_from AND u.time_limit_until THEN 0 ELSE 1 END expired," .
580  "rq.role_disk_quota, system_role.rol_id role_id, " .
581  "p1.value+0 user_disk_quota," .
582  "p2.value+0 disk_usage, " .
583  "p3.value last_update, " .
584  "p4.value last_reminder, " .
585  "p5.value language, " .
586 
587  // We add 0 to some of the values to convert them into a number.
588  // This is needed for correct sorting.
589  "CASE WHEN rq.role_disk_quota>p1.value+0 OR p1.value IS NULL THEN rq.role_disk_quota ELSE p1.value+0 END disk_quota " .
590  "FROM usr_data u " .
591 
592  // Fetch the role with the highest disk quota value.
593  "JOIN (SELECT u.usr_id usr_id,MAX(rd.disk_quota) role_disk_quota " .
594  "FROM usr_data u " .
595  "JOIN rbac_ua ua ON ua.usr_id=u.usr_id " .
596  "JOIN rbac_fa fa ON fa.rol_id=ua.rol_id AND fa.parent=%s " .
597  "JOIN role_data rd ON rd.role_id=ua.rol_id WHERE u.usr_id=ua.usr_id GROUP BY u.usr_id) rq ON rq.usr_id=u.usr_id " .
598 
599  // Fetch the system role in order to determine whether the user has unlimited disk quota
600  "LEFT JOIN rbac_ua system_role ON system_role.usr_id=u.usr_id AND system_role.rol_id = %s " .
601 
602  // Fetch the user disk quota from table usr_pref
603  "LEFT JOIN usr_pref p1 ON p1.usr_id=u.usr_id AND p1.keyword = 'disk_quota' " .
604 
605  // Fetch the disk usage from table usr_pref
606  "LEFT JOIN usr_pref p2 ON p2.usr_id=u.usr_id AND p2.keyword = 'disk_usage' " .
607 
608  // Fetch the last update from table usr_pref
609  "LEFT JOIN usr_pref p3 ON p3.usr_id=u.usr_id AND p3.keyword = 'disk_usage.last_update' " .
610 
611  // Fetch the date when the last disk quota reminder was sent from table usr_pref
612  "LEFT JOIN usr_pref p4 ON p4.usr_id=u.usr_id AND p4.keyword = 'disk_quota_last_reminder' " .
613 
614  // Fetch the language of the user
615  "LEFT JOIN usr_pref p5 ON p5.usr_id=u.usr_id AND p5.keyword = 'language' " .
616 
617  // Fetch only users who have exceeded their quota, and who have
618  // access, and who have not received a reminder in the past seven days
619  // #8554 / #10301
620  'WHERE (((p1.value+0 >= rq.role_disk_quota OR rq.role_disk_quota IS NULL) AND p2.value+0 > p1.value+0) OR
621  ((rq.role_disk_quota > p1.value+0 OR p1.value IS NULL) AND p2.value+0 > rq.role_disk_quota)) ' .
622  'AND (u.active=1 AND (u.time_limit_unlimited = 1 OR ' . $ilDB->unixTimestamp() . ' BETWEEN u.time_limit_from AND u.time_limit_until)) ' .
623  'AND (p4.value IS NULL OR p4.value < DATE_SUB(NOW(), INTERVAL 7 DAY)) ',
624  array('integer','integer'),
625  array(ROLE_FOLDER_ID, SYSTEM_ROLE_ID)
626  );
627 
628  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
629  $details = self::_lookupDiskUsage($row['usr_id']);
630  $row['disk_usage_details'] = $details['details'];
631 
632  // Send reminder e-mail
633  $mail->setData($row);
634  $mail->send();
635 
636  // Store the date the last reminder was sent in the table usr_pref.
637  if ($row['last_reminder'] != null) {
638  $ilDB->manipulatef(
639  "UPDATE usr_pref SET value= " . $ilDB->now() . " " .
640  "WHERE usr_id=%s AND keyword = 'disk_quota_last_reminder'",
641  array('integer'),
642  array($row['usr_id'])
643  );
644  } else {
645  $ilDB->manipulatef(
646  "INSERT INTO usr_pref (usr_id, keyword, value) " .
647  "VALUES (%s, 'disk_quota_last_reminder', " . $ilDB->now() . ")",
648  array('integer'),
649  array($row['usr_id'])
650  );
651  }
652  }
653  }
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
$row
Class ilDiskQuotaReminderMail.
global $ilDB
+ Here is the caller graph for this function:

◆ _sendSummaryMails()

static ilDiskQuotaChecker::_sendSummaryMails ( )
static

Definition at line 541 of file class.ilDiskQuotaChecker.php.

References $DIC, and $ilSetting.

Referenced by ilDAVCronDiskQuota\run().

542  {
543  global $DIC;
544  $ilSetting = $DIC['ilSetting'];
545 
546  $lastStart = $ilSetting->get('last_cronjob_disk_quota_sum_start_ts', 0);
547  if (!$lastStart || date('dmY', $lastStart) != date('dmY')) {
548  $ilSetting->set('last_cronjob_disk_quota_sum_start_ts', time());
549 
550  include_once 'Services/Mail/classes/class.ilDiskQuotaSummaryNotification.php';
551  $dqsn = new ilDiskQuotaSummaryNotification();
552  $dqsn->send();
553  }
554  }
global $DIC
Definition: saml.php:7
global $ilSetting
Definition: privfeed.php:17
+ Here is the caller graph for this function:

◆ _updateDiskUsageReport()

static ilDiskQuotaChecker::_updateDiskUsageReport ( )
static

Updates the disk usage info of all user accounts.

The result is stored in usr_pref of each user. The following keywords are used:

'disk_usage_last_update' - the unix timestamp of the last update. 'disk_usage.file' - the disk usage of file objects owned by the user.

Definition at line 334 of file class.ilDiskQuotaChecker.php.

References $DIC, and $ilDB.

Referenced by ilDAVCronDiskQuota\run().

335  {
336  global $DIC;
337  $ilDB = $DIC['ilDB'];
338 
339  // delete old values
340  $ilDB->manipulate("DELETE FROM usr_pref " .
341  "WHERE " . $ilDB->like("keyword", "text", 'disk_usage%'));
342 
343 
344  require_once 'Modules/File/classes/class.ilObjFileAccess.php';
345  self::__updateDiskUsageReportOfType(new ilObjFileAccess(), 'file');
346 
347  self::__updateDiskUsageReportOfType(new ilObjForumAccess(), 'frm');
348 
349  require_once 'Modules/HTMLLearningModule/classes/class.ilObjFileBasedLMAccess.php';
350  self::__updateDiskUsageReportOfType(new ilObjFileBasedLMAccess(), 'htlm');
351 
352  require_once 'Modules/MediaCast/classes/class.ilObjMediaCastAccess.php';
353  self::__updateDiskUsageReportOfType(new ilObjMediaCastAccess(), 'mcst');
354 
355  require_once 'Modules/ScormAicc/classes/class.ilObjSAHSLearningModuleAccess.php';
356  self::__updateDiskUsageReportOfType(new ilObjSAHSLearningModuleAccess(), 'sahs');
357 
358  require_once 'Services/Mail/classes/class.ilObjMailAccess.php';
359  self::__updateDiskUsageReportOfUsers(new ilObjMailAccess(), 'mail_attachment');
360 
361  // insert the sum of the disk usage of each user
362  // note: second % is needed to not fail on oracle char field
363  $ilDB->manipulate(
364  "INSERT INTO usr_pref " .
365  "(usr_id, keyword, value) " .
366  "SELECT usr_id, 'disk_usage', SUM(value) " .
367  "FROM usr_pref " .
368  "WHERE " . $ilDB->like("keyword", "text", 'disk_usage.%.size%') .
369  "GROUP BY usr_id"
370  );
371 
372  // insert last update
373  $ilDB->manipulate("INSERT INTO usr_pref " .
374  "(usr_id, keyword, value) " .
375  "SELECT usr_id, 'disk_usage.last_update', " . $ilDB->now() . " " .
376  "FROM usr_data");
377  }
global $DIC
Definition: saml.php:7
Access class for file objects.
Class ilObjMediaCastAccess.
Class ilObjForumAccess.
Class ilFileBasedLMAccess.
Class ilObjMailAccess.
global $ilDB
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: