Created
September 19, 2025 20:38
-
-
Save paul121/bef27d04a1eab16b90e3bcea2926074d to your computer and use it in GitHub Desktop.
Rothamsted File Migration Query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $plan_storage = \Drupal::entityTypeManager()->getStorage('plan'); | |
| $total_plans = $plan_storage->getQuery() | |
| ->accessCheck(FALSE) | |
| ->condition('type', 'rothamsted_experiment') | |
| ->exists('column_descriptors') | |
| ->sort("id") | |
| ->count() | |
| ->execute(); | |
| print("--- begin --- \n"); | |
| print("\n"); | |
| print(" Total plans w/ uploaded column data: $total_plans -- \n"); | |
| print("\n"); | |
| $plan_query = $plan_storage->getQuery() | |
| ->accessCheck(FALSE) | |
| ->condition('type', 'rothamsted_experiment') | |
| ->exists('column_descriptors'); | |
| $column_group = $plan_query->andConditionGroup() | |
| ->condition('file.%delta', 3, '>') | |
| ->condition('file.%delta.entity.filename', 'columns.csv', 'ENDS_WITH'); | |
| $column_level_group = $plan_query->andConditionGroup() | |
| ->condition('file.%delta', 3, '>') | |
| ->condition('file.%delta.entity.filename', 'levels.csv', 'ENDS_WITH'); | |
| $plot_attr_group = $plan_query->andConditionGroup() | |
| ->condition('file.%delta', 3, '>') | |
| ->condition('file.%delta.entity.filename', 'attributes.csv', 'ENDS_WITH'); | |
| $geojson_group = $plan_query->andConditionGroup() | |
| ->condition('file.%delta', 3, '>') | |
| ->condition('file.%delta.entity.filename', 'plots.geojson', 'ENDS_WITH'); | |
| $dup_group = $plan_query->orConditionGroup() | |
| ->condition('file.entity.filename', '_0.csv', 'ENDS_WITH') | |
| ->condition('file.entity.filename', '_1.csv', 'ENDS_WITH') | |
| ->condition('file.entity.filename', '_2.csv', 'ENDS_WITH') | |
| ->condition('file.entity.filename', '_3.csv', 'ENDS_WITH') | |
| ->condition('file.entity.filename', '_4.csv', 'ENDS_WITH'); | |
| $or_group = $plan_query->orConditionGroup() | |
| ->condition($column_group) | |
| ->condition($column_level_group) | |
| ->condition($plot_attr_group) | |
| ->condition($geojson_group) | |
| ->condition($dup_group); | |
| $plans = $plan_query | |
| ->condition($or_group) | |
| ->sort("id") | |
| ->execute(); | |
| $count = count($plans); | |
| print("\n"); | |
| print(" -- Plans with multiple variable/geojson files: $count -- \n"); | |
| print("\n"); | |
| /** @var \Drupal\plan\Entity\PlanInterface $plan */ | |
| foreach ($plan_storage->loadMultiple($plans) as $plan) { | |
| $link = $plan->toUrl()->setAbsolute()->toString(); | |
| print("#{$plan->id()} -- {$plan->label()}: $link\n"); | |
| } | |
| print("\n"); | |
| print("\n"); | |
| $plan_query2 = $plan_storage->getQuery() | |
| ->accessCheck(FALSE) | |
| ->condition('id', array_values($plans), 'NOT IN') | |
| ->condition('type', 'rothamsted_experiment') | |
| ->exists('column_descriptors'); | |
| $column_group = $plan_query->andConditionGroup() | |
| ->condition('file.%delta.entity.filename', 'columns.csv', 'ENDS_WITH'); | |
| $column_level_group = $plan_query->andConditionGroup() | |
| ->condition('file.%delta.entity.filename', 'column-levels.csv', 'ENDS_WITH'); | |
| $plot_attr_group = $plan_query->andConditionGroup() | |
| ->condition('file.%delta.entity.filename', 'plot-attributes.csv', 'ENDS_WITH'); | |
| $plans2 = $plan_query2 | |
| ->condition($column_group) | |
| ->condition($column_level_group) | |
| ->condition($plot_attr_group) | |
| ->sort("id") | |
| ->execute(); | |
| print("\n"); | |
| $count = count($plans2); | |
| print(" -- Good plans: $count -- \n"); | |
| print("\n"); | |
| /** @var \Drupal\plan\Entity\PlanInterface $plan */ | |
| foreach ($plan_storage->loadMultiple($plans2) as $plan) { | |
| $link = $plan->toUrl()->setAbsolute()->toString(); | |
| print("#{$plan->id()} -- {$plan->label()}: $link\n"); | |
| } | |
| print("--- end --- \n"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment