Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
eef1fb1
Make error messages indicate the field.
laceysanderson Dec 19, 2023
e7f9b27
Add in 3 missing terms for the prepared chado test environment.
laceysanderson Dec 19, 2023
2f4b02b
Add a method to create content type + fields from yaml in the test en…
laceysanderson Dec 19, 2023
df005d3
Fix deprecation notice: preg_replace(): Passing null to parameter #2 …
laceysanderson Dec 19, 2023
cbfded2
Add a test for the publish service.
laceysanderson Dec 19, 2023
0e5090c
Added commented out debugging text.
laceysanderson Dec 19, 2023
02bd1c4
Confirmed the entities are inserted but field items are not yet.
laceysanderson Dec 19, 2023
cce095f
Remove changes to TripalPublish for easier merge.
laceysanderson Jan 8, 2024
ea7f0a4
Resolve small merge conflict.
laceysanderson Jan 8, 2024
b1d1f49
resolve merge conflict.
laceysanderson Jan 8, 2024
8d9e3a4
Do not replace token if the value returned is NULL.
laceysanderson Jan 8, 2024
d0602b7
Just debugging info.
laceysanderson Jan 8, 2024
717ac69
Fix small merge conflict.
laceysanderson Apr 2, 2024
ea4ad56
Merge branch '4.x' into tv4g1-issue1716-dataLeakBetweenPublishCalls
dsenalik Apr 3, 2024
256956c
init() initializes all class variables
dsenalik Apr 4, 2024
bf828bd
remove @debug lines
dsenalik Apr 4, 2024
4030cac
Revert changes to prepare sql for tests.
laceysanderson Apr 4, 2024
4e0d82f
Move createContentTypeFromConfig() testing helper into tripal test tr…
laceysanderson Apr 4, 2024
72e0cf3
Add missing terms.
laceysanderson Apr 4, 2024
ce23485
Ensure we have a session before retrieving it.
laceysanderson Apr 4, 2024
c62e5df
Remove non-working assertions.
laceysanderson Apr 4, 2024
99d14fb
Change how hasSession() is called
dsenalik Apr 5, 2024
c6ee0a8
Change how hasSession() is called elsewhere
dsenalik Apr 5, 2024
355dcea
assert for both publish counts
dsenalik Apr 6, 2024
70fa922
Forgot about the null contact getting published
dsenalik Apr 6, 2024
2700339
oops remove temp file
dsenalik Apr 7, 2024
0d5887e
because of null contact assert either 3 or 4
dsenalik Apr 8, 2024
816bf5c
Tripal Publish to TripalPublish for consistency
dsenalik Apr 8, 2024
e259a02
Merge branch '4.x' into tv4g1-issue1716-dataLeakBetweenPublishCalls
dsenalik Apr 13, 2024
9051076
Merge branch '4.x' into tv4g1-issue1716-dataLeakBetweenPublishCalls
dsenalik Apr 15, 2024
e24c5c6
Merge branch '4.x' into tv4g1-issue1716-dataLeakBetweenPublishCalls
laceysanderson Apr 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions tripal/src/Entity/TripalEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,10 +568,12 @@ public static function postLoad(EntityStorageInterface $storage, array &$entitie
// `tripal_load_listing` session variable to TRUE. If it is TRUE then
// we skip this. @todo: in the future if we want to only attach
// specific fields we can get more fancy.
$session = \Drupal::request()->getSession();
$is_listing = $session->get('tripal_load_listing');
if ($is_listing === TRUE) {
return;
if (\Drupal::request()->hasSession()) {
$session = \Drupal::request()->getSession();
$is_listing = $session->get('tripal_load_listing');
if ($is_listing === TRUE) {
return;
}
}

$entity_type_id = $storage->getEntityTypeId();
Expand Down
9 changes: 7 additions & 2 deletions tripal/src/ListBuilders/TripalEntityListBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ public function buildRow(EntityInterface $entity) {
* {@inheritdoc}
*/
public function load() {
$session = \Drupal::request()->getSession();
$session->set('tripal_load_listing', TRUE);
// Using the session helps speed up this listing by telling TripalEntity not
// to load ALL the fields.
if (\Drupal::request()->hasSession()) {
$session = \Drupal::request()->getSession();
$session->set('tripal_load_listing', TRUE);
}

try {
$entity_ids = $this->getEntityIds();
$entities = $this->storage->loadMultiple($entity_ids);
Expand Down
46 changes: 26 additions & 20 deletions tripal/src/Services/TripalPublish.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ class TripalPublish {
*
* @var integer $total_items
*/
private $total_items;
private $total_items = 0;

/**
* The number of items that have been handled so far. This must never
* be below 0 and never exceed $total_items;
*
* @var integer $num_handled
*/
private $num_handled;
private $num_handled = 0;

/**
* The interval when the job progress should be updated. Updating the job
Expand All @@ -33,7 +33,7 @@ class TripalPublish {
*
* @var integer $interval
*/
private $interval;
private $interval = 1;

/**
* The TripalJob object.
Expand All @@ -42,13 +42,6 @@ class TripalPublish {
*/
protected $job = NULL;

/**
* The TripalLogger object.
*
* @var \Drupal\tripal\Services\TripalLogger $logger
*/
protected $logger = NULL;

/**
* The id of the entity type (bundle)
*
Expand All @@ -73,15 +66,13 @@ class TripalPublish {
*/
protected $field_info = [];


/**
* Stores the bundle (entity type) object.
*
* @var \Drupal\tripal\Entity\TripalEntityType $entity_type
**/
protected $entity_type = NULL;


/**
* The TripalStorage object.
*
Expand Down Expand Up @@ -109,14 +100,21 @@ class TripalPublish {
*
* @var array $unsupported_fields
*/
protected $unsupported_fields;
protected $unsupported_fields = [];

/**
* Stores the last percentage that progress was reported.
*
* @var integer
*/
protected $reported;
protected $reported = 0;

/**
* The TripalLogger object.
*
* @var \Drupal\tripal\Services\TripalLogger $logger
*/
protected $logger = NULL;

/**
* Initializes the publisher service.
Expand All @@ -128,15 +126,20 @@ class TripalPublish {
*/
public function init($bundle, $datastore, $datastore_options = [], TripalJob $job = NULL) {

$this->bundle = $bundle;
$this->datastore = $datastore;
$this->job = $job;
// Initialize class variables that may persist between consecutive jobs
$this->total_items = 0;
$this->interval = 1;
$this->num_handled = 0;
$this->interval = 1;
$this->job = $job;
$this->bundle = $bundle;
$this->datastore = $datastore;
$this->field_info = [];
$this->entity_type = NULL;
$this->storage = NULL;
$this->required_types = [];
$this->unsupported_fields = [];
$this->reported = 0;


// Initialize the logger.
$this->logger = \Drupal::service('tripal.logger');
if ($job) {
Expand Down Expand Up @@ -298,6 +301,7 @@ protected function setFieldInfo() {
$field_info['prop_types'][$prop_type->getKey()] = $prop_type;
}
$this->field_info[$field_name] = $field_info;

}
}
}
Expand Down Expand Up @@ -473,7 +477,9 @@ protected function getEntityTitles($matches) {
$field = $this->field_info[$field_name]['instance'];
$main_prop = $field->mainPropertyName();
$value = $match[$field_name][$delta][$main_prop]['value']->getValue();
$entity_title = trim(preg_replace("/\[$field_name\]/", $value, $entity_title));
if ($value !== NULL) {
$entity_title = trim(preg_replace("/\[$field_name\]/", $value, $entity_title));
}
}
}
$titles[] = $entity_title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Drupal\Tests\BrowserTestBase;
use Drupal\file\Entity\File;
use Drupal\user\Entity\Role;
use Drupal\Core\Session;
use Drupal\Core\Url;

/**
Expand All @@ -27,6 +28,8 @@ class TripalRoutePermissionsTest extends BrowserTestBase {
* @group Tripal Permissions
*/
public function testTripalAdminPages() {
$this->assertTrue(\Drupal::request()->hasSession(),
'This test depends on having a session but for some reason there is not one available.');
$session = $this->getSession();

// The URLs to check with the key being the label expected in the
Expand Down Expand Up @@ -108,6 +111,8 @@ public function testTripalAdminPages() {
* @group Tripal Jobs
*/
public function testTripalJobPages() {
$this->assertTrue(\Drupal::request()->hasSession(),
'This test depends on having a session but for some reason there is not one available.');
$session = $this->getSession();

// The job to use for testing.
Expand Down Expand Up @@ -173,6 +178,8 @@ public function testTripalJobPages() {
* @group Tripal Dashboard
*/
public function testTripalDashboardPages() {
$this->assertTrue(\Drupal::request()->hasSession(),
'This test depends on having a session but for some reason there is not one available.');
$session = $this->getSession();

// The URLs to check.
Expand Down Expand Up @@ -232,6 +239,8 @@ public function testTripalDashboardPages() {
* @group Tripal Content
*/
public function testTripalContentPages() {
$this->assertTrue(\Drupal::request()->hasSession(),
'This test depends on having a session but for some reason there is not one available.');
$session = $this->getSession();

// Create a Content Type + Entity for this test.
Expand Down Expand Up @@ -345,6 +354,8 @@ public function testTripalContentPages() {
*/
public function testAdminTripalDataFilesPages() {
$session = $this->getSession();
$this->assertTrue(\Drupal::request()->hasSession(),
'This test depends on having a session but for some reason there is not one available.');

// The URLs to check.
$urls = [
Expand Down Expand Up @@ -398,6 +409,8 @@ public function testAdminTripalDataFilesPages() {
* @group Tripal Data Files
*/
public function testTripalDataFilesPages() {
$this->assertTrue(\Drupal::request()->hasSession(),
'This test depends on having a session but for some reason there is not one available.');
$session = $this->getSession();

$permission = 'manage tripal files';
Expand Down Expand Up @@ -476,6 +489,8 @@ public function testTripalDataFilesPages() {
* @group Tripal Term Configuration
*/
public function testTripalTermConfigPages() {
$this->assertTrue(\Drupal::request()->hasSession(),
'This test depends on having a session but for some reason there is not one available.');
$session = $this->getSession();

// The URLs to check.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* @group Tripal
* @group Tripal Services
* @group Tripal Publish
* @group TripalPublish
*/
class TripalTokenParserTest extends TripalTestBrowserBase {

Expand Down
74 changes: 74 additions & 0 deletions tripal/tests/src/Traits/TripalTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,78 @@ public function createTripalContentType($values = []) {

return $entity_type_obj;
}

/**
* Creates a content type and associated fields using the
* tripalentitytype_collection and tripalfield_collection configuration.
*
* @param string $config_id
* The id from a tripalentitytype_collection config file. Fields will also be
* added if there is a tripalfield_collection with this same id.
* @param string $content_type_id
* The id of the content type to create. It must exist in the specified YAML.
*
* @return integer
* The return value is 1 if everything went well and 2 if the content type
* was created but the fields were not due to a missing config with matching
* id. If the content type was not created then PHPUnit asserts fail.
*/
protected function createContentTypeFromConfig($config_id, $content_type_id, $createTerms = FALSE) {
$content_type_service = \Drupal::service('tripal.tripalentitytype_collection');
$field_service = \Drupal::service('tripal.tripalfield_collection');
$config_factory = \Drupal::service('config.factory');
$idsmanager = \Drupal::service('tripal.collection_plugin_manager.idspace');

// FIRST THE CONTENT TYPE.
$yaml_contentTypes = 'tripal.tripalentitytype_collection.' . $config_id;

// check that config is installed.
$config = $config_factory->get($yaml_contentTypes);
$this->assertIsObject($config,
'You need to have called $this->installConfig for the module containing the configuration for the content type you want to use in this test.');
$specific_config = $config->get('content_types');
$this->assertIsArray($specific_config,
'You need to have called $this->installConfig for the module containing the configuration for the content type you want to use in this test.');

foreach ($specific_config as $content_type) {

if (!array_key_exists('id', $content_type) OR $content_type['id'] != $content_type_id) {
continue;
}

list($termIdSpace, $termAccession) = explode(':', $content_type['term']);
$idspace = $idsmanager->loadCollection($termIdSpace);
$this->assertIsObject($idspace, "We were not able to get the id space " . $termIdSpace);
$term = $idspace->getTerm($termAccession);
$this->assertIsObject($term, "We were not able to get the term " . $content_type['term']);
$content_type['term'] = $term;

// Add the content type
$content_type = $content_type_service->createContentType($content_type);
$this->assertIsObject($content_type,
"We were not able to create the $content_type_id content type in the testing environment.");
}

// NOW THE FIELDS
$yaml_fields = 'tripal.tripalfield_collection.' . $config_id;

// check that config is installed.
$config = $config_factory->get($yaml_fields);
if (!is_object($config)) {
return 2;
}
$specific_config = $config->get('fields');
if (!is_array($specific_config)) {
return 2;
}

foreach ($specific_config as $field) {
if (array_key_exists('content_type', $field) AND $field['content_type'] === $content_type_id) {
// @debug print "\nAdding Field to Bundle: " . print_r($field,TRUE);
$field_service->addBundleField($field);
}
}

return 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ protected function setUp(): void {
* @group chado-install-form
*/
public function testLoadInstallerForm() {
$this->assertTrue(\Drupal::request()->hasSession(),
'This test depends on having a session but for some reason there is not one available.');
$session = $this->getSession();

// Check that the page opens.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class TripalChadoRoutePermissionsTest extends BrowserTestBase {
*
*/
public function testTripalChadoAdminPages() {
$this->assertTrue(\Drupal::request()->hasSession(),
'This test depends on having a session but for some reason there is not one available.');
$session = $this->getSession();

// The URLs to check with the key being the label expected in the
Expand Down
2 changes: 1 addition & 1 deletion tripal_chado/tests/src/Kernel/ChadoTestKernelBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use Drupal\Tests\tripal\Kernel\TripalTestKernelBase;
use Drupal\tripal\TripalDBX\TripalDbx;
use Drupal\tripal\TripalVocabTerms\TripalTerm;
use Drupal\tripal_chado\Database\ChadoConnection;
use Drupal\Tests\tripal_chado\Traits\ChadoTestTrait;

Expand Down Expand Up @@ -93,5 +94,4 @@ protected function setUp() :void {
->save();
}
}

}
Loading