Beispiel #1
0
  /**
   * 删除被某篇文章引用的所有上传的文件
   *
   * @param site_id
   * @param ref_id
   * @param ref_type
   * @return
   * @throws IOException
   */
  public static int deleteFilesByRef(Session ssn, int site_id, int ref_id, int ref_type)
      throws Exception {
    List files = findNamedAll("GET_UPLOAD_FILE_BY_REF", site_id, ref_id, ref_type);
    for (int i = 0; i < files.size(); i++) {
      FckUploadFileBean fufb = (FckUploadFileBean) files.get(i);
      if (StringUtils.isNotEmpty(fufb.getSavePath())) {
        FCK_UploadManager.getUploadHandler().remove(fufb);
      }

      int photo_site = DLOG4JUtils.sizeInKbytes(fufb.getFileSize());
      fufb.getSite().getCapacity().incDiaryUsed(-photo_site);

      ssn.delete(fufb);
    }
    return files.size();
  }
Beispiel #2
0
 /**
  * 查询某个HTTP会话上传的且尚未被领取的所有文件信息 要把文件大小计算进site中
  *
  * @param userid
  * @param sessionId
  * @return
  * @throws CapacityExceedException
  */
 public static int pickupOrphanFiles(
     int userid, String sessionId, SiteBean site, int refId, int refType)
     throws CapacityExceedException {
   int er = 0;
   try {
     // 要把文件大小计算进site中
     Number totalSize =
         executeNamedStat("SUM_UPLOAD_FILE_SIZE", new Object[] {new Integer(userid), sessionId});
     if (totalSize != null) {
       beginTransaction();
       int iTotalSize = totalSize.intValue();
       int file_size = DLOG4JUtils.sizeInKbytes(iTotalSize);
       if (site.getCapacity().getDiaryTotal() > 0
           && site.getCapacity().getDiaryUsed() + file_size > site.getCapacity().getDiaryTotal()) {
         // 已然超过可用的空间
         throw new CapacityExceedException(site.getCapacity().getDiaryTotal());
       }
       executeNamedUpdate("INC_SITE_UPLOAD_SPACE", Math.max(1, file_size), site.getId());
       // 更新尚未领取文件的归属信息
       executeNamedUpdate(
           "PICKUP_UPLOAD_FILES",
           new Object[] {
             new Integer(site.getId()),
             new Integer(refId),
             new Integer(refType),
             new Integer(userid),
             sessionId
           });
       commit();
     }
     return er;
   } catch (HibernateException e) {
     rollback();
     throw e;
   }
 }