Пример #1
0
  public boolean addOneJob(long configID, boolean immediate) {
    ZCDeployJobSchema job = new ZCDeployJobSchema();
    ZCDeployConfigSchema config = new ZCDeployConfigSchema();
    config.setID(configID);
    if (!config.fill()) {
      return false;
    }

    String staticDir =
        Config.getContextRealPath() + Config.getValue("Statical.TargetDir").replace('\\', '/');
    String sourcePath =
        staticDir + "/" + ApplicationPage.getCurrentSiteAlias() + config.getSourceDir();
    job.setID(NoUtil.getMaxID("DeployJobID"));
    job.setConfigID(config.getID());
    job.setSource(sourcePath);
    job.setMethod(config.getMethod());

    String targetDir = config.getTargetDir();
    if (XString.isEmpty(targetDir)) {
      targetDir = "/";
    } else if (!targetDir.endsWith("/")) {
      targetDir = targetDir + "/";
    }

    job.setTarget(targetDir);
    job.setSiteID(config.getSiteID());
    job.setHost(config.getHost());
    job.setPort(config.getPort());
    job.setUserName(config.getUserName());
    job.setPassword(config.getPassword());
    job.setStatus(0L);
    job.setAddTime(new Date());
    job.setAddUser(User.getUserName());

    Transaction trans = new Transaction();
    trans.add(job, OperateType.INSERT);
    if (trans.commit()) {
      if (immediate) {
        executeJob(config, job);
      }
      return true;
    }
    LogUtil.getLogger().info("添加部署任务时,数据库操作失败");
    return false;
  }
Пример #2
0
 public void add() {
   Transaction tran = new Transaction();
   ZCFullTextSchema ft = new ZCFullTextSchema();
   if (XString.isEmpty($V("ID"))) {
     ft.setValue(this.request);
     ft.setID(NoUtil.getMaxID("FullTextID"));
     ft.setSiteID(ApplicationPage.getCurrentSiteID());
     ft.setAddTime(new Date());
     ft.setAddUser(User.getUserName());
     tran.add(ft, OperateType.INSERT);
   } else {
     ft.setID(Long.parseLong($V("ID")));
     ft.fill();
     ft.setValue(this.request);
     ft.setModifyTime(new Date());
     ft.setModifyUser(User.getUserName());
     tran.add(ft, OperateType.UPDATE);
   }
   if (tran.commit()) this.response.setMessage("保存成功");
   else this.response.setError("发生错误,保存失败");
 }
Пример #3
0
  public boolean executeBatchJob(ZCDeployConfigSchema config, ZCDeployJobSet jobs) {
    if ((config == null) || (jobs.size() < 1)) {
      return false;
    }

    Transaction trans = new Transaction();
    String message = "";
    boolean connectFlag = true;

    String deployMethod = config.getMethod();
    if ("DIR".equals(deployMethod)) {
      for (int i = 0; i < jobs.size(); i++) {
        ZCDeployJobSchema job = jobs.get(i);

        ZCDeployLogSchema jobLog = new ZCDeployLogSchema();
        jobLog.setID(NoUtil.getMaxID("DeployLogID"));
        jobLog.setSiteID(job.getSiteID());
        jobLog.setJobID(job.getID());
        jobLog.setBeginTime(new Date());

        if (job.getStatus() == 3L) {
          job.setRetryCount(job.getRetryCount() + 1L);
        }

        String sourceFile = job.getSource();
        if (sourceFile.indexOf("template") != -1) {
          LogUtil.getLogger().info("模板文件" + sourceFile + "不复制,跳过");
          return true;
        }

        String target = job.getTarget();
        target = target.replace('\\', '/');
        String targetDir = target.substring(0, target.lastIndexOf("/"));
        File dir = new File(targetDir);
        if (!dir.exists()) {
          dir.mkdirs();
        }
        if (!targetDir.endsWith("/template")) {
          if ("delete".equalsIgnoreCase(job.getOperation())) {
            if (FileUtil.delete(target)) {
              message = "成功删除文件" + target;
              LogUtil.getLogger().info(message);
              job.setStatus(2L);
            } else {
              message = "失败:删除文件" + target;
              LogUtil.getLogger().info(message);
              job.setStatus(3L);
              Errorx.addError(message);
            }
          } else if (FileUtil.copy(sourceFile, target)) {
            message = "成功复制文件" + sourceFile + "到" + target;
            LogUtil.getLogger().info(message);
            job.setStatus(2L);
          } else {
            message = "失败:复制文件" + sourceFile + "到" + target;
            LogUtil.getLogger().info(message);
            job.setStatus(3L);
            Errorx.addError(message);
          }
        }

        jobLog.setMessage(message);
        jobLog.setEndTime(new Date());
        LogUtil.getLogger().info(message);

        trans.add(jobLog, OperateType.INSERT);
        trans.add(job, OperateType.UPDATE);
      }
    } else if ("FTP".equals(deployMethod)) {
      CommonFtp ftp = new CommonFtp();
      try {
        ftp.connect(
            config.getHost(), (int) config.getPort(), config.getUserName(), config.getPassword());
        connectFlag = true;
      } catch (IOException e1) {
        e1.printStackTrace();

        ZCDeployLogSchema jobLog = new ZCDeployLogSchema();
        jobLog.setID(NoUtil.getMaxID("DeployLogID"));
        jobLog.setSiteID(config.getSiteID());
        jobLog.setJobID(jobs.get(0).getID());
        jobLog.setBeginTime(new Date());
        jobLog.setEndTime(new Date());
        jobLog.setMessage(e1.getMessage());
        trans.add(jobLog, OperateType.INSERT);
        connectFlag = false;
      }
      if (connectFlag) {
        for (int i = 0; i < jobs.size(); i++) {
          ZCDeployJobSchema job = jobs.get(i);

          ZCDeployLogSchema jobLog = new ZCDeployLogSchema();
          jobLog.setID(NoUtil.getMaxID("DeployLogID"));
          jobLog.setSiteID(job.getSiteID());
          jobLog.setJobID(job.getID());
          jobLog.setBeginTime(new Date());

          if (job.getStatus() == 3L) {
            job.setRetryCount(job.getRetryCount() + 1L);
          }

          String target = job.getTarget();
          target = target.replace('\\', '/');
          if ("delete".equalsIgnoreCase(job.getOperation()))
            try {
              target = target.replaceAll("///", "/");
              if (ftp.delete(target)) {
                message = "FTP删除文件成功";
                job.setStatus(2L);
                jobLog.setMessage(message);
                jobLog.setEndTime(new Date());
                LogUtil.getLogger().info(message);

                trans.add(jobLog, OperateType.INSERT);
                trans.add(job, OperateType.UPDATE);
                break;
              }
              message = "FTP删除文件失败";
              job.setStatus(3L);
            } catch (Exception e) {
              job.setStatus(3L);
              message = e.getMessage();
              Errorx.addError(message);
            }
          else {
            try {
              String srcFile = job.getSource();
              srcFile = srcFile.replaceAll("///", "/");
              srcFile = srcFile.replaceAll("//", "/");
              String path = srcFile;
              ArrayList list = FileList.getAllFiles(path);
              if (list.size() == 0) {
                job.setStatus(3L);
                message = "文件不存在:" + path;
                Errorx.addError(message);
              } else {
                for (int j = 0; j < list.size(); j++) {
                  String name = (String) list.get(j);
                  if (name.indexOf("template") != -1) {
                    continue;
                  }
                  name = name.replace('\\', '/');
                  String targetName = name.replaceAll(path, "");
                  ftp.upload(name, target + targetName);
                }
                job.setStatus(2L);
                message = "FTP上传成功";
              }
            } catch (Exception e) {
              job.setStatus(3L);
              message = e.getMessage();
              Errorx.addError(message);
            }
          }
          label1106:
          jobLog.setMessage(message);
          jobLog.setEndTime(new Date());
          LogUtil.getLogger().info(message);

          trans.add(jobLog, OperateType.INSERT);
          trans.add(job, OperateType.UPDATE);
        }
      }
      ftp.disconnect();
    } else if ("SFTP".equals(deployMethod)) {
      SFtp sftp = new SFtp();
      try {
        sftp.connect(
            config.getHost(), (int) config.getPort(), config.getUserName(), config.getPassword());
        connectFlag = true;
      } catch (JSchException e1) {
        e1.printStackTrace();

        ZCDeployLogSchema jobLog = new ZCDeployLogSchema();
        jobLog.setID(NoUtil.getMaxID("DeployLogID"));
        jobLog.setSiteID(config.getSiteID());
        jobLog.setJobID(jobs.get(0).getID());
        jobLog.setBeginTime(new Date());
        jobLog.setEndTime(new Date());
        jobLog.setMessage(e1.getMessage());
        trans.add(jobLog, OperateType.INSERT);
        connectFlag = false;
      }
      if (connectFlag) {
        for (int i = 0; i < jobs.size(); i++) {
          ZCDeployJobSchema job = jobs.get(i);

          ZCDeployLogSchema jobLog = new ZCDeployLogSchema();
          jobLog.setID(NoUtil.getMaxID("DeployLogID"));
          jobLog.setSiteID(job.getSiteID());
          jobLog.setJobID(job.getID());
          jobLog.setBeginTime(new Date());

          if (job.getStatus() == 3L) {
            job.setRetryCount(job.getRetryCount() + 1L);
          }

          String target = job.getTarget();
          target = target.replace('\\', '/');
          if ("delete".equalsIgnoreCase(job.getOperation()))
            try {
              target = target.replaceAll("///", "/");
              if (sftp.delete(target)) {
                message = "SFTP删除文件成功";
                job.setStatus(2L);
                jobLog.setMessage(message);
                jobLog.setEndTime(new Date());
                LogUtil.getLogger().info(message);

                trans.add(jobLog, OperateType.INSERT);
                trans.add(job, OperateType.UPDATE);
              }
              message = "SFTP删除文件失败";
              job.setStatus(3L);
            } catch (Exception e) {
              job.setStatus(3L);
              message = e.getMessage();
              Errorx.addError(message);
            }
          else {
            try {
              String srcFile = job.getSource();
              srcFile = srcFile.replaceAll("///", "/");
              srcFile = srcFile.replaceAll("//", "/");
              String path = srcFile;
              ArrayList list = FileList.getAllFiles(path);
              if (list.size() == 0) {
                job.setStatus(3L);
                message = "文件不存在" + srcFile;
              } else {
                for (int j = 0; j < list.size(); j++) {
                  String name = (String) list.get(j);
                  if (name.indexOf("template") != -1) {
                    continue;
                  }
                  name = name.replace('\\', '/');
                  String targetName = name.replaceAll(path, "");
                  sftp.upload(name, target + targetName);
                }
                job.setStatus(2L);
                message = "SFTP上传成功";
              }
            } catch (Exception e) {
              job.setStatus(3L);
              message = e.getMessage();
              Errorx.addError(message);
            }
          }
          label1730:
          jobLog.setMessage(message);
          jobLog.setEndTime(new Date());
          LogUtil.getLogger().info(message);

          trans.add(jobLog, OperateType.INSERT);
          trans.add(job, OperateType.UPDATE);
        }
      }
      sftp.disconnect();
    }

    if (trans.commit()) {
      return true;
    }
    LogUtil.getLogger().info("添加部署任务时,数据库操作失败");
    Errorx.addError(message);
    return false;
  }
Пример #4
0
  public ZCDeployJobSet getJobs(long siteID, ArrayList list, String operation) {
    ZCDeployJobSet jobSet = new ZCDeployJobSet();
    for (int j = 0; j < list.size(); j++) {
      String srcPath = (String) list.get(j);
      if (XString.isEmpty(srcPath)) {
        continue;
      }
      srcPath = srcPath.replace('\\', '/').replaceAll("///", "/").replaceAll("//", "/");

      String baseDir =
          Config.getContextRealPath() + Config.getValue("Statical.TargetDir").replace('\\', '/');
      baseDir = baseDir + "/" + SiteUtil.getAlias(siteID);

      baseDir = baseDir.replaceAll("///", "/");
      baseDir = baseDir.replaceAll("//", "/");
      srcPath = srcPath.replaceAll(baseDir, "");

      ZCDeployConfigSchema config = new ZCDeployConfigSchema();

      QueryBuilder qb =
          new QueryBuilder(
              " where UseFlag =1 and siteid=? and ? like concat(sourcedir,'%')", siteID, srcPath);
      if (Config.isSQLServer()) {
        qb.setSQL(" where siteid=? and charindex(sourcedir,?)=0");
      }
      if (Config.isDB2()) {
        qb.setSQL(" where siteid=? and locate(sourcedir,'" + srcPath + "')=0");
        qb.getParams().remove(qb.getParams().size() - 1);
      }

      ZCDeployConfigSet set = config.query(qb);

      for (int i = 0; i < set.size(); i++) {
        config = set.get(i);
        String target = config.getTargetDir();
        if (XString.isEmpty(target)) {
          target = "/";
        } else if (!target.endsWith("/")) {
          target = target + "/";
        }

        String filePath = srcPath;
        if (!config.getSourceDir().equals("/")) {
          filePath = srcPath.replaceAll(config.getSourceDir(), "");
        }
        target = dealFileName(target, filePath);

        ZCDeployJobSchema job = new ZCDeployJobSchema();
        job.setID(NoUtil.getMaxID("DeployJobID"));
        job.setConfigID(config.getID());
        job.setSource(baseDir + srcPath);
        job.setMethod(config.getMethod());
        job.setTarget(target);
        job.setSiteID(config.getSiteID());
        job.setHost(config.getHost());
        job.setPort(config.getPort());
        job.setUserName(config.getUserName());
        job.setPassword(config.getPassword());
        job.setRetryCount(0L);
        job.setStatus(0L);
        job.setOperation(operation);
        job.setAddTime(new Date());
        if (User.getCurrent() != null) job.setAddUser(User.getUserName());
        else {
          job.setAddUser("SYS");
        }

        jobSet.add(job);
      }
    }

    return jobSet;
  }
Пример #5
0
  public static void dealAutoIndex(long siteID, boolean autoIndex) {
    ZCFullTextSchema ft = new ZCFullTextSchema();
    ft.setSiteID(siteID);
    ft.setProp1("AutoIndex");
    ZCFullTextSet set = ft.query();
    if (!autoIndex) {
      if (set.size() == 0) {
        return;
      }
      long sourceID = set.get(0).getID();
      ZDScheduleSchema sd = new ZDScheduleSchema();
      sd.setSourceID(sourceID);
      ZDScheduleSet sdSet = sd.query();
      if (sdSet.size() == 0) {
        return;
      }
      sd = sdSet.get(0);
      if ("N".equals(sd.getIsUsing())) {
        return;
      }
      sd.setIsUsing("N");
      sd.update();
    } else if (set.size() == 0) {
      ft.setID(NoUtil.getMaxID("FullTextID"));
      ft.setRelaText("-1");
      ft.setType("Article");
      ft.setName("全站索引-" + SiteUtil.getName(ft.getSiteID()));
      ft.setCode("AllArticle");
      ft.setAddUser("SYS");
      ft.setAddTime(new Date());

      ZDScheduleSchema sd = new ZDScheduleSchema();
      sd.setAddTime(new Date());
      sd.setAddUser("SYS");
      sd.setCronExpression("*/3 * * * *");
      sd.setID(NoUtil.getMaxID("ScheduleID"));
      sd.setIsUsing("Y");
      sd.setPlanType("Period");
      sd.setTypeCode("IndexMaintenance");
      sd.setStartTime(new Date());
      sd.setSourceID(ft.getID());

      Transaction tran = new Transaction();
      tran.add(ft, OperateType.INSERT);
      tran.add(sd, OperateType.INSERT);
      tran.commit();
    } else {
      ft = set.get(0);
      long sourceID = set.get(0).getID();
      ZDScheduleSchema sd = new ZDScheduleSchema();
      sd.setSourceID(sourceID);
      ZDScheduleSet sdSet = sd.query();
      if (sdSet.size() == 0) {
        sd.setAddTime(new Date());
        sd.setAddUser("SYS");
        sd.setCronExpression("*/3 * * * *");
        sd.setID(NoUtil.getMaxID("ScheduleID"));
        sd.setIsUsing("Y");
        sd.setPlanType("Period");
        sd.setTypeCode("IndexMaintenance");
        sd.setStartTime(new Date());
        sd.setSourceID(ft.getID());
        sd.insert();
      }
    }
  }
Пример #6
0
  public void add() {
    if (ForumUtil.isNotSendTheme($V("SiteID"), $V("ForumID"))) {
      this.response.setLogInfo(0, "您没有发帖的权限");
      return;
    }
    ForumScore forumScore = new ForumScore($V("SiteID"));
    ZCThemeSchema theme = new ZCThemeSchema();
    ZCForumMemberSchema user = new ZCForumMemberSchema();
    ZCForumSchema forum = new ZCForumSchema();
    ForumPriv priv = new ForumPriv($V("SiteID"));
    Transaction trans = new Transaction();

    theme.setValue(this.request);
    theme.setID(NoUtil.getMaxID("ThemeID"));

    forum.setID(theme.getForumID());
    forum.fill();
    theme.setSiteID($V("SiteID"));
    theme.setAddUser(User.getUserName());
    theme.setOrderFlag(0L);
    theme.setViewCount(0);
    theme.setReplyCount(0);
    theme.setTopTheme("N");
    theme.setBest("N");
    theme.setType("0");
    theme.setAddTime(new Date());
    theme.setOrderTime(new Date());
    theme.setStatus("Y");
    theme.setVerifyFlag(forum.getVerify().equals("N") ? "Y" : "N");
    trans.add(theme, OperateType.INSERT);

    ZCPostSchema post = new ZCPostSchema();
    post.setValue(this.request);
    post.setFirst("Y");
    post.setID(NoUtil.getMaxID("PostID"));
    post.setThemeID(theme.getID());
    post.setAddUser(User.getUserName());
    post.setAddTime(theme.getAddTime());
    post.setVerifyFlag(forum.getVerify().equals("N") ? "Y" : "N");
    post.setInvisible("Y");
    post.setLayer(1L);
    post.setMessage(PostAdd.processMsg($V("Message")));
    trans.add(post, OperateType.INSERT);
    user.setUserName(theme.getAddUser());
    user.fill();

    if (priv.hasPriv("Verify")) {
      theme.setVerifyFlag("Y");
      post.setVerifyFlag("Y");
    }

    if (theme.getVerifyFlag().equals("Y")) {
      user.setForumScore(user.getForumScore() + forumScore.PublishTheme);
      ForumUtil.userGroupChange(user);
      user.setThemeCount(user.getThemeCount() + 1L);
      forum.setThemeCount(forum.getThemeCount() + 1);
      forum.setLastThemeID(theme.getID());
      forum.setLastPost(theme.getSubject());
      forum.setLastPoster(theme.getAddUser());
    }
    if (post.getVerifyFlag().equals("Y")) {
      forum.setPostCount(forum.getPostCount() + 1);
    }
    trans.add(user, OperateType.UPDATE);
    trans.add(forum, OperateType.UPDATE);
    if ($V("file").length() > 0) {
      String[] Attachments = $V("file").split(",");
      String[] indexs = $V("indexs").split(",");
      for (int i = 0; i < Attachments.length; i++) {
        ZCForumAttachmentSchema attachment = new ZCForumAttachmentSchema();
        attachment.setID(NoUtil.getMaxID("ForumAttachmentID"));
        attachment.setPostID(post.getID());
        attachment.setSiteID($V("SiteID"));
        String suffix =
            $V("file" + indexs[i]).substring($V("file" + indexs[i]).lastIndexOf(".") + 1);
        if (PubFun.isAllowExt(suffix, "Attach")) {
          attachment.setType("attach");
        } else if (PubFun.isAllowExt(suffix, "Image")) {
          attachment.setType("image");
        } else if (PubFun.isAllowExt(suffix, "Audio")) {
          attachment.setType("audio");
        } else if (PubFun.isAllowExt(suffix, "Video")) {
          attachment.setType("video");
        } else {
          this.response.setLogInfo(0, "不允许上传该文件类型");
          return;
        }
        attachment.setSuffix(suffix);
        attachment.setName(
            $V("file" + indexs[i]).substring($V("file" + indexs[i]).lastIndexOf("\\") + 1));
        String[] file = Attachments[i].split("#");
        attachment.setPath(file[0]);
        attachment.setAttSize(file[1]);
        attachment.setDownCount(0L);
        attachment.setAddUser(User.getUserName());
        attachment.setAddTime(new Date());
        trans.add(attachment, OperateType.INSERT);
      }
    }
    if (trans.commit()) {
      if (theme.getVerifyFlag().equals("Y")) {
        CacheManager.set("Forum", "Forum", forum.getID(), forum);
        this.response.setLogInfo(1, "新增成功");
        this.response.put("ThemeID", theme.getID());
      } else {
        this.response.setLogInfo(2, "论坛管理员设置了审核机制,请等待审核!");
      }
    } else this.response.setLogInfo(0, "新增失败!");
  }