Friday, January 22, 2010

How to debug my save command

I've been reading the manual and looking for examples, but I am still
having difficulty with issuing a save to update only three fields that
I have updated.

I have a foreach loop to read $data for records that have been
previously selected based on the 'scheduled' date for the reminder. I
am doing setup of some variables from $data values in order to send an
e-mail reminder for the next service interval. (Background: when a
repair order is created or updated, the scheduled dates for the e-mail
reminders are set and the 'actual' date is set to null.) After sending
the e-mail I want to update the 'actual' field as proof that an e-mail
was sent.

Here is the code I have been working with in my controller:

// Loop through eligible repair orders, send reminder, and update
actual date
foreach ( $data as $data ) {

$to = $data['Repairorder']['customer_email'];
$vin = $data['Repairorder']['vin'];
$services = $data['Repairorder']['lof'] . ' lubrication service';
switch($data['Repairorder']['odometer_type']) {
case 'Kms':
$interval = 5000;
break;
case 'Miles':
$interval = 3000;
break;
}
$new_odometer = $data['Repairorder']['odometer'] + $interval;
$odometer_type = $data['Repairorder']['odometer_type'];

// Send e-mail reminder message
// $id = $this->sendMail(
// $data['Repairorder']['id'],
// $to,
// $vin,
// $services,
// $new_odometer,
// $interval,
// $odometer_type);

// Update 'actual' date field(s)
if ($data['Repairorder']['lof_sch_60'] <= date('Y-m-d'))
$data['Repairorder']['lof_act_60'] = date('Y-m-d');
if ($data['Repairorder']['lof_sch_75'] <= date('Y-m-d'))
$data['Repairorder']['lof_act_75'] = date('Y-m-d');
if ($data['Repairorder']['lof_sch_90'] <= date('Y-m-d'))
$data['Repairorder']['lof_act_90'] = date('Y-m-d');

$this->Repairorder->id = $data['Repairorder']['id'];
$this->Repairorder->save($data);
// array('fieldlist' => array(
// 'lof_act_60',
// 'lof_act_75',
// 'lof_act_90'
// )));

/* Debug information to the error.log file in ../app/tmp/ */
$this->log(array(
'record' => $data['Repairorder']['id'],
'lof_sch_60' => $data['Repairorder']['lof_sch_60'],
'lof_act_60' => $data['Repairorder']['lof_act_60'],
'lof_sch_75' => $data['Repairorder']['lof_sch_75'],
'lof_act_75' => $data['Repairorder']['lof_act_75'],
'lof_sch_90' => $data['Repairorder']['lof_sch_90'],
'lof_act_90' => $data['Repairorder']['lof_act_90']
));

} // end_foreach on $data results

The log entry for each record has the correct value set for the
'actual' field, but the update to the database is not occurring.
Ultimately I would like to provide an array with the fieldlist of the
three fields I want to update.

In the $data array is ['Repairorder']['id']. That should be enough to
access the individual record, right? I shouldn't have to set that
before a save, but only set it if I was doing a saveField. Is that
understanding correct?

Where is the error(s) in my code for the save to not work? Thank you
in advance for your assistance.

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: