clean install

This commit is contained in:
2024-12-10 15:08:16 +01:00
commit e14eb2d8fd
31193 changed files with 3555714 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
name: farmOS Migrate
description: farmOS Migrate API plugins.
type: module
package: farmOS
core_version_requirement: ^10
dependencies:
- drupal:migrate
- migrate_plus:migrate_plus

View File

@@ -0,0 +1,76 @@
<?php
/**
* @file
* Post update hooks for the farm_migrate module.
*/
/**
* Uninstall farmOS v1 migrations.
*/
function farm_migrate_post_update_uninstall_v1_migrations(&$sandbox) {
// Delete migration and migration_group configurations.
$configurations = [
'migrate_plus.migration.farm_migrate_area_land',
'migrate_plus.migration.farm_migrate_area_none',
'migrate_plus.migration.farm_migrate_area_structure',
'migrate_plus.migration.farm_migrate_area_water',
'migrate_plus.migration.farm_migrate_asset_animal',
'migrate_plus.migration.farm_migrate_asset_compost',
'migrate_plus.migration.farm_migrate_asset_equipment',
'migrate_plus.migration.farm_migrate_asset_group',
'migrate_plus.migration.farm_migrate_asset_plant',
'migrate_plus.migration.farm_migrate_asset_sensor',
'migrate_plus.migration.farm_migrate_asset_sensor_listener',
'migrate_plus.migration.farm_migrate_inventory',
'migrate_plus.migration.farm_migrate_log_activity',
'migrate_plus.migration.farm_migrate_log_birth',
'migrate_plus.migration.farm_migrate_log_harvest',
'migrate_plus.migration.farm_migrate_log_input',
'migrate_plus.migration.farm_migrate_log_lab_test',
'migrate_plus.migration.farm_migrate_log_maintenance',
'migrate_plus.migration.farm_migrate_log_medical',
'migrate_plus.migration.farm_migrate_log_observation',
'migrate_plus.migration.farm_migrate_log_seeding',
'migrate_plus.migration.farm_migrate_log_transplanting',
'migrate_plus.migration.farm_migrate_quantity_standard',
'migrate_plus.migration.farm_migrate_role',
'migrate_plus.migration.farm_migrate_sensor_listener_data_streams',
'migrate_plus.migration.farm_migrate_sensor_listener_notifications',
'migrate_plus.migration.farm_migrate_taxonomy_animal_type',
'migrate_plus.migration.farm_migrate_taxonomy_crop_family',
'migrate_plus.migration.farm_migrate_taxonomy_log_category',
'migrate_plus.migration.farm_migrate_taxonomy_material_type',
'migrate_plus.migration.farm_migrate_taxonomy_plant_type',
'migrate_plus.migration.farm_migrate_taxonomy_season',
'migrate_plus.migration.farm_migrate_taxonomy_unit',
'migrate_plus.migration.farm_migrate_area_field_parent',
'migrate_plus.migration.farm_migrate_asset_field_parent',
'migrate_plus.migration.farm_migrate_file',
'migrate_plus.migration.farm_migrate_file_private',
'migrate_plus.migration.farm_migrate_quantity_system',
'migrate_plus.migration.farm_migrate_system_date',
'migrate_plus.migration.farm_migrate_user',
'migrate_plus.migration_group.farm_migrate_area',
'migrate_plus.migration_group.farm_migrate_asset',
'migrate_plus.migration_group.farm_migrate_asset_parent',
'migrate_plus.migration_group.farm_migrate_config',
'migrate_plus.migration_group.farm_migrate_file',
'migrate_plus.migration_group.farm_migrate_log',
'migrate_plus.migration_group.farm_migrate_plan',
'migrate_plus.migration_group.farm_migrate_quantity',
'migrate_plus.migration_group.farm_migrate_role',
'migrate_plus.migration_group.farm_migrate_sensor_data',
'migrate_plus.migration_group.farm_migrate_taxonomy',
'migrate_plus.migration_group.farm_migrate_user',
];
foreach ($configurations as $name) {
\Drupal::configFactory()->getEditable($name)->delete();
}
// Uninstall the migrate_drupal module.
if (\Drupal::service('module_handler')->moduleExists('migrate_drupal')) {
\Drupal::service('module_installer')->uninstall(['migrate_drupal']);
}
}

View File

@@ -0,0 +1,116 @@
<?php
namespace Drupal\farm_migrate\Plugin\migrate\process;
use Drupal\Component\Uuid\Uuid;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\MigrateSkipRowException;
use Drupal\migrate\Row;
use Drupal\migrate_plus\Plugin\migrate\process\EntityLookup;
/**
* This plugin looks for existing asset entities.
*
* Lookups are performed on multiple fields to find the asset, in the following
* order:
*
* - UUID
* - ID tag
* - Name
* - ID (primary key)
*
* @codingStandardsIgnoreStart
*
* Example usage:
* @code
* destination:
* plugin: 'entity:log'
* process:
* asset:
* plugin: asset_lookup
* source: asset
* @endcode
* @codingStandardsIgnoreEnd
*
* @MigrateProcessPlugin(
* id = "asset_lookup",
* handle_multiples = FALSE
* )
*/
class AssetLookup extends EntityLookup {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
// Hard-code the entity type.
$this->configuration['entity_type'] = 'asset';
// If no bundle was specified, add all bundles.
if (empty($this->configuration['bundle'])) {
$asset_types = $this->entityTypeManager->getStorage('asset_type')->loadMultiple();
foreach ($asset_types as $bundle => $asset_type) {
$this->configuration['bundle'][] = $bundle;
}
}
// Ignore case sensitivity.
$this->configuration['ignore_case'] = TRUE;
// Delegate to the parent entity_lookup plugin.
return parent::transform($value, $migrate_executable, $row, $destination_property);
}
/**
* {@inheritdoc}
*/
protected function query($value) {
// Trim the value.
$value = trim($value);
// If the value is empty, return NULL.
if (empty($value)) {
return NULL;
}
// We are going to attempt to look up the asset via multiple fields. If one
// lookup fails, we will try the next, until all options are exhausted.
$results = [];
// First, if the value is a valid UUID, attempt a UUID lookup.
if (Uuid::isValid($value)) {
$this->lookupValueKey = 'uuid';
$results = parent::query($value);
}
// If there are no results, try a lookup by ID tag.
if (empty($results)) {
$this->lookupValueKey = 'id_tag';
$results = parent::query($value);
}
// If there are no results, try a lookup by name.
if (empty($results)) {
$this->lookupValueKey = 'name';
$results = parent::query($value);
}
// If there are no results, and the value is a positive integer, try a
// lookup by asset ID.
if (empty($results) && is_numeric($value) && (int) $value == $value && (int) $value > 0) {
$this->lookupValueKey = 'id';
$results = parent::query($value);
}
// If there are still no results, throw an exception and skip the row.
if (empty($results)) {
throw new MigrateSkipRowException('Asset not found: ' . $value);
}
return $results;
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace Drupal\farm_migrate\Plugin\migrate\process;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
/**
* This plugin converts values to a boolean.
*
* @codingStandardsIgnoreStart
*
* Example usage:
* @code
* destination:
* plugin: 'entity:log'
* process:
* is_movement:
* plugin: boolean
* source: is_movement
* @endcode
* @codingStandardsIgnoreEnd
*
* @MigrateProcessPlugin(
* id = "boolean"
* )
*/
class Boolean extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
// If the value is NULL or an empty string, return NULL so that the field's
// default value will be used.
if (is_null($value) || trim($value) === '') {
return NULL;
}
// Use PHP's filter_var() with FILTER_VALIDATE_BOOLEAN constant.
return filter_var($value, FILTER_VALIDATE_BOOLEAN);
}
}

View File

@@ -0,0 +1,73 @@
<?php
namespace Drupal\farm_migrate\Plugin\migrate\process;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\MigrateSkipRowException;
use Drupal\migrate\Row;
use Drupal\migrate_plus\Plugin\migrate\process\EntityLookup;
/**
* This plugin looks for existing term entities.
*
* @codingStandardsIgnoreStart
*
* Example usage:
* @code
* destination:
* plugin: 'entity:log'
* process:
* asset:
* plugin: term_lookup
* source: term
* @endcode
* @codingStandardsIgnoreEnd
*
* @MigrateProcessPlugin(
* id = "term_lookup",
* handle_multiples = FALSE
* )
*/
class TermLookup extends EntityLookup {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
// Hard-code the entity type.
$this->configuration['entity_type'] = 'taxonomy_term';
// Ignore case sensitivity.
$this->configuration['ignore_case'] = TRUE;
// Delegate to the parent entity_lookup plugin.
return parent::transform($value, $migrate_executable, $row, $destination_property);
}
/**
* {@inheritdoc}
*/
protected function query($value) {
// Trim the value.
$value = trim($value);
// If the value is empty, return NULL.
if (empty($value)) {
return NULL;
}
// Attempt to look up the term with the parent query() method.
$results = parent::query($value);
// If there are no results, throw an exception and skip the row.
if (empty($results)) {
throw new MigrateSkipRowException('Term not found: ' . $value);
}
return $results;
}
}