?

Log in

No account? Create an account
entries friends calendar profile adric.net Previous Previous Next Next
It's thursday and the code mostly works - nil.enroll(aetheric_username, quantum_class_id)
yljatlhQo'! QIch lo'laltbebej!
adric
adric
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 
  MoocashOrderProcessing.new(op).save unless MoocashOrderProcessing.find_by_orders_products_id(op.orders_products_id)
end

## 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
    aetheric_username='mjolnir'
    
    ## 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.  
    else
      ## New MoocashOrder, pass the Order by id
      mco = MoocashOrder.new lineitem.order
      ## ask the MoocashOrder to enroll
      mco.enroll quantum_class_id
      ## if writing to DB does not fail spectacularly ...
      mco.save
      ## mark it done
      mop.processed = 1
      mop.save
    end
  end
end

ref:https://dev.atlbbs.com/svn/atlbbs/trunk/moocash/doc/logic_three.rb

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:

1 comment or Leave a comment
Comments
suri From: suri Date: December 5th, 2008 01:59 am (UTC) (Link)
Converting 4 Excel, 3 word and countless pieces of paper into one cohesive address book -- the old fashioned kind that has A,B,C tabs and such -- is taking a lot of time. Then maybe I can get to the Christmas cards. And it's too cold here already. Did I mention I hate snow because it creates Ice?
1 comment or Leave a comment