Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDSS-1337: Track news sharing imported content #478

Merged
merged 7 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ dependencies:
config:
- field.field.node.stanford_news.layout_builder__layout
- field.field.node.stanford_news.stanford_intranet__access
- field.field.node.stanford_news.su_sdss_imported_news_sharing
- field.field.node.stanford_news.su_metatags
- field.field.node.stanford_news.su_news_banner
- field.field.node.stanford_news.su_news_banner_media_caption
Expand Down Expand Up @@ -189,7 +190,9 @@ content:
weight: 4
region: content
settings:
view_mode: default
preview_view_mode: default
form_display_mode: default
nesting_depth: 0
require_layouts: 1
empty_message: ''
Expand Down Expand Up @@ -247,14 +250,6 @@ content:
collapsed: false
revision: false
removed_reference: keep
auto_open: true
allow_edit: true
hide_fieldset: false
hide_title: false
config_labels_button: _none
labels: { }
add_existing_widget: autocomplete
auto_open_edit_form: false
third_party_settings:
change_labels:
add_another: 'Add another Media Contact'
Expand Down Expand Up @@ -390,6 +385,7 @@ hidden:
sticky: true
su_news_dek: true
su_sdss_import_source: true
su_sdss_imported_news_sharing: true
uid: true
unpublish_on: true
url_redirects: true
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dependencies:
- core.base_field_override.node.stanford_news.title
- field.field.node.stanford_news.layout_builder__layout
- field.field.node.stanford_news.stanford_intranet__access
- field.field.node.stanford_news.su_sdss_imported_news_sharing
- field.field.node.stanford_news.su_metatags
- field.field.node.stanford_news.su_news_banner
- field.field.node.stanford_news.su_news_banner_media_caption
Expand Down Expand Up @@ -625,4 +626,5 @@ hidden:
stanford_intranet__access: true
su_metatags: true
su_news_source: true
su_sdss_imported_news_sharing: true
su_shared_tags: true
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dependencies:
- core.entity_view_mode.node.search_indexing
- field.field.node.stanford_news.layout_builder__layout
- field.field.node.stanford_news.stanford_intranet__access
- field.field.node.stanford_news.su_sdss_imported_news_sharing
- field.field.node.stanford_news.su_metatags
- field.field.node.stanford_news.su_news_banner
- field.field.node.stanford_news.su_news_banner_media_caption
Expand Down Expand Up @@ -136,6 +137,7 @@ hidden:
su_metatags: true
su_news_dek: true
su_sdss_import_source: true
su_sdss_imported_news_sharing: true
su_sdss_media_contacts: true
su_sdss_media_mention: true
su_sdss_news_banner_caption: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dependencies:
- core.entity_view_mode.node.stanford_card
- field.field.node.stanford_news.layout_builder__layout
- field.field.node.stanford_news.stanford_intranet__access
- field.field.node.stanford_news.su_sdss_imported_news_sharing
- field.field.node.stanford_news.su_metatags
- field.field.node.stanford_news.su_news_banner
- field.field.node.stanford_news.su_news_banner_media_caption
Expand Down Expand Up @@ -183,6 +184,7 @@ hidden:
su_news_components: true
su_news_dek: true
su_sdss_import_source: true
su_sdss_imported_news_sharing: true
su_sdss_media_contacts: true
su_sdss_media_mention: true
su_sdss_news_banner_caption: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dependencies:
- core.entity_view_mode.node.teaser
- field.field.node.stanford_news.layout_builder__layout
- field.field.node.stanford_news.stanford_intranet__access
- field.field.node.stanford_news.su_sdss_imported_news_sharing
- field.field.node.stanford_news.su_metatags
- field.field.node.stanford_news.su_news_banner
- field.field.node.stanford_news.su_news_banner_media_caption
Expand Down Expand Up @@ -222,6 +223,7 @@ hidden:
su_news_source: true
su_news_topics: true
su_sdss_import_source: true
su_sdss_imported_news_sharing: true
su_sdss_media_contacts: true
su_sdss_media_mention: true
su_sdss_news_banner_caption: true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
uuid: bec5aa1e-8cb5-4e3f-9673-3198d96ca964
langcode: en
status: true
dependencies:
config:
- field.storage.node.su_sdss_imported_news_sharing
- node.type.stanford_news
id: node.stanford_news.su_sdss_imported_news_sharing
field_name: su_sdss_imported_news_sharing
entity_type: node
bundle: stanford_news
label: 'Imported via News Sharing'
description: 'This content was imported from another site through News Sharing.'
required: false
translatable: true
default_value: { }
default_value_callback: ''
settings:
on_label: 'Yes'
off_label: 'No'
field_type: boolean
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
uuid: 9e91a7b2-54be-4154-b251-b49040727100
langcode: en
status: true
dependencies:
module:
- node
id: node.su_sdss_imported_news_sharing
field_name: su_sdss_imported_news_sharing
entity_type: node
type: boolean
settings: { }
module: core
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ source:
stanford_minimal_html: stanford_minimal_html
type: stanford_news
image_path: 'public://media/sdss_news_sharing/'
imported_via_news_sharing: 1
process:
type: constants/type
su_sdss_imported_news_sharing: constants/imported_via_news_sharing
title: title
image_file:
-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,44 @@ display:
plugin_id: bundle
value:
stanford_news: stanford_news
su_sdss_imported_news_sharing_value:
id: su_sdss_imported_news_sharing_value
table: node__su_sdss_imported_news_sharing
field: su_sdss_imported_news_sharing_value
relationship: none
group_type: group
admin_label: ''
plugin_id: boolean
operator: '!='
value: '1'
group: 1
exposed: false
expose:
operator_id: ''
label: ''
description: ''
use_operator: false
operator: ''
operator_limit_selection: false
operator_list: { }
identifier: ''
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
style:
type: serializer
row:
Expand Down
81 changes: 78 additions & 3 deletions docroot/profiles/sdss/sdss_profile/sdss_profile.install
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

use Drupal\Core\DrupalKernel;
use Drupal\Core\Menu\MenuTreeParameters;
use Drupal\Core\Site\Settings;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\node\NodeInterface;
Expand Down Expand Up @@ -755,8 +754,7 @@ function _sdss_profile_reset_node_changed_time(NodeInterface $node, int $changed
/**
* Create su_sdss_media_mention field from configuration.
*/
function sdss_profile_update_10001()
{
function sdss_profile_update_10001() {
$config_directory = \Drupal::service('config.storage.sync');
$field_storage = $config_directory->read('field.storage.node.su_sdss_media_mention');
$field_config = $config_directory->read('field.field.node.stanford_news.su_sdss_media_mention');
Expand Down Expand Up @@ -898,3 +896,80 @@ function sdss_profile_update_10007(&$sandbox) {

$sandbox['#finished'] = empty($sandbox['pids']) ? 1 : ($sandbox['count'] - count($sandbox['pids'])) / $sandbox['count'];
}

/**
* Add imported via news sharing field to News.
*/
function sdss_profile_update_10008() {
$entity_type_manager = \Drupal::entityTypeManager();

$field_storage = $entity_type_manager->getStorage('field_storage_config');
if (!$field_storage->load('node.su_sdss_imported_news_sharing')) {
$field_storage->create([
'uuid' => '9e91a7b2-54be-4154-b251-b49040727100',
'field_name' => 'su_sdss_imported_news_sharing',
'type' => 'boolean',
'entity_type' => 'node',
'cardinality' => 1,
])->save();

$field_config_storage = $entity_type_manager->getStorage('field_config');
$field_config_storage->create([
'entity_type' => 'node',
'field_name' => 'su_sdss_imported_news_sharing',
'bundle' => 'stanford_news',
'label' => 'Imported via News Sharing',
'description' => 'This content was imported from another site through News Sharing.',
])->save();
}
}

/**
* Flag existing content imported via News Sharing.
*/
function sdss_profile_update_10009(&$sandbox) {
if (!isset($sandbox['count'])) {
$migration_storage = \Drupal::entityTypeManager()->getStorage('migration');
if (!$migration_entity = $migration_storage->load('sdss_news_sharing')) {
$sandbox['#finished'] = 1;
return;
}

$sandbox['nids'] = [];
$migration = \Drupal::service('plugin.manager.migration')->createInstance($migration_entity->id());
if (!$migration) {
$sandbox['#finished'] = 1;
return;
}

$database = $migration->getIdMap()->getDatabase();
$query = $database->select($migration->getIdMap()->mapTableName(), 'mt')
->fields('mt', ['destid1']);
$destination_records = $query->execute();
foreach ($destination_records as $destination_record) {
if (isset($destination_record->destid1)) {
$sandbox['nids'][] = $destination_record->destid1;
}
}
$sandbox['count'] = count($sandbox['nids']);
joegl marked this conversation as resolved.
Show resolved Hide resolved
}

$node_ids = array_splice($sandbox['nids'], 0, 250);

if (empty($node_ids)) {
$sandbox['#finished'] = 1;
return;
}

$nodes = \Drupal::entityTypeManager()->getStorage('node')->loadMultiple($node_ids);
foreach ($nodes as $node) {
if (!$node->hasField('su_sdss_imported_news_sharing')) {
continue;
}
$field = $node->get('su_sdss_imported_news_sharing');
$field->set(0, 1);
$node->save();
joegl marked this conversation as resolved.
Show resolved Hide resolved
}

$sandbox['#finished'] = empty($sandbox['nids']) ? 1 : ($sandbox['count'] - count($sandbox['nids'])) / $sandbox['count'];
}
Loading