From registration.entity.inc:


  public function save() {
    // set a default state if not provided
    if (!$this->state || $this->state == -1) {
      $default_state = registration_get_default_state();
      if ($default_state) {
        $this->state = $default_state->internalIdentifier();
      }
    }
    $this->updated = REQUEST_TIME;
    if (!$this->registration_id) {
      $this->created = REQUEST_TIME;
    }
    return parent::save();
  }

Even if a registration is created and created/updated are written to, it is overwritten on the first save. You may be asking why I am trying to do this- at the moment I am importing 22-25k orders from a legacy system into Drupal Commerce, combined with Commerce Registration / Registration. The only way around this I have found was loading the entity after saving it (ouch) to write the time values, then saving it again.

In my case, retaining the timestamp as they were is crucial- and for possibly others trying to utilize Migrate. Is there any other way around this?

Comments

kevinquillen’s picture

Possible workaround:


public function save() {
    // set a default state if not provided
    if (!$this->state || $this->state == -1) {
      $default_state = registration_get_default_state();
      if ($default_state) {
        $this->state = $default_state->internalIdentifier();
      }
    }

    if (!$this->updated) {
      $this->updated = REQUEST_TIME;
    }
    
    if (!$this->registration_id && !$this->created) {
      $this->created = REQUEST_TIME;
    }

    return parent::save();
  }

levelos’s picture

Status: Active » Fixed

Looks reasonable.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

  • levelos committed 5531bdf on 7.x-1.x, panels, any-entity, slots, integrations, hold_state
    #1774236: Registration save() does not allow for initial writing of...