Skip to content
Snippets Groups Projects
Commit 349a5d91 authored by Paul Mrvik's avatar Paul Mrvik
Browse files

Issue #3476191 by globexplorer: Change from timestamp to big int

parent 1456b33f
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,27 @@ function conditional_notification_update_10001() {
}
/**
* Fix Y2K38 bug on timestamp fields
* conditional_notification_log.
*/
function conditional_notification_update_10002() {
$connection = \Drupal::database();
if ($connection->schema()->tableExists('conditional_notification_log') && $connection->databaseType() != 'sqlite') {
$new = [
'type' => 'int',
'not null' => FALSE,
'default' => NULL,
'size' => 'big',
];
$connection->schema()->changeField('conditional_notification_log', 'entity_date_field_timestamp', 'entity_date_field_timestamp', $new);
$connection->schema()->changeField('conditional_notification_log', 'entity_date_offset', 'entity_date_offset', $new);
$connection->schema()->changeField('conditional_notification_log', 'processed_timestamp', 'processed_timestamp', $new);
}
}
......@@ -118,6 +118,10 @@ function conditional_notification_cron() {
$results = $query->execute();
\Drupal::logger('debug')->warning('Whats going on here!!!');
\Drupal::logger('debug')->warning('cron results<pre><code>' . print_r($results, TRUE) . '</code></pre>');
if (!empty($results)) {
$entities = \Drupal::entityTypeManager()->getStorage('conditional_notification_log')->loadMultiple($results);
foreach ($entities as $entity) {
......
......@@ -67,10 +67,18 @@ class ConditionalNotificationLog extends ContentEntityBase implements Conditiona
$fields['entity_date_field_part'] = BaseFieldDefinition::create('string')
->setLabel(t('Entity date field part'));
$fields['entity_date_field_timestamp'] = BaseFieldDefinition::create('timestamp')
$fields['entity_date_field_timestamp'] = BaseFieldDefinition::create('integer')
->setSettings([
'unsigned' => true,
'size' => 'big'
])
->setLabel(t('Entity date field timestamp'));
$fields['entity_date_offset'] = BaseFieldDefinition::create('timestamp')
$fields['entity_date_offset'] = BaseFieldDefinition::create('integer')
->setSettings([
'unsigned' => true,
'size' => 'big'
])
->setLabel(t('Entity date offset'));
$fields['entity_date_string_day'] = BaseFieldDefinition::create('string')
......@@ -82,10 +90,13 @@ class ConditionalNotificationLog extends ContentEntityBase implements Conditiona
$fields['processed'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Processed'));
$fields['processed_timestamp'] = BaseFieldDefinition::create('timestamp')
$fields['processed_timestamp'] = BaseFieldDefinition::create('integer')
->setSettings([
'unsigned' => true,
'size' => 'big'
])
->setLabel(t('Processed on'));
return $fields;
}
......
......@@ -305,28 +305,44 @@ final class ConditionalNotificationForm extends EntityForm {
$helper_service = \Drupal::service('conditional_notification.helper');
if ($saved_date_field = $this->entity->getTimeOffsetDateField()) {
$time_offset_date_field_part_options = $helper_service->getSupportedDateParts($saved_date_field );
$time_offset_date_field_part_options = $helper_service->getSupportedDateParts($saved_date_field);
}
else {
$time_offset_date_field_part_options = $helper_service->getSupportedDateParts($selected_date_field);
}
if (empty($form_state->getValue('time_offset_date_field_part'))) {
$selected_date_field_part = key($time_offset_date_field_part_options);
if (!empty($time_offset_date_field_part_options)) {
if (empty($form_state->getValue('time_offset_date_field_part'))) {
// Check if default value
if ($date_field_part = $this->entity->getTimeOffsetDateFieldPart()) {
$selected_date_field_part = $date_field_part;
}
else {
$selected_date_field_part = key($time_offset_date_field_part_options);
}
}
else {
if ($date_field_part = $this->entity->getTimeOffsetDateFieldPart()) {
$selected_date_field_part = $form_state->getValue('time_offset_date_field_part');
}
else {
$selected_date_field_part = '';
}
}
}
else {
$selected_date_field_part = $form_state->getValue('time_offset_date_field_part');
}
$selected_date_field_part = '';
}
$form['time_offset_wrapper']['time_offset_date_field_part'] = [
'#type' => 'select',
'#title' => $this->t('Date parts'),
'#options' => $time_offset_date_field_part_options,
'#disabled' => $notification_time_offset_disabled,
'#default_value' => $this->entity->getTimeOffsetDateFieldPart() ?? $selected_date_field_part,
'#default_value' => $selected_date_field_part,
];
$form['time_offset_wrapper']['time_offset'] = [
'#type' => 'number',
......
......@@ -278,19 +278,17 @@ final class NotificationFactory {
$data['entity_date_field_part'] = $date_field_part;
$data['entity_date_field_timestamp'] = $entity->{$date_field}->{$date_field_part};
}
else {
else {
$data['entity_date_field_part'] = NULL;
$data['entity_date_field_timestamp'] = $entity->get($date_field)->date->getTimestamp();
$data['entity_date_field_timestamp'] = $entity->get($date_field)->date->getTimestamp();
}
// Calculate offset
$time_offset = $notification->getTimeOffset();
$time_offset_type = $notification->getTimeOffsetType();
$data['time_offset_type'] = $time_offset_type;
$data['time_offset'] = $time_offset;
$data['entity_date_offset'] = $data['entity_date_field_timestamp'] + ($this->getCalculatedOffset($time_offset, $time_offset_type));
\Drupal::logger('debug')->warning('offset type<pre><code>' . print_r($data['time_offset_type'], TRUE) . '</code></pre>');
\Drupal::logger('debug')->warning('offset<pre><code>' . print_r($data['time_offset'], TRUE) . '</code></pre>');
\Drupal::logger('debug')->warning('offset<pre><code>' . print_r($data['entity_date_offset'], TRUE) . '</code></pre>');
$calculdated_offset = $this->getCalculatedOffset($time_offset, $time_offset_type);
$data['entity_date_offset'] = $data['entity_date_field_timestamp'] + ($calculdated_offset);
$data['entity_date_string_day'] = $this->getCalculatedOffsetString($data['entity_date_offset']);
$data['entity_date_string_hour'] = $this->getCalculatedOffsetString($data['entity_date_offset'], 'hours');
}
......@@ -298,6 +296,7 @@ final class NotificationFactory {
// Only Create log if all conditions met
if ($data['time_offset_enabled'] && $data['entity_date_offset']) {
\Drupal::logger('debug')->warning('DATA<pre><code>' . print_r($data, TRUE) . '</code></pre>');
$this->addToLogQueue($data);
}
......
......@@ -109,6 +109,14 @@ final class NotificationLogQueue extends QueueWorkerBase implements ContainerFac
// Get the day as string
$entity_date_string_day = $data['entity_date_string_day'];
if ($entity_id == 283) {
\Drupal::logger('debug')->warning('DATA on queue process!! <pre><code>' . print_r($data, TRUE) . '</code></pre>');
}
//\Drupal::logger('debug')->warning('DATA on queue process!! <pre><code>' . print_r($data, TRUE) . '</code></pre>');
if ($this->checkIfRecordsAlreadyExists($data)) {
// Update record
$this->updateRecord($data);
......@@ -124,8 +132,8 @@ final class NotificationLogQueue extends QueueWorkerBase implements ContainerFac
'time_offset' => $time_offset,
'entity_date_field' => $entity_date_field,
'entity_date_field_part' => $entity_date_field_part,
'entity_date_field_timestamp' => $entity_date_field_timestamp,
'entity_date_offset' => $entity_date_offset,
'entity_date_field_timestamp' => intval($entity_date_field_timestamp),
'entity_date_offset' => intval($entity_date_offset),
'entity_date_string_day' => $entity_date_string_day,
'entity_date_string_hour' => $entity_date_string_hour,
'processed' => 0,
......@@ -133,6 +141,12 @@ final class NotificationLogQueue extends QueueWorkerBase implements ContainerFac
}
catch (\Exception $exception) {
$message = $exception->getMessage();
$this->getLogger('conditional_notification')->warning('Problem writing conditional notification log with field: @field',['@field' => $notification_id]);
$this->getLogger('conditional_notification')->warning('Problem writing conditional notification log with field: @field',['@field' => $entity_id]);
$this->getLogger('conditional_notification')->warning('Problem writing conditional notification log with field: @field',['@field' => $entity_date_field_timestamp]);
$this->getLogger('conditional_notification')->warning('Problem writing conditional notification log with field entity date offset: @field',['@field' => $entity_date_offset]);
$this->getLogger('conditional_notification')->warning('Problem writing conditional notification log: @message',['@message' => $message]);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment