nil.enroll(aetheric_username, quantum_class_id) (adric) wrote,
nil.enroll(aetheric_username, quantum_class_id)

It's thursday and the code mostly works

Code works manually but not in the script. Anyone receiving multiple new account emails can rest assured that this is a good sign ;)

#!/usr/bin/env ../script/runner

## third try on the order processing logic, started in pseudocode

## preliminaries:

## cache existing moodle users
moodle_users = User.all.collect do |u| u.username end

## Run through lineitems, creating MoocashOrderProcessing 
##   where not found so we have is_processed? fields 
OrderProduct.all.each do |op|
  ## make a mop if there is not already a MoocashOrderProcessing line for this lineitem unless MoocashOrderProcessing.find_by_orders_products_id(op.orders_products_id)

## Main order processing loop

## For every line item not marked as processed 
MoocashOrderProcessing.find_all_by_processed(0).each do |mop|
  ##get the lineitem from the MOP view 
  lineitem = mop.orderproduct
  ## if lineitem's product type is 'training'
  if lineitem.product.master_categories_id == '1'

    ## FAKE: get class_id from lineitem.products_id => class_id
    quantum_class_id = '1'
    ## FAKE: get username from Order.orderstatushistory.comments REGEX ~= USERNAME:$username
    ## if we're given an existing Moodle user, set it up for enroll in new class_id
    if moodle_users.include? aetheric_username
      ## FAKE: enroll(aetheric_username, quantum_class_id)
      ## lineitem.processed = 1
      p 'Moocash : order processing : debug : username given: #{aetheric_username}'

    ## More likely create a new entry in the view so Moodle will add a new
    ## => user and enroll it.  
      ## New MoocashOrder, pass the Order by id
      mco = lineitem.order
      ## ask the MoocashOrder to enroll
      mco.enroll quantum_class_id
      ## if writing to DB does not fail spectacularly ...
      ## mark it done
      mop.processed = 1


Reread Dune Messiah in the last couple days. That was really quite good and much better than I remember. It makes watching the SciFi miniseries ever so much more painful, though.

Moving is proceeding at a trickle, but there's food in the kitchen and other signs of a potential home. Plenty of work ahead on that front, not including dragging more crap across town, and eventually paying someone to move the furniture over.

That wasn't much better that the last try, but oh well. How are all of you doing? Surviving the $holiday onslaught?
Tags: rails

  • Tuesday?

    Amusing away messages at work today included: "Band-aids: Went to buy band-aids, back soon". Zaniness readings are pushing the border between yellow…

  • Please *do* glorify some great hackers and not crime

    Please *do* glorify some great hackers and not crime Re: "Stop Glorifying Hackers"(sic) from the M. McWhorter, I'm sorry you had trouble safely…

  • MCU for Fall and Winter 2013

    The Keanu movie about the ronin was not as bad as the trailer led us to believe it would be. I saw it in a theatre with an aikido afficianado and…

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded