Last active
December 11, 2023 18:02
-
-
Save laceysanderson/898e939aff1e5c38452aa1f04990e80c to your computer and use it in GitHub Desktop.
Inserting test data vie drush:php-cli
This file contains 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
// First get access to the chado database connection. | |
$chado = \Drupal::service('tripal_chado.database'); | |
// Create a function to make random strings. | |
$randomString = function($len = 10) {$word = array_merge(range('a', 'z'), range('A', 'Z')); shuffle($word); return substr(implode($word), 0, $len);}; | |
// Insert a set number of organisms | |
$total = 5; | |
$subspecies = 2868; // cvterm_id | |
for ($i = 1; $i <= $total; $i++) { | |
$values = [ | |
'genus' => 'Tripalus', | |
'species' => 'databasica', | |
'type_id' => $subspecies, | |
'infraspecific_name' => $randomString(25), | |
'common_name' => 'Tripal ' . $i, | |
]; | |
$values['abbreviation'] = 'T. databasica ssp. ' . $values['infraspecific_name']; | |
$chado->insert('1:organism') | |
->fields($values) | |
->execute(); | |
} | |
// Look at them all. | |
$chado->query("SELECT * FROM {1:organism}")->fetchAll(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment