You are here

public function UcRolesLicense::prepareRow in Commerce License 8.2

Adds additional data to the row.

Parameters

\Drupal\migrate\Row $row: The row object.

Return value

bool FALSE if this row needs to be skipped.

Overrides SourcePluginBase::prepareRow

File

src/Plugin/migrate/source/d6/UcRolesLicense.php, line 78

Class

UcRolesLicense
Drupal 6 Ubercart roles expiration source.

Namespace

Drupal\commerce_license\Plugin\migrate\source\d6

Code

public function prepareRow(Row $row) {

  // Get the most recent order for this user and role product, if different
  // from the earliest order we retrieved in query().
  $query = $this
    ->select('uc_order_products', 'uop');
  $query
    ->innerJoin('uc_orders', 'uo', 'uop.order_id = uo.order_id');
  $query
    ->condition('uop.nid', $row
    ->getSourceProperty('nid'));
  $query
    ->condition('uo.uid', $row
    ->getSourceProperty('uid'));
  $query
    ->condition('uo.order_id', $row
    ->getSourceProperty('order_id'), '<>');
  $query
    ->fields('uo', [
    'order_id',
    'created',
    'modified',
  ]);
  $query
    ->orderBy('created', DESC);
  $query
    ->range(0, 1);
  $latest_order_data = $query
    ->execute()
    ->fetchAssoc();
  if ($latest_order_data) {

    // Set the date of the last renewal to the creation date of the most
    // recent order for this role.
    // This is the closest thing we have?
    $row
      ->setSourceProperty('renewed', $latest_order_data['created']);
  }
  else {
    $row
      ->setSourceProperty('renewed', NULL);
  }
  return parent::prepareRow($row);
}