<commit_before>﻿module Optimacms
  module PageServices
    class PageRouteService

      def self.find_page_by_url(url, lang='')
        where_base = 'is_folder = 0 AND enabled = 1 AND '
        order = 'url_parts_count DESC, url_vars_count ASC'

        if url.blank?
          where = where_base + 'url = \'\''
        else
          #where = where_base + '\'' + url + '\' REGEXP parsed_url'
          where = where_base + '\'' + url + '\''+ " REGEXP parsed_url"
        end

        # result
        pagedata = PageData.new
        pagedata.url = url

        # try 1
        rows = Page.where(where).order(order).all
        pagedata.page = rows[0] if rows.count>0

        # try 2
        if pagedata.page.nil? && url.blank?
          where = where_base + "url = '#{lang}'"
          rows = Page.where(where).order(order).all

          pagedata.page = rows[0] if row.count>0
        end

        return pagedata if pagedata.page.nil?


        # params from url
        pagedata.url_vars = get_url_vars(pagedata.url, pagedata.page)

        # controller
        if pagedata.page.controller_action.present?
          pagedata.controller, pagedata.action = parse_controller_action(pagedata.page.controller_action)
        end
<commit_msg>fix pagedata<commit_after>﻿module Optimacms
  module PageServices
    class PageRouteService

      def self.find_page_by_url(url, lang='')
        where_base = 'is_folder = 0 AND enabled = 1 AND '
        order = 'url_parts_count DESC, url_vars_count ASC'

        if url.blank?
          where = where_base + 'url = \'\''
        else
          #where = where_base + '\'' + url + '\' REGEXP parsed_url'
          where = where_base + '\'' + url + '\''+ " REGEXP parsed_url"
        end

        # result
        pagedata = PageData.new
        pagedata.url = url

        # try 1
        rows = Page.where(where).order(order).all
        pagedata.page = rows[0] if rows.count>0

        # try 2
        if pagedata.page.nil? && url.blank?
          where = where_base + "url = '#{lang}'"
          rows = Page.where(where).order(order).all

          pagedata.page = rows[0] if rows.count>0
        end

        return pagedata if pagedata.page.nil?


        # params from url
        pagedata.url_vars = get_url_vars(pagedata.url, pagedata.page)

        # controller
        if pagedata.page.controller_action.present?
          pagedata.controller, pagedata.action = parse_controller_action(pagedata.page.controller_action)
        end

{'fraction_non_alphanumeric': 0.10869565217391304, 'fraction_numerical': 0.00644122383252818, 'mean_word_length': 2.0231143552311437, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1454352', 'n_tokens_mistral': 810, 'n_tokens_neox': 783, 'n_words': 169}