mardi 1 août 2017

DB::beginTransaction not working for sub functions

I've DB::beginTransaction() in laravel but its working only for database changes done in main function only not for sub functions.

i.e.

try {
  DB::beginTransaction();
  $status = (Input::get('task_status') == '') ? 1 : Input::get('task_status');
  $data = array(
    'id' => Input::get('id'),
    'task_title' => Input::get('task_title'),
    'task_desc' => Input::get('task_desc'),
  );
  DB::table('task')->insert($data);
  $id = DB::getPdo()->lastInsertId();

  // Add Actionees
  if (!$this->addActionees(Input::get('actionees'), $id)) {\
    DB::rollback();
    return Response::json(false);
  }
  // Add Tasks
  if (!$this->addTasks(Input::get('linked_tasks'), $id)) {\
    DB::rollback();
    return Response::json(false);
  }\
  DB::commit();
  return Response::json($id);
} catch (Exception $ex) {
  Log::error("Method: ".__METHOD__.
    ", Line ".__LINE__.
    ": ".(string) $ex);\
  DB::rollback();
  return Response::json($ex);
}

So in above example the changes that done under functions addTasks() and addActionees() is not rolled back.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire