示例#1
0
文件: tmp.php 项目: nemein/openpsa
 /**
  * Loads the temporary object identified by the argument from the DB, verifies
  * ownership (using the midgard:owner privilege) and returns the instance.
  *
  * The object timestamp is updated implicitly by the temporary object class.
  *
  * Objects which have exceeded their lifetime will no longer be returned for
  * security reasons.
  *
  * @param int $id The temporary object ID to load.
  * @return midcom_core_temporary_object The associated object or null in case that it
  *     is unavailable.
  */
 function request_object($id)
 {
     if (!$id) {
         debug_add("Invalid argument, may not evaluate to false", MIDCOM_LOG_INFO);
         debug_print_r('Got this argument:', $id);
         return null;
     }
     $tmp = new midcom_core_temporary_object((int) $id);
     if (!$tmp->can_do('midgard:owner')) {
         debug_add("The current user does not have owner privileges on the temporary object {$id}, denying access.", MIDCOM_LOG_INFO);
         debug_print_r('Got this object:', $tmp);
         return null;
     }
     // Check if the object has timeouted already.
     $timeout = time() - $GLOBALS['midcom_config']['midcom_temporary_resource_timeout'];
     if ($tmp->timestamp < $timeout) {
         debug_add("The temporary object {$id}  has exceeded its maximum lifetime, rejecting access and dropping it", MIDCOM_LOG_INFO);
         debug_print_r("Object was:", $tmp);
         $tmp->delete();
         return null;
     }
     // Update the object timestamp
     $tmp->update();
     return $tmp;
 }