<commit_before>require 'highline'

def ask(what, options = {})
  default = options[:default]
  validate = options[:validate] || /(y(es)?)|(no?)|(a(bort)?|\n)/i
  echo = (options[:echo].nil?) ? true : options[:echo]

  ui = HighLine.new
  ui.ask("#{what}?  ") do |q|
    q.overwrite = false
    q.default = default
    q.validate = validate
    q.responses[:not_valid] = what
    unless echo
      q.echo = '*'
    end
  end
end

def public_path
  Pathname.new Rails.public_path
end

namespace :contao do
  desc 'Link all contao files'
  task :bootstrap do
    TechnoGate::Contao::Application.linkify

    FileUtils.mkdir_p public_path.join('system/logs')
    File.open(public_path.join('sitemap.xml'), 'w') {|f| f.write ''}

    Rake::Task['contao:generate_localconfig'].invoke
    Rake::Task['contao:generate_htaccess'].invoke
    Rake::Task['contao:apply_patches'].invoke
    Rake::Task['assets:precompile'].invoke if Rails.env.production?
    Rake::Task['contao:fix_permissions'].invoke

    TechnoGate::Contao::Notifier.notify 'The contao folder has been bootstraped, Good Luck.'
  end

  desc 'Apply Patches'
  task :apply_patches do
    path = File.expand_path "../../../contao_patches/#{Rails.env}", __FILE__
    Dir["#{path}/**/*.patch"].each do |patch|
      TechnoGate::Contao::Notifier.notify("Applying patch #{File.basename patch}")
      result = system <<-CMD
        cd #{public_path}
        patch -Nfp1 -i #{patch} --no-backup-if-mismatch
      CMD

      if !result
        TechnoGate::Contao::Notifier.notify("Patch #{File.basename patch} failed to apply")
        abort 'Please fix patches before bootstrapping'
      end
    end
  end

  desc 'Fix permissions'
  task :fix_permissions do
    require 'fileutils'

    paths = [
      'system/html',
      'system/logs',
      'system/scripts',
      'system/tmp',
      'system/cache',
      'system/config',
    ].map {|p| public_path.join p}.reject {|p| !File.exists? p}

    FileUtils.chmod 0777, paths

    FileUtils.chmod 0666, Dir["#{public_path}/system/config/**/*.php"]

    Dir["#{public_path}/system/modules/efg/**/*"].each do |f|
      if File.directory?(f)
        FileUtils.chmod 0777, f
      else
        FileUtils.chmod 0666, f
      end
    end

    FileUtils.chmod 0666, public_path.join('sitemap.xml')

    TechnoGate::Contao::Notifier.notify 'The permissions of the contao folder has been fixed'
  end
<commit_msg>Make sure the runonce.php scripts are deletable<commit_after>require 'highline'

def ask(what, options = {})
  default = options[:default]
  validate = options[:validate] || /(y(es)?)|(no?)|(a(bort)?|\n)/i
  echo = (options[:echo].nil?) ? true : options[:echo]

  ui = HighLine.new
  ui.ask("#{what}?  ") do |q|
    q.overwrite = false
    q.default = default
    q.validate = validate
    q.responses[:not_valid] = what
    unless echo
      q.echo = '*'
    end
  end
end

def public_path
  Pathname.new Rails.public_path
end

namespace :contao do
  desc 'Link all contao files'
  task :bootstrap do
    TechnoGate::Contao::Application.linkify

    FileUtils.mkdir_p public_path.join('system/logs')
    File.open(public_path.join('sitemap.xml'), 'w') {|f| f.write ''}

    Rake::Task['contao:generate_localconfig'].invoke
    Rake::Task['contao:generate_htaccess'].invoke
    Rake::Task['contao:apply_patches'].invoke
    Rake::Task['assets:precompile'].invoke if Rails.env.production?
    Rake::Task['contao:fix_permissions'].invoke

    TechnoGate::Contao::Notifier.notify 'The contao folder has been bootstraped, Good Luck.'
  end

  desc 'Apply Patches'
  task :apply_patches do
    path = File.expand_path "../../../contao_patches/#{Rails.env}", __FILE__
    Dir["#{path}/**/*.patch"].each do |patch|
      TechnoGate::Contao::Notifier.notify("Applying patch #{File.basename patch}")
      result = system <<-CMD
        cd #{public_path}
        patch -Nfp1 -i #{patch} --no-backup-if-mismatch
      CMD

      if !result
        TechnoGate::Contao::Notifier.notify("Patch #{File.basename patch} failed to apply")
        abort 'Please fix patches before bootstrapping'
      end
    end
  end

  desc 'Fix permissions'
  task :fix_permissions do
    require 'fileutils'

    paths = [
      'system/html',
      'system/logs',
      'system/scripts',
      'system/tmp',
      'system/cache',
      'system/config',
    ].map {|p| public_path.join p}.reject {|p| !File.exists? p}

    FileUtils.chmod 0777, paths

    FileUtils.chmod 0666, Dir["#{public_path}/system/config/**/*.php"]

    Dir["#{public_path}/system/modules/efg/**/*"].each do |f|
      if File.directory?(f)
        FileUtils.chmod 0777, f
      else
        FileUtils.chmod 0666, f
      end
    end

    Dir["#{public_path}/system/modules/*/config/runonce.php"].each do |f|
      FileUtils.chmod 0666, f
    end

    FileUtils.chmod 0666, public_path.join('sitemap.xml')

    TechnoGate::Contao::Notifier.notify 'The permissions of the contao folder has been fixed'
  end

{'fraction_non_alphanumeric': 0.14974772956609486, 'fraction_numerical': 0.009283551967709384, 'mean_word_length': 3.150753768844221, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '3909937', 'n_tokens_mistral': 1731, 'n_tokens_neox': 1673, 'n_words': 361}