l10n_server-2.x-dev/l10n_migrate/src/Plugin/migrate/source/L10nServerRelease.php

l10n_migrate/src/Plugin/migrate/source/L10nServerRelease.php
<?php

declare(strict_types=1);

namespace Drupal\l10n_migrate\Plugin\migrate\source;

use Drupal\Core\Database\Query\SelectInterface;
use Drupal\Core\Site\Settings;
use Drupal\migrate\Plugin\migrate\source\SqlBase;
use Drupal\migrate\Row;

/**
 * Migrate Source plugin.
 *
 * @MigrateSource(
 *   id = "l10n_migrate_server_release",
 *   source_module = "l10n_migrate",
 * )
 */
class L10nServerRelease extends SqlBase {

  /**
   * {@inheritdoc}
   */
  public function query(): SelectInterface {
    $query = $this
      ->select('l10n_server_release', 'r')
      ->fields('r', [
        'rid', 'pid', 'title', 'download_link', 'file_date', 'file_hash', 'last_parsed', 'weight', 'sid_count',
      ]);

    if ($pid = Settings::get('l10n_migrate_project_only')) {
      $query->condition('pid', $pid);
    }

    return $query;
  }

  /**
   * {@inheritdoc}
   */
  public function fields(): array {
    return [
      'rid' => $this->t('Release ID'),
      'pid' => $this->t('Project ID'),
      'title' => $this->t('Title'),
      'version' => $this->t('Version'),
      // @todo download_link (text) to download_link (varchar(255))
      'download_link' => $this->t('Download link'),
      'file_date' => $this->t('File date'),
      'file_hash' => $this->t('File hash'),
      'last_parsed' => $this->t('Last parsed'),
      'weight' => $this->t('Weight'),
      'sid_count' => $this->t('String ID count'),
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getIds(): array {
    return [
      'rid' => [
        'type' => 'integer',
        'alias' => 'r',
      ],
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function prepareRow(Row $row): bool {
    $row->setSourceProperty(
      'version',
      $row->getSourceProperty('title')
    );

    return parent::prepareRow($row);
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc