<?php

/**
 i* file: Fix Quote revisions now that revision attribute is going to Documents
 *
 */

class UpdateQuoteRevisionsShell extends Shell {


  var $uses = array('Enquiry', 'Quote', 'Document');


  function main() {

    // $enquiries = $this->Enquiry->find('all');

    // print_r($enquiries);

    $quotes = $this->Quote->find('all');


    foreach($quotes as $quote) {

      if($quote['Quote']['revision'] != 0) {
        echo 'Quote: '. $quote['Quote']['id'].' Document: '.$quote['Document']['id'];
        echo "\tQuote Revision is: {$quote['Quote']['revision']}  Doc Revision is: {$quote['Document']['revision']} \n";
      
        $this->Document->read(null, $quote['Document']['id']);
        $this->Document->set('revision', $quote['Quote']['revision']);
        
        if($this->Document->save()) {
            echo "Updated Document ID\n";
        }
      }



    }

  }
}


?>
