app/controllers/cms/agents/tasks/links_controller.rb
# Checks the URLs by task.
Checks the URLs by task.
Checks the URLs by task .
def check
    @task.log "# #{@site.name}"
    @ref_string = Cms::CheckLinks::RefString
    @base_url = @site.full_url.sub(/^(https?:\/\/.*?\/).*/, '\\1')
    @urls    = { @ref_string.new(@site.url) => %w(Site) }
    @results = {}
    @errors  = {}
    @html_request_timeout = SS.config.cms.check_links["html_request_timeout"] rescue 10
    @head_request_timeout = SS.config.cms.check_links["head_request_timeout"] rescue 5
    @check_mobile = SS.config.cms.check_links["check_mobile_path"] != false
    (10*1000*1000).times do |i|
      break if @urls.blank?
      url, refs = @urls.shift
      check_url(url, refs)
      @task.count
    end
    msg = ["[#{@errors.size} errors]"]
    @errors.map do |ref, urls|
      ref = File.join(@base_url, ref) if ref[0] == "/"
      msg << ref
      msg << urls.map do |url|
        meta = @meta.present? ? url.meta : ""
        url = File.join(@base_url, url) if url[0] == "/"
        "  - #{url} #{meta}"
      end
    end
    msg = msg.join("\n")
    @task.log msg
    if @email.present?
      ActionMailer::Base.mail(
        from: "shirasagi@" + @site.domain.sub(/:.*/, ""),
        to: @email,
        subject: "[#{@site.name}] Link Check: #{@errors.size} errors",
        body: msg
      ).deliver_now
    end
    create_report
    head :ok
  end
def check @task . log "# #{@site.name}" @ref_string = Cms :: CheckLinks :: RefString @base_url = @site . full_url . sub ( / ^(https?: \/ \/ .*? \/ ).* / , '\\1' ) @urls = { @ref_string . new ( @site . url ) => %w( Site ) } @results = { } @errors = { } @html_request_timeout = SS . config . cms . check_links [ "html_request_timeout" ] rescue 10 @head_request_timeout = SS . config . cms . check_links [ "head_request_timeout" ] rescue 5 @check_mobile = SS . config . cms . check_links [ "check_mobile_path" ] != false ( 10 * 1000 * 1000 ) . times do | i | break if @urls . blank? url , refs = @urls . shift check_url ( url , refs ) @task . count end msg = [ "[#{@errors.size} errors]" ] @errors . map do | ref , urls | ref = File . join ( @base_url , ref ) if ref [ 0 ] == "/" msg << ref msg << urls . map do | url | meta = @meta . present? ? url . meta : "" url = File . join ( @base_url , url ) if url [ 0 ] == "/" "  - #{url} #{meta}" end end msg = msg . join ( "\n" ) @task . log msg if @email . present? ActionMailer :: Base . mail ( from : "shirasagi@" + @site . domain . sub ( / :.* / , "" ) , to : @email , subject : "[#{@site.name}] Link Check: #{@errors.size} errors" , body : msg ) . deliver_now end create_report head :ok end
Checks the URLs by task.
Checks the URLs by task .
# @task.log url