diff --git a/replication.install b/replication.install index 0761ecb..4f4e5e5 100644 --- a/replication.install +++ b/replication.install @@ -102,3 +102,52 @@ function replication_update_8100() { } } } + +/** + * Update ReplicationHistoryItem property definitions. + * + * For compatibility with CouchDB 2.0.0. + */ +function replication_update_8101() { + $connection = Database::getConnection(); + $entity_definition_update_manager = Drupal::entityDefinitionUpdateManager(); + $entity_type_id = 'replication_log'; + + // Check if we have updates for replication_log entity type. + if ($entity_definition_update_manager->needsUpdates()) { + $changes = $entity_definition_update_manager->getChangeSummary(); + if (in_array($entity_type_id, array_keys($changes))) { + // Set tables to update (history field tables). + $tables_to_update = [ + $entity_type_id . '__history', + $entity_type_id . '_revision__history' + ]; + + $tables_data = []; + // Copy content from entity tables. + foreach ($tables_to_update as $table_to_update) { + $tables_data[$table_to_update] = $connection->select($table_to_update) + ->fields($table_to_update) + ->execute()->fetchAll(); + $connection->truncate($table_to_update)->execute(); + } + + // Apply updates. + $storage_definitions = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions($entity_type_id); + if ($storage_definitions['history']) { + $entity_definition_update_manager->updateFieldStorageDefinition($storage_definitions['history']); + } + + // Insert content into updated entity tables. + foreach ($tables_data as $table_name => $table_data) { + foreach ($table_data as $result) { + $data = (array) $result; + // Save the information in the table. + $connection->insert($table_name) + ->fields($data) + ->execute(); + } + } + } + } +} diff --git a/src/Plugin/Field/FieldType/ReplicationHistoryItem.php b/src/Plugin/Field/FieldType/ReplicationHistoryItem.php index d3bd681..096209d 100644 --- a/src/Plugin/Field/FieldType/ReplicationHistoryItem.php +++ b/src/Plugin/Field/FieldType/ReplicationHistoryItem.php @@ -43,14 +43,14 @@ class ReplicationHistoryItem extends FieldItemBase { ->setDescription(t('Number of documents written.')) ->setRequired(FALSE); - $properties['end_last_seq'] = DataDefinition::create('integer') - ->setLabel(t('End sequence')) - ->setDescription(t('Sequence ID where the replication ended.')) + $properties['start_last_seq'] = DataDefinition::create('string') + ->setLabel(t('Start sequence')) + ->setDescription(t('Sequence ID where the replication started.')) ->setRequired(FALSE); - $properties['end_time'] = DataDefinition::create('datetime_iso8601') - ->setLabel(t('End time')) - ->setDescription(t('Date and time when replication ended.')) + $properties['end_last_seq'] = DataDefinition::create('string') + ->setLabel(t('End sequence')) + ->setDescription(t('Sequence ID where the replication ended.')) ->setRequired(FALSE); $properties['missing_checked'] = DataDefinition::create('integer') @@ -63,7 +63,7 @@ class ReplicationHistoryItem extends FieldItemBase { ->setDescription(t('Number of missing documents found.')) ->setRequired(FALSE); - $properties['recorded_seq'] = DataDefinition::create('integer') + $properties['recorded_seq'] = DataDefinition::create('string') ->setLabel(t('Recorded sequence')) ->setDescription(t('Recorded intermediate sequence.')) ->setRequired(FALSE); @@ -73,16 +73,16 @@ class ReplicationHistoryItem extends FieldItemBase { ->setDescription(t('Unique session ID for the replication.')) ->setRequired(TRUE); - $properties['start_last_seq'] = DataDefinition::create('integer') - ->setLabel(t('Start sequence')) - ->setDescription(t('Sequence ID where the replication started.')) - ->setRequired(FALSE); - $properties['start_time'] = DataDefinition::create('datetime_iso8601') ->setLabel(t('Start time')) ->setDescription(t('Date and time when replication started.')) ->setRequired(FALSE); + $properties['end_time'] = DataDefinition::create('datetime_iso8601') + ->setLabel(t('End time')) + ->setDescription(t('Date and time when replication ended.')) + ->setRequired(FALSE); + return $properties; } @@ -107,16 +107,6 @@ class ReplicationHistoryItem extends FieldItemBase { 'unsigned' => TRUE, 'not null' => FALSE, ], - 'end_last_seq' => [ - 'type' => 'int', - 'size' => 'big', - 'not null' => FALSE, - ], - 'end_time' => [ - 'type' => 'varchar', - 'length' => 50, - 'not null' => FALSE, - ], 'missing_checked' => [ 'type' => 'int', 'unsigned' => TRUE, @@ -127,20 +117,24 @@ class ReplicationHistoryItem extends FieldItemBase { 'unsigned' => TRUE, 'not null' => FALSE, ], - 'recorded_seq' => [ - 'type' => 'int', - 'size' => 'big', - 'not null' => FALSE, - 'default' => 0, - ], 'session_id' => [ 'type' => 'varchar', 'length' => 128, 'not null' => TRUE, ], + 'recorded_seq' => [ + 'type' => 'varchar', + 'length' => 512, + 'not null' => TRUE, + ], 'start_last_seq' => [ - 'type' => 'int', - 'size' => 'big', + 'type' => 'varchar', + 'length' => 512, + 'not null' => FALSE, + ], + 'end_last_seq' => [ + 'type' => 'varchar', + 'length' => 512, 'not null' => FALSE, ], 'start_time' => [ @@ -148,6 +142,11 @@ class ReplicationHistoryItem extends FieldItemBase { 'length' => 50, 'not null' => FALSE, ], + 'end_time' => [ + 'type' => 'varchar', + 'length' => 50, + 'not null' => FALSE, + ], ], ]; }