Skip to content

Commit

Permalink
Merge branch 'develop' into feature/SD-22-updated-hero-image-theme
Browse files Browse the repository at this point in the history
  • Loading branch information
yeniatencio authored Dec 18, 2024
2 parents f4f34fe + c4c0ddd commit b8a747f
Show file tree
Hide file tree
Showing 9 changed files with 247 additions and 1 deletion.
7 changes: 7 additions & 0 deletions css/ckeditor_overrides.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ button.ck.ck-button[data-cke-tooltip-text="Media"] svg {
.ck.ck-content.ck-editor__editable {
min-height: 200px;
}

.ck-link-form {
.ck-reset_all-excluded {
background-color: rgba(265, 256, 257, 21.4) !important;
}
}

6 changes: 6 additions & 0 deletions drush.services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
drush.command.tide_core:
class: Drupal\tide_core\Command\AuditLogCleanupCommand
arguments: ['@config.factory']
tags:
- { name: drush.command }
9 changes: 9 additions & 0 deletions modules/tide_site/tide_site.install
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,12 @@ function tide_site_update_10002() {
}
}
}

/**
* Enable linkset.
*/
function tide_site_update_10003() {
$system_feature_flags = \Drupal::configFactory()->getEditable('system.feature_flags');
$system_feature_flags->set('linkset_endpoint', TRUE)
->save();
}
2 changes: 1 addition & 1 deletion modules/tide_tfa/src/TideTfaOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static function setupTfaSettings() {
'code_validity_period' => '600',
'email_setting' => [
'subject' => 'Single Digtial Presence CMS two-factor authentication code',
'body' => '[user:display-name],\r\n\r\nThis code is valid for [length] minutes. \r\n\r\nYour code is: [code]\r\n\r\nThis code will expire once you have logged in.',
'body' => 'Hi [user:display-name],\r\n\r\nYour two-factor authentication code is: [code]\r\n\r\nThis code is valid for [length] minutes. \r\n\r\nThis code will expire when you have logged in.\r\n\r\nFrom the SDP team\r\n\r\nRead more about 2FA: https://digital-vic.atlassian.net/servicedesk/customer/article/2439479507',
],
],
];
Expand Down
106 changes: 106 additions & 0 deletions src/Command/AuditLogCleanupCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

namespace Drupal\tide_core\Command;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Database\Database;
use Drush\Commands\DrushCommands;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Custom AuditLog Clean Drush command.
*/
class AuditLogCleanupCommand extends DrushCommands {

/**
* The configuration service.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;

/**
* Constructs a AuditLogCleanupCommand object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration service.
*/
public function __construct(ConfigFactoryInterface $config_factory) {
$this->configFactory = $config_factory;
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory')
);
}

/**
* Removes log entries older than the configured retention period.
*
* @command tide_core:auditlog-cleanup
* @aliases tcl
* @description Cleans up audittrail logs older than the configured retention period.
*
* @option force-cleanup Skip confirmation and run the cleanup immediately.
*/
public function cleanupLogs($options = ['force-cleanup' => FALSE]) {
// Check if the user passed the --force-cleanup option.
if (!$options['force-cleanup']) {
// If the force-cleanup flag isn't passed, ask for confirmation.
$confirmation = $this->confirmCleanup();
if (!$confirmation) {
$this->output()->writeln('<comment>Cleanup operation cancelled.</comment>');
return;
}
}

$config = $this->configFactory->get('tide_core.settings');
define('DEFAULT_LOG_RETENTION_DAYS', 30);
$log_retention_days = $config->get('log_retention_days') ?: DEFAULT_LOG_RETENTION_DAYS;
// Get current date and time.
$current_time = new DateTime();
$current_time->sub(new DateInterval("P{$log_retention_days}D"));
$threshold_timestamp = $current_time->getTimestamp();
// Connect to the database.
$database = Database::getConnection();
$deleted = $database->delete('admin_audit_trail')
->condition('created', $threshold_timestamp, '<')
->execute();

// Output the result.
$this->output()->writeln("Deleted $deleted log entries older than $log_retention_days days.");
// Run a database optimization command to recover space.
$this->optimizeDatabase();
}

/**
* Ask for confirmation before proceeding with the cleanup.
*
* @return bool
* TRUE if the user confirms, FALSE if the user cancels.
*/
private function confirmCleanup() {
$question = 'Are you sure you want to delete log entries older than the configured retention period? (y/n): ';
$confirmation = $this->io()->ask($question, 'n');
$confirmation = strtolower($confirmation);
// Return TRUE if the user answers 'y' or 'yes'.
return in_array($confirmation, ['y', 'yes']);
}

/**
* Run database optimization (optional).
*
* @return void
* TRUE write the message.
*/
private function optimizeDatabase() {
$database = Database::getConnection();
$database->query('OPTIMIZE TABLE {admin_audit_trail}');
$this->output()->writeln("Database optimized to recover space.");
}

}
62 changes: 62 additions & 0 deletions src/Form/AuditTrailSettingsForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace Drupal\tide_core\Form;

use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;

/**
* Provides the configuration form for setting the log retention days.
*/
class AuditTrailSettingsForm extends ConfigFormBase {

/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
// This returns the name of the config object.
return ['tide_core.settings'];
}

/**
* {@inheritdoc}
*/
public function getFormId() {
// The form ID for this form.
return 'tide_core_log_retention_settings_form';
}

/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
// Load the configuration data.
$config = $this->config('tide_core.settings');

// Add a text field to specify the number of days for log retention.
$form['log_retention_days'] = [
'#type' => 'number',
'#title' => $this->t('Log retention days'),
'#description' => $this->t('Enter the number of days after which logs should be deleted.'),
// Default to 30 if not set.
'#default_value' => $config->get('log_retention_days', 30),
'#min' => 1,
'#required' => TRUE,
];

return parent::buildForm($form, $form_state);
}

/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->config('tide_core.settings')
->set('log_retention_days', $form_state->getValue('log_retention_days'))
->save();

$this->messenger()->addMessage($this->t('The log retention days have been updated.'));
parent::submitForm($form, $form_state);
}

}
42 changes: 42 additions & 0 deletions tide_core.install
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Installation functions for Tide Core.
*/

use Drupal\field\Entity\FieldConfig;
use Drupal\tide_core\TideCoreOperation;
use Drupal\user\Entity\Role;
use Drupal\user\Entity\User;
Expand Down Expand Up @@ -316,3 +317,44 @@ function tide_core_update_10010() {
$module_installer->install(['tide_tfa']);
}
}

/**
* Enabled tide_data_driven_component module.
*/
function tide_core_update_10011() {
$moduleHandler = \Drupal::service('module_handler');
$moduleInstaller = \Drupal::service('module_installer');
// Enable tide_data_driven_component.
if (!$moduleHandler->moduleExists('tide_data_driven_component')) {
$moduleInstaller->install(['tide_data_driven_component']);
}
if ($moduleHandler->moduleExists('tide_landing_page')) {
// Define the fields to be updated.
$fields_to_update = [
'field_landing_page_component',
'field_landing_page_header',
];
$new_component = 'data_driven_component';

foreach ($fields_to_update as $field_name) {
$field_config = FieldConfig::loadByName('node', 'landing_page', $field_name);

if ($field_config) {
// Get the current handler settings.
$handler_settings = $field_config->getSetting('handler_settings');

// Ensure 'target_bundles' exists in handler settings.
if (isset($handler_settings['target_bundles'])) {
// Add the new component if it does not already exist.
if (!array_key_exists($new_component, $handler_settings['target_bundles'])) {
$handler_settings['target_bundles'][$new_component] = $new_component;

// Update the field configuration with the new handler settings.
$field_config->setSetting('handler_settings', $handler_settings);
$field_config->save();
}
}
}
}
}
}
6 changes: 6 additions & 0 deletions tide_core.links.menu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ tide_core.moderated_content:
parent: system.admin_content
route_name: content_moderation.admin_moderated_content
weight: 100

audit_trail_settings.admin:
title: 'Audit Trail Settings'
description: 'Change audit trail log clean time'
parent: admin_audit_trail.report_form
route_name: audit_trail_settings.admin
8 changes: 8 additions & 0 deletions tide_core.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,11 @@ tide_core.package_version:
methods: ['GET']
requirements:
_access: 'TRUE'

audit_trail_settings.admin:
path: '/admin/reports/audit-trail/audit-trail-settings'
defaults:
_form: '\Drupal\tide_core\Form\AuditTrailSettingsForm'
_title: 'Audit Trail Settings'
requirements:
_permission: "access admin audit trail"

0 comments on commit b8a747f

Please sign in to comment.