Sha256: 1d04ac34e146fad6dfd7538d6cfe9bae206a6a91bbb3fed518aaf474855148a9

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

#!/usr/bin/env ruby

require "rawbotz"
require "rawbotz/option_parser"

optparse = Rawbotz::OptionParser.new do |opts, options|
  opts.banner = "Usage: #{$PROGRAM_NAME} [OPTIONS]"
  opts.separator ""

  opts.on("-m", "--[no-]mail",
          "send mail with result") do |v|
    options[:mail] = v
  end
  opts.on("-d", "--[no-]dry-run",
          "simulate, log potential changes but do not save them") do |d|
    options[:dry_run] = d
  end
end
optparse.parse!
options = optparse.options

logger = Logger.new(STDOUT)
logger.level = optparse.options[:verbose] ? Logger::DEBUG : Logger::INFO

logger.debug "#{$PROGRAM_NAME} #{Rawbotz::VERSION}"

logger.info("Fetching and updating local products from MySQL database")

begin
  products = RawgentoDB::Query.products
rescue
  logger.error "Could not connect to MySQL database or other error"
  logger.error $!.inspect
  # $@ -> backtrace would be available, too
  exit 1
end

product_count = RawgentoModels::LocalProduct.unscoped.count

updater = Rawbotz::ProductUpdater.new logger
updater.sync(options[:dry_run])

logger.info("Finished updating local products.")

logger.info("Found #{RawgentoModels::LocalProduct.unscoped.count - product_count}  new products")

if options[:mail]
  logger.debug("Sending mail")
  if updater.change_text.present?
    Rawbotz::mail("rawbotz local product update",
                  "Found #{RawgentoModels::LocalProduct.unscoped.count - product_count} new local products\n\nOther changes:\n#{updater.change_text}")
  else
    Rawbotz::mail("rawbotz local product update: no changes", "Nothing changed in magento")
  end
end

exit 0

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rawbotz-0.2.0 exe/rawbotz_update_local_products