<commit_before>module Deployinator
  module Stacks
    module Smartpatienttracker
      def smartpatienttracker_git_repo_url
        '<EMAIL>:xfactoradvertising/smart.git'
      end

      def smartpatienttracker_user
        'www-data'
      end

      def smartpatienttracker_stage_ip
        '172.16.58.3'
      end

      def smartpatienttracker_prod_ip
        '172.16.31.10'
      end

      def checkout_root
        '/tmp'
      end

      def site_root
        '/var/www/sites'
      end

      def site_path
        "#{site_root}/#{stack}"
      end

      def smartpatienttracker_git_checkout_path
        "#{checkout_root}/#{stack}"
      end

      def smartpatienttracker_dev_version
        %x{cat #{site_path}/version.txt}
      end

      def smartpatienttracker_dev_build
        Version.get_build(smartpatienttracker_dev_version)
      end

      def smartpatienttracker_stage_version
        %x{ssh #{smartpatienttracker_user}@#{smartpatienttracker_stage_ip} 'cat #{site_path}/version.txt'}
      end

      def smartpatienttracker_stage_build
        Version.get_build(smartpatienttracker_stage_version)
      end

      def smartpatienttracker_prod_version
        %x{ssh #{smartpatienttracker_user}@#{smartpatienttracker_prod_ip} 'cat #{site_path}/version.txt'}
      end

      def smartpatienttracker_prod_build
        Version.get_build(smartpatienttracker_prod_version)
      end

      def smartpatienttracker_head_build
        %x{git ls-remote #{smartpatienttracker_git_repo_url} HEAD | cut -c1-7}.chomp
      end

      # NOTE this options hash is unused but it is still passed by deployinator and removing it will break things
      def smartpatienttracker_dev(options={})
        old_build = smartpatienttracker_dev_build

        git_cmd = old_build ? :git_freshen_clone : :github_clone
        send(git_cmd, stack, 'sh -c')

        git_bump_version stack, ''

        build = smartpatienttracker_head_build

        begin
          # take application offline (maintenance mode)
          run_cmd %Q{cd #{site_path} && /usr/bin/php artisan down --env=dev || true} # return true so command is non-fatal

          # sync relevant site files to final destination
          run_cmd %Q{rsync -av --delete --force --exclude='app/storage/*/**' --exclude='vendor/' --exclude='.git/' --exclude='.gitignore' --filter "protect .env*" --filter "protect down" --filter "protect vendor/**" --filter "protect app/storage/**" --filter "protect app/files/**" --filter "protect public/assets/audio/**" #{smartpatienttracker_git_checkout_path}/ #{site_path}}

           # ensure storage is writable (shouldn't have to do this but running webserver as different user)
          run_cmd %Q{chmod 777 #{site_path}/app/storage/*}
          run_cmd %Q{chmod 777 #{site_path}/app/files}
          run_cmd %Q{chmod 777 #{site_path}/files}

          # install dependencies
          run_cmd %Q{cd #{site_path} && /usr/local/bin/composer install --no-dev}

          # run db migrations
          run_cmd %Q{cd #{site_path} && /usr/bin/php artisan migrate:refresh --seed --env=dev}

          # put application back online
          run_cmd %Q{cd #{site_path} && /usr/bin/php artisan up --env=dev}

          log_and_stream 'Done!<br>'
        rescue
          log_and_stream 'Failed!<br>'
        end

        log_and_shout(:old_build => old_build, :build => build, :send_email => false) # TODO make email true

      end

      # NOTE this options hash is unused but it is still passed by deployinator and removing it will break things
      def smartpatienttracker_stage(options={})
        old_build = smartpatienttracker_stage_build

        build = smartpatienttracker_dev_build

        begin
          # take application offline (maintenance mode)
          # return true so command is non-fatal (artisan doesn't exist the first time)
          run_cmd %Q{ssh #{smartpatienttracker_user}@#{smartpatienttracker_stage_ip} "cd #{site_path} && /usr/bin/php artisan down --env=stage || true"}

          # sync new app contents
          run_cmd %Q{rsync -ave ssh --delete --force --delete-excluded --exclude='app/storage/*/**' --exclude='.env*' --filter "protect .env*" --filter "protect down" --filter "protect app/storage/**" --filter "protect app/files/**" --filter "protect public/assets/audio/**" #{site_path}/ #{smartpatienttracker_user}@#{smartpatienttracker_stage_ip}:#{site_path}}

          # generate optimized autoload files
          run_cmd %Q{ssh #{smartpatienttracker_user}@#{smartpatienttracker_stage_ip} "cd #{site_path} && /usr/local/bin/composer dump-autoload -o"}

          # run db migrations
          run_cmd %Q{ssh #{smartpatienttracker_user}@#{smartpatienttracker_stage_ip} "cd #{site_path} && /usr/bin/php artisan migrate --seed --env=stage"}

          # put application back online
          run_cmd %Q{ssh #{smartpatienttracker_user}@#{smartpatienttracker_stage_ip} "cd #{site_path} && /usr/bin/php artisan up --env=stage"}

          log_and_stream 'Done!<br>'
        rescue
          log_and_stream 'Failed!<br>'
        end

        log_and_shout(:old_build => old_build, :build => build, :env => 'STAGE', :send_email => false) # TODO make email true

      end

      # NOTE this options hash is unused but it is still passed by deployinator and removing it will break things
      def smartpatienttracker_prod(options={})
        old_build = smartpatienttracker_prod_build
        build = smartpatienttracker_stage_build

        begin
          # take application offline (maintenance mode)
          # return true so command is non-fatal (artisan doesn't exist the first time)
          run_cmd %Q{ssh #{smartpatienttracker_user}@#{smartpatienttracker_prod_ip} "cd #{site_path} && /usr/bin/php artisan down || true"}

          # sync new app contents
          run_cmd %Q{ssh #{smartpatienttracker_user}@#{smartpatienttracker_stage_ip} "cd #{site_path} && rsync -ave ssh --delete --force --delete-excluded --exclude='app/storage/*/**' --exclude='.env*' --filter 'protect .env*' --filter 'protect down' --filter 'protect app/storage/**' --filter "protect app/files/**" --filter "protect public/assets/audio/**" #{site_path}/ #{smartpatienttracker_user}@#{smartpatienttracker_prod_ip}:#{site_path}"}<commit_msg>use single-quotes since entire command is double-quoted<commit_after>module Deployinator
  module Stacks
    module Smartpatienttracker
      def smartpatienttracker_git_repo_url
        'git@github.com:xfactoradvertising/smart.git'
      end

      def smartpatienttracker_user
        'www-data'
      end

      def smartpatienttracker_stage_ip
        '172.16.58.3'
      end

      def smartpatienttracker_prod_ip
        '172.16.31.10'
      end

      def checkout_root
        '/tmp'
      end

      def site_root
        '/var/www/sites'
      end

      def site_path
        "#{site_root}/#{stack}"
      end

      def smartpatienttracker_git_checkout_path
        "#{checkout_root}/#{stack}"
      end

      def smartpatienttracker_dev_version
        %x{cat #{site_path}/version.txt}
      end

      def smartpatienttracker_dev_build
        Version.get_build(smartpatienttracker_dev_version)
      end

      def smartpatienttracker_stage_version
        %x{ssh #{smartpatienttracker_user}@#{smartpatienttracker_stage_ip} 'cat #{site_path}/version.txt'}
      end

      def smartpatienttracker_stage_build
        Version.get_build(smartpatienttracker_stage_version)
      end

      def smartpatienttracker_prod_version
        %x{ssh #{smartpatienttracker_user}@#{smartpatienttracker_prod_ip} 'cat #{site_path}/version.txt'}
      end

      def smartpatienttracker_prod_build
        Version.get_build(smartpatienttracker_prod_version)
      end

      def smartpatienttracker_head_build
        %x{git ls-remote #{smartpatienttracker_git_repo_url} HEAD | cut -c1-7}.chomp
      end

      # NOTE this options hash is unused but it is still passed by deployinator and removing it will break things
      def smartpatienttracker_dev(options={})
        old_build = smartpatienttracker_dev_build

        git_cmd = old_build ? :git_freshen_clone : :github_clone
        send(git_cmd, stack, 'sh -c')

        git_bump_version stack, ''

        build = smartpatienttracker_head_build

        begin
          # take application offline (maintenance mode)
          run_cmd %Q{cd #{site_path} && /usr/bin/php artisan down --env=dev || true} # return true so command is non-fatal

          # sync relevant site files to final destination
          run_cmd %Q{rsync -av --delete --force --exclude='app/storage/*/**' --exclude='vendor/' --exclude='.git/' --exclude='.gitignore' --filter 'protect .env*' --filter 'protect down' --filter 'protect vendor/**' --filter 'protect app/storage/**' --filter 'protect app/files/**' --filter 'protect public/assets/audio/**' #{smartpatienttracker_git_checkout_path}/ #{site_path}}

           # ensure storage is writable (shouldn't have to do this but running webserver as different user)
          run_cmd %Q{chmod 777 #{site_path}/app/storage/*}
          run_cmd %Q{chmod 777 #{site_path}/app/files}
          run_cmd %Q{chmod 777 #{site_path}/files}

          # install dependencies
          run_cmd %Q{cd #{site_path} && /usr/local/bin/composer install --no-dev}

          # run db migrations
          run_cmd %Q{cd #{site_path} && /usr/bin/php artisan migrate:refresh --seed --env=dev}

          # put application back online
          run_cmd %Q{cd #{site_path} && /usr/bin/php artisan up --env=dev}

          log_and_stream 'Done!<br>'
        rescue
          log_and_stream 'Failed!<br>'
        end

        log_and_shout(:old_build => old_build, :build => build, :send_email => false) # TODO make email true

      end

      # NOTE this options hash is unused but it is still passed by deployinator and removing it will break things
      def smartpatienttracker_stage(options={})
        old_build = smartpatienttracker_stage_build

        build = smartpatienttracker_dev_build

        begin
          # take application offline (maintenance mode)
          # return true so command is non-fatal (artisan doesn't exist the first time)
          run_cmd %Q{ssh #{smartpatienttracker_user}@#{smartpatienttracker_stage_ip} "cd #{site_path} && /usr/bin/php artisan down --env=stage || true"}

          # sync new app contents
          run_cmd %Q{rsync -ave ssh --delete --force --delete-excluded --exclude='app/storage/*/**' --exclude='.env*' --filter 'protect .env*' --filter 'protect down' --filter 'protect app/storage/**' --filter 'protect app/files/**' --filter 'protect public/assets/audio/**' #{site_path}/ #{smartpatienttracker_user}@#{smartpatienttracker_stage_ip}:#{site_path}}

          # generate optimized autoload files
          run_cmd %Q{ssh #{smartpatienttracker_user}@#{smartpatienttracker_stage_ip} "cd #{site_path} && /usr/local/bin/composer dump-autoload -o"}

          # run db migrations
          run_cmd %Q{ssh #{smartpatienttracker_user}@#{smartpatienttracker_stage_ip} "cd #{site_path} && /usr/bin/php artisan migrate --seed --env=stage"}

          # put application back online
          run_cmd %Q{ssh #{smartpatienttracker_user}@#{smartpatienttracker_stage_ip} "cd #{site_path} && /usr/bin/php artisan up --env=stage"}

          log_and_stream 'Done!<br>'
        rescue
          log_and_stream 'Failed!<br>'
        end

        log_and_shout(:old_build => old_build, :build => build, :env => 'STAGE', :send_email => false) # TODO make email true

      end

      # NOTE this options hash is unused but it is still passed by deployinator and removing it will break things
      def smartpatienttracker_prod(options={})
        old_build = smartpatienttracker_prod_build
        build = smartpatienttracker_stage_build

        begin
          # take application offline (maintenance mode)
          # return true so command is non-fatal (artisan doesn't exist the first time)
          run_cmd %Q{ssh #{smartpatienttracker_user}@#{smartpatienttracker_prod_ip} "cd #{site_path} && /usr/bin/php artisan down || true"}

          # sync new app contents
          run_cmd %Q{ssh #{smartpatienttracker_user}@#{smartpatienttracker_stage_ip} "cd #{site_path} && rsync -ave ssh --delete --force --delete-excluded --exclude='app/storage/*/**' --exclude='.env*' --filter 'protect .env*' --filter 'protect down' --filter 'protect app/storage/**' --filter 'protect app/files/**' --filter 'protect public/assets/audio/**' #{site_path}/ #{smartpatienttracker_user}@#{smartpatienttracker_prod_ip}:#{site_path}"}
{'fraction_non_alphanumeric': 0.11180914512922466, 'fraction_numerical': 0.004453280318091451, 'mean_word_length': 2.920199501246883, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 5, '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': '336277', 'n_tokens_mistral': 3900, 'n_tokens_neox': 3716, 'n_words': 943}