<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def WriteAllCrashDetails(client_id, crash_details, flow_session_id=None, hunt_session_id=None, token=None):
 """Updates the last crash attribute of the client."""

  # AFF4.
  if data_store.AFF4Enabled():
    with aff4.FACTORY.Create(
        client_id, aff4_grr.VFSGRRClient, token=token) as client_obj:
      client_obj.Set(client_obj.Schema.LAST_CRASH(crash_details))

    # Duplicate the crash information in a number of places so we can find it
    # easily.
    client_urn = rdf_client.ClientURN(client_id)
    client_crashes = aff4_grr.VFSGRRClient.CrashCollectionURNForCID(client_urn)
    with data_store.DB.GetMutationPool() as pool:
      grr_collections.CrashCollection.StaticAdd(
          client_crashes, crash_details, mutation_pool=pool)

  # Relational db.
  if data_store.RelationalDBEnabled():
    try:
      data_store.REL_DB.WriteClientCrashInfo(client_id, crash_details)
    except db.UnknownClientError:
      pass

  if not flow_session_id:
    return

  if data_store.RelationalDBEnabled():
    flow_id = flow_session_id.Basename()
    data_store.REL_DB.UpdateFlow(
        client_id, flow_id, client_crash_info=crash_details)

    flow_obj = data_store.REL_DB.ReadFlowObject(client_id, flow_id)
    if flow_obj.parent_hunt_id:
      db_compat.ProcessHuntClientCrash(
          flow_obj, client_crash_info=crash_details)

  # TODO(amoser): Registering crashes in hunts is currently not implemented for
  # the relational db.
  if not data_store.RelationalDBEnabled():
    with aff4.FACTORY.Open(
        flow_session_id,
        flow.GRRFlow,
        mode="rw",
        age=aff4.NEWEST_TIME,
        token=token) as aff4_flow:
      aff4_flow.Set(aff4_flow.Schema.CLIENT_CRASH(crash_details))

    hunt_session_id = ExtractHuntId(flow_session_id)
    if hunt_session_id and hunt_session_id != flow_session_id:
      hunt_obj = aff4.FACTORY.Open(
          hunt_session_id,
          aff4_type=implementation.GRRHunt,
          mode="rw",
          token=token)
      hunt_obj.RegisterCrash(crash_details)