Skip to content

Commit

Permalink
HERB-101 Drupal 10.x upgrade rector changes (guide step 3)
Browse files Browse the repository at this point in the history
  • Loading branch information
camilocodes committed Dec 13, 2024
1 parent 56c4947 commit a77ed2b
Show file tree
Hide file tree
Showing 20 changed files with 614 additions and 581 deletions.
1,103 changes: 567 additions & 536 deletions build/composer.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion custom/modules/herbarium/herbarium_core.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ name: Herbarium Core
type: module
description: Herbarium Core Functions
core: 8.x
core_version_requirement: ^8 || ^9
core_version_requirement: ^9 || ^10
package: Herbarium
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: 'Herbarium Specimen'
description: 'Herbarium Specimen'
type: module
core: 8.x
core_version_requirement: ^8 || ^9
core_version_requirement: ^9 || ^10
dependencies:
- chosen
- datetime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @file
* Add style to feature pages.
*/

use Drupal\core\Database\Database;
use Drupal\Core\Entity\EntityInterface;
use Drupal\node\Entity\Node;
use Drupal\taxonomy\Entity\Term;
Expand Down Expand Up @@ -169,7 +169,7 @@ function _herbarium_specimen_generate_specimen_surrogates_batch($nid, $file_path
* are possible values.
*/
function _herbarium_specimen_manually_remove_broken_file_reference($nid, $field_name) {
$query = \Drupal\core\Database\Database::getConnection()->select("node__$field_name", 'n');
$query = Database::getConnection()->select("node__$field_name", 'n');
$query->fields('n', ["{$field_name}_target_id"]);
$query->condition('n.entity_id', $nid);
$result = $query->execute();
Expand All @@ -178,19 +178,19 @@ function _herbarium_specimen_manually_remove_broken_file_reference($nid, $field_
while ($row = $result->fetchAssoc()) {
$fid = $row["{$field_name}_target_id"];

$deleted = \Drupal\core\Database\Database::getConnection()->delete("node__$field_name")
$deleted = Database::getConnection()->delete("node__$field_name")
->condition('entity_id', $nid)
->execute();

$deleted = \Drupal\core\Database\Database::getConnection()->delete("node_revision__$field_name")
$deleted = Database::getConnection()->delete("node_revision__$field_name")
->condition('entity_id', $nid)
->execute();

$deleted = \Drupal\core\Database\Database::getConnection()->delete('file_managed')
$deleted = Database::getConnection()->delete('file_managed')
->condition('fid', $fid)
->execute();

$deleted = \Drupal\core\Database\Database::getConnection()->delete('file_usage')
$deleted = Database::getConnection()->delete('file_usage')
->condition('fid', $fid)
->execute();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Herbarium Specimen Bulk Import
type: module
description: Herbarium Specimen Bulk Import
core: 8.x
core_version_requirement: ^8 || ^9
core_version_requirement: ^9 || ^10
package: Herbarium
dependencies:
- migrate_source_csv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @file
* Contains herbarium_core.module.
*/

use Drupal\core\Database\Database;
use Drupal\Core\Link;
use Drupal\taxonomy\Entity\Term;

Expand All @@ -19,7 +19,7 @@ use Drupal\taxonomy\Entity\Term;
*/
function _herbarium_specimen_bulk_import_get_migration_destinations($id) {
$table_name = "migrate_map_$id";
return \Drupal\core\Database\Database::getConnection()->query("SELECT destid1 FROM $table_name", [
return Database::getConnection()->query("SELECT destid1 FROM $table_name", [
':migrate_id' => $table_name,
]);
}
Expand Down Expand Up @@ -659,7 +659,7 @@ function _herbarium_specimen_validate_accession_id($data) {
$values = \Drupal::entityQuery('node')
->condition('type', 'herbarium_specimen')
->condition('field_dwc_record_number', $data)
->execute();
->accessCheck(FALSE)->execute();
$id_exists = !empty($values);

return !$id_exists;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class MigrateEvent implements EventSubscriberInterface {
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
public static function getSubscribedEvents(): array {
$events[MigrateEvents::PREPARE_ROW][] = ['onPrepareRow', 0];
$events[CoreMigrateEvents::POST_ROW_SAVE][] = ['onPostRowSave', 0];
return $events;
Expand Down Expand Up @@ -198,7 +198,7 @@ public function taxTermExists($value, $field, $vocabulary) {
$query = \Drupal::entityQuery('taxonomy_term');
$query->condition('vid', $vocabulary);
$query->condition($field, $value);
$tids = $query->execute();
$tids = $query->accessCheck(FALSE)->execute();
if (!empty($tids)) {
foreach ($tids as $tid) {
return $tid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $migratio
count($rows) + 1,
$node->get('field_dwc_record_number')->value,
Link::createFromRoute($node->getTitle(), 'entity.node.canonical', ['node' => $target->destid1]),
render($collectors),
\Drupal::service('renderer')->render($collectors),
$node->get('field_dwc_eventdate')->value,
],
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Herbarium Specimen CSV Export
type: module
description: Herbarium Specimen CSV Export
core: 8.x
core_version_requirement: ^8 || ^9
core_version_requirement: ^9 || ^10
package: Herbarium
dependencies:
- herbarium_core
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function getAllNodesCsv() {
$query = \Drupal::entityQuery('node')
->condition('status', NodeInterface::PUBLISHED)
->condition('type', 'herbarium_specimen');
$result = $query->execute();
$result = $query->accessCheck(FALSE)->execute();

return $this->serveFile(
implode('|', $result),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: 'Herbarium Specimen Archival Master LTS'
description: 'Herbarium Specimen Archival Master LTS'
type: module
core: 8.x
core_version_requirement: ^8 || ^9
core_version_requirement: ^9 || ^10
dependencies:
- herbarium_core
- herbarium_specimen
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Drupal\core\Database\Database;

/**
* @file
* Features related to herbarium_specimen_lts.
Expand Down Expand Up @@ -64,12 +66,12 @@ function _herbarium_specimen_lts_store_new_image($nid, $file_path, $commit_messa
*/
function _herbarium_specimen_lts_set_file_status($file_path, $status) {
$sql = 'UPDATE ' . HERBARIUM_SPECIMEN_LTS_QUEUE_TABLE . " SET status=$status WHERE file='$file_path'";
return \Drupal\core\Database\Database::getConnection()->query($sql);
return Database::getConnection()->query($sql);
}

function _herbarium_specimen_lts_regen_set_file_status($nid, $status) {
$sql = 'UPDATE ' . HERBARIUM_SPECIMEN_LTS_REGEN_TABLE . " SET status=$status WHERE nid='$nid'";
return \Drupal\core\Database\Database::getConnection()->query($sql);
return Database::getConnection()->query($sql);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion custom/modules/unb_herbarium/unb_herbarium.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: 'UNB CMH custom features'
package: 'UNB Herbarium'
type: module
core: 8.x
core_version_requirement: ^8 || ^9
core_version_requirement: ^9 || ^10
dependencies:
- block
- contact
Expand Down
18 changes: 9 additions & 9 deletions custom/modules/unb_herbarium/unb_herbarium.install
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function unb_herbarium_update_8004(&$sandbox) {
if (!isset($sandbox['total'])) {
$nids = \Drupal::entityQuery('node')
->condition('type', 'herbarium_specimen')
->execute();
->accessCheck(FALSE)->execute();
$sandbox['total'] = count($nids);
$sandbox['current'] = 0;
}
Expand All @@ -80,7 +80,7 @@ function unb_herbarium_update_8004(&$sandbox) {
$nids = \Drupal::entityQuery('node')
->condition('type', 'herbarium_specimen')
->range($sandbox['current'], $sandbox['current'] + $nodes_per_batch)
->execute();
->accessCheck(FALSE)->execute();

foreach($nids as $nid) {
$node = Node::load($nid);
Expand Down Expand Up @@ -109,7 +109,7 @@ function unb_herbarium_update_8005(&$sandbox) {
// Get total number of items we will need to update.
$count_query = \Drupal::entityQuery('node')
->condition('type', $content_type);
$count_nids = $count_query->execute();
$count_nids = $count_query->accessCheck(FALSE)->execute();
$num_nodes = count($count_nids);

// Set up the sandbox with initial values.
Expand All @@ -122,7 +122,7 @@ function unb_herbarium_update_8005(&$sandbox) {
$query = \Drupal::entityQuery('node')
->condition('type', $content_type)
->range($sandbox['progress'], $sandbox['progress'] + $batch_size);
$nids = $query->execute();
$nids = $query->accessCheck(FALSE)->execute();

// Perform field update operation.
foreach ($nids as $nid) {
Expand Down Expand Up @@ -160,7 +160,7 @@ function unb_herbarium_update_8006(&$sandbox) {
// Get total number of items we will need to update.
$count_query = \Drupal::entityQuery('node')
->condition('type', $content_type);
$count_nids = $count_query->execute();
$count_nids = $count_query->accessCheck(FALSE)->execute();
$num_nodes = count($count_nids);

// Set up the sandbox with initial values.
Expand All @@ -173,7 +173,7 @@ function unb_herbarium_update_8006(&$sandbox) {
$query = \Drupal::entityQuery('node')
->condition('type', $content_type)
->range($sandbox['progress'], $sandbox['progress'] + $batch_size);
$nids = $query->execute();
$nids = $query->accessCheck(FALSE)->execute();

// Perform field update operation.
foreach ($nids as $nid) {
Expand Down Expand Up @@ -211,7 +211,7 @@ function unb_herbarium_update_8007(&$sandbox) {
// Get total number of items we will need to update.
$count_query = \Drupal::entityQuery('node')
->condition('type', $content_type);
$count_nids = $count_query->execute();
$count_nids = $count_query->accessCheck(FALSE)->execute();
$num_nodes = count($count_nids);

// Set up the sandbox with initial values.
Expand All @@ -224,7 +224,7 @@ function unb_herbarium_update_8007(&$sandbox) {
$query = \Drupal::entityQuery('node')
->condition('type', $content_type)
->range($sandbox['progress'], $sandbox['progress'] + $batch_size);
$nids = $query->execute();
$nids = $query->accessCheck(FALSE)->execute();

// Perform field update operation.
foreach ($nids as $nid) {
Expand Down Expand Up @@ -260,7 +260,7 @@ function unb_herbarium_update_8008(&$sandbox) {
// Get total number of items we will need to update.
$count_query = \Drupal::entityQuery('node')
->condition('type', $content_type);
$count_nids = $count_query->execute();
$count_nids = $count_query->accessCheck(FALSE)->execute();
$num_nodes = count($count_nids);

// Set up the sandbox with initial values.
Expand Down
16 changes: 8 additions & 8 deletions custom/modules/unb_herbarium/unb_herbarium.module
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @file
* Contains unb_herbarium.module.
*/

use Drupal\core\Database\Database;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Link;
use Drupal\Core\Routing\RouteMatchInterface;
Expand Down Expand Up @@ -33,7 +33,7 @@ function unb_herbarium_help($route_name, RouteMatchInterface $route_match) {
* Implements hook_theme_registry_alter().
*/
function unb_herbarium_theme_registry_alter(&$theme_registry) {
$theme_registry['taxonomy_term']['path'] = drupal_get_path('module', 'unb_herbarium') . '/templates';
$theme_registry['taxonomy_term']['path'] = \Drupal::service('extension.list.module')->getPath('unb_herbarium') . '/templates';
}

/**
Expand All @@ -49,7 +49,7 @@ function unb_herbarium_theme($existing, $type, $theme, $path) {
'output' => NULL,
],
'template' => 'node--herbarium-specimen',
'path' => drupal_get_path('module', 'unb_herbarium') . '/templates',
'path' => \Drupal::service('extension.list.module')->getPath('unb_herbarium') . '/templates',
'base hook' => 'node__herbarium_specimen',
],
];
Expand Down Expand Up @@ -429,7 +429,7 @@ function unb_herbarium_search_api_autocomplete_suggestions_alter(array &$suggest
* The vocabulary ID.
*/
function _unb_herbarium_create_tax_term_if_not_exists($name, $vid) {
if ($terms = taxonomy_term_load_multiple_by_name($name, $vid)) {
if ($terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadByProperties(['name' => $name, 'vid' => $vid])) {
$term = reset($terms);
}
else {
Expand All @@ -455,7 +455,7 @@ function _unb_herbarium_get_nid_from_accession_id($accession_id) {
$nids = \Drupal::entityQuery('node')
->condition('type', 'herbarium_specimen')
->condition('field_dwc_record_number', $accession_id)
->execute();
->accessCheck(FALSE)->execute();
if (!empty($nids)) {
foreach ($nids as $nid) {
return $nid;
Expand Down Expand Up @@ -490,7 +490,7 @@ function _unb_herbarium_resave_herb_sample_nid($nid) {
*/
function _unb_herbarium_get_all_bulk_import_migration_tables() {
$sql = "SHOW TABLES LIKE 'migrate_map_cmh_herb_import_standard_%'";
$results = \Drupal\core\Database\Database::getConnection()->query($sql);
$results = Database::getConnection()->query($sql);
return $results->fetchCol();
}

Expand All @@ -505,7 +505,7 @@ function _unb_herbarium_get_all_bulk_import_migration_tables() {
*/
function _unb_herbarium_get_bulk_import_migration_nids($migration_table_name) {
$sql_ids = "select destid1 from $migration_table_name";
$id_results = \Drupal\core\Database\Database::getConnection()->query($sql_ids);
$id_results = Database::getConnection()->query($sql_ids);
return $id_results->fetchCol();
}

Expand Down Expand Up @@ -537,7 +537,7 @@ function _unb_herbarium_resave_all_bulk_migration_nodes() {
foreach ($nids_to_process as $migration_nid) {
if (!empty($migration_nid) && $migration_nid > $last_resaved_node) {
// Ensure the node still exists.
$values = \Drupal::entityQuery('node')->condition('nid', $migration_nid)->execute();
$values = \Drupal::entityQuery('node')->condition('nid', $migration_nid)->accessCheck(FALSE)->execute();
if(!empty($values)) {
echo("Resaving NID#$migration_nid\n");
_unb_herbarium_resave_herb_sample_nid($migration_nid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MigrateEvent implements EventSubscriberInterface {
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
public static function getSubscribedEvents(): array {
$events[MigrateEvents::PREPARE_ROW][] = ['onPrepareRow', 0];
return $events;
}
Expand Down Expand Up @@ -499,7 +499,7 @@ public function taxtermExists($value, $field, $vocabulary) {
$query = \Drupal::entityQuery('taxonomy_term');
$query->condition('vid', $vocabulary);
$query->condition($field, $value);
$tids = $query->execute();
$tids = $query->accessCheck(FALSE)->execute();
if (!empty($tids)) {
foreach ($tids as $tid) {
return $tid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public function taxtermExists($value, $field, $vocabulary) {
$query = \Drupal::entityQuery('taxonomy_term');
$query->condition('vid', $vocabulary);
$query->condition($field, $value);
$tids = $query->execute();
$tids = $query->accessCheck(FALSE)->execute();
if (!empty($tids)) {
foreach ($tids as $tid) {
return $tid;
Expand Down Expand Up @@ -334,7 +334,7 @@ public function checkStubTermExists($name, $parent = 0) {
$query->condition('vid', 'herbarium_specimen_taxonomy');
$query->condition('name', $name);

$tids = $query->execute();
$tids = $query->accessCheck(FALSE)->execute();
if (!empty($tids)) {
foreach ($tids as $tid) {
$storage = \Drupal::service('entity_type.manager')->getStorage('taxonomy_term');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: UNB Herbarium CSV Import
type: module
description: Migratation import from UNB Herbarium filemaker CSV export to D8 Sample node content.
core: 8.x
core_version_requirement: ^8 || ^9
core_version_requirement: ^9 || ^10
package: Migration
dependencies:
- migrate_source_csv
Expand Down
2 changes: 1 addition & 1 deletion custom/themes/0_unbherbarium_ca/unbherbarium_ca.info.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
core: 8.x
core_version_requirement: ^8 || ^9
core_version_requirement: ^9 || ^10
type: theme
base theme: bootstrap

Expand Down
2 changes: 1 addition & 1 deletion custom/themes/0_unbherbarium_ca/unbherbarium_ca.theme
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function unbherbarium_ca_preprocess_menu_local_task(&$variables) {
$query = \Drupal::entityQuery('node')
->condition('nid', $node_id)
->condition('type', $content_type)
->execute();
->accessCheck(FALSE)->execute();

if (!empty($query)) {
$variables['link']['#title'] = t('Specimen Data');
Expand Down

0 comments on commit a77ed2b

Please sign in to comment.