/** * Attempt to submit a CSV Tank for discrimination * * @param array $data * @return null */ protected function rec_create($data) { $rec = $this->parent_rec; // check column headers $imp = new CSVImporter($rec); $valid = $imp->validate_headers(); if ($valid !== true) { throw new Rframe_Exception(Rframe::BAD_DATA, $valid); } // check for extra data (project/activity/org/etc) if (!$rec->TankOrg->count() > 0) { throw new Rframe_Exception(Rframe::BAD_DATA, 'Must define organization'); } if (!$rec->TankActivity->count() > 0) { throw new Rframe_Exception(Rframe::BAD_DATA, 'Must define activity'); } if (!$rec->TankActivity[0]->tact_prj_id) { throw new Rframe_Exception(Rframe::BAD_DATA, 'Must define project'); } // import in foreground... TODO: param for bg processing $n = $imp->import_file(); if (is_string($n)) { $rec->set_meta_field('submit_message', $n); $rec->set_meta_field('submit_success', false); $rec->save(); throw new Rframe_Exception(Rframe::BAD_DATA, $n); } // success! $rec->set_meta_field('submit_message', "Successfully imported {$n} rows"); $rec->set_meta_field('submit_success', true); $rec->save(); // add to job_queue if (!isset($data['nojob'])) { $this->queue_discriminator($rec->tank_id); } return '1'; }