reverted the removal of ALWAYS_UPDATE_META option.
This commit is contained in:
@@ -60,6 +60,12 @@ class ImportCommand extends Command
|
||||
InputOption::VALUE_NONE,
|
||||
'import metadata changes only. Works when there are records in database.'
|
||||
)
|
||||
->addOption(
|
||||
'always-update-metadata',
|
||||
null,
|
||||
InputOption::VALUE_NONE,
|
||||
'Mapper option. Always update the locally stored metadata from backend.'
|
||||
)
|
||||
->addOption('show-messages', null, InputOption::VALUE_NONE, 'Show internal messages.')
|
||||
->addOption('config', 'c', InputOption::VALUE_REQUIRED, 'Use Alternative config file.')
|
||||
->addOption('servers-filter', null, InputOption::VALUE_OPTIONAL, '[DEPRECATED] Select backends.', '');
|
||||
@@ -117,6 +123,10 @@ class ImportCommand extends Command
|
||||
$this->db->setOptions(options: [Options::DEBUG_TRACE => true]);
|
||||
}
|
||||
|
||||
if ($input->getOption('always-update-metadata')) {
|
||||
$mapperOpts[Options::MAPPER_ALWAYS_UPDATE_META] = true;
|
||||
}
|
||||
|
||||
if ($input->getOption('direct-mapper')) {
|
||||
$this->mapper = new DirectMapper(logger: $this->logger, db: $this->db);
|
||||
}
|
||||
|
||||
@@ -296,57 +296,59 @@ final class DirectMapper implements iImport
|
||||
}
|
||||
|
||||
// -- this sometimes leads to never ending updates as data from backends conflicts.
|
||||
if (true === (clone $cloned)->apply(entity: $entity, fields: $keys)->isChanged(fields: $keys)) {
|
||||
try {
|
||||
$localFields = array_merge($keys, [iState::COLUMN_GUIDS]);
|
||||
if (true === (bool)ag($this->options, Options::MAPPER_ALWAYS_UPDATE_META)) {
|
||||
if (true === (clone $cloned)->apply(entity: $entity, fields: $keys)->isChanged(fields: $keys)) {
|
||||
try {
|
||||
$localFields = array_merge($keys, [iState::COLUMN_GUIDS]);
|
||||
|
||||
$entity->guids = Guid::makeVirtualGuid(
|
||||
$entity->via,
|
||||
ag($entity->getMetadata($entity->via), iState::COLUMN_ID)
|
||||
);
|
||||
$entity->guids = Guid::makeVirtualGuid(
|
||||
$entity->via,
|
||||
ag($entity->getMetadata($entity->via), iState::COLUMN_ID)
|
||||
);
|
||||
|
||||
$local = $local->apply(
|
||||
entity: $entity,
|
||||
fields: array_merge($localFields, [iState::COLUMN_EXTRA])
|
||||
);
|
||||
$local = $local->apply(
|
||||
entity: $entity,
|
||||
fields: array_merge($localFields, [iState::COLUMN_EXTRA])
|
||||
);
|
||||
|
||||
$this->removePointers($cloned)->addPointers($local, $local->id);
|
||||
$this->removePointers($cloned)->addPointers($local, $local->id);
|
||||
|
||||
$changes = $local->diff(fields: $localFields);
|
||||
$changes = $local->diff(fields: $localFields);
|
||||
|
||||
if (count($changes) >= 1) {
|
||||
$this->logger->notice('MAPPER: [%(backend)] updated [%(title)] metadata.', [
|
||||
if (count($changes) >= 1) {
|
||||
$this->logger->notice('MAPPER: [%(backend)] updated [%(title)] metadata.', [
|
||||
'id' => $cloned->id,
|
||||
'backend' => $entity->via,
|
||||
'title' => $cloned->getName(),
|
||||
'changes' => $local->diff(fields: $localFields),
|
||||
]);
|
||||
}
|
||||
|
||||
if (false === $inDryRunMode) {
|
||||
$this->db->update($local);
|
||||
}
|
||||
|
||||
if (null === ($this->changed[$local->id] ?? null)) {
|
||||
$this->actions[$local->type]['updated']++;
|
||||
Message::increment("{$entity->via}.{$local->type}.updated");
|
||||
}
|
||||
|
||||
$this->changed[$local->id] = $this->objects[$local->id] = $local->id;
|
||||
} catch (PDOException $e) {
|
||||
$this->actions[$local->type]['failed']++;
|
||||
Message::increment("{$entity->via}.{$local->type}.failed");
|
||||
$this->logger->error(sprintf('MAPPER: %s', $e->getMessage()), [
|
||||
'id' => $cloned->id,
|
||||
'backend' => $entity->via,
|
||||
'title' => $cloned->getName(),
|
||||
'changes' => $local->diff(fields: $localFields),
|
||||
'state' => [
|
||||
'database' => $cloned->getAll(),
|
||||
'backend' => $entity->getAll()
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
if (false === $inDryRunMode) {
|
||||
$this->db->update($local);
|
||||
}
|
||||
|
||||
if (null === ($this->changed[$local->id] ?? null)) {
|
||||
$this->actions[$local->type]['updated']++;
|
||||
Message::increment("{$entity->via}.{$local->type}.updated");
|
||||
}
|
||||
|
||||
$this->changed[$local->id] = $this->objects[$local->id] = $local->id;
|
||||
} catch (PDOException $e) {
|
||||
$this->actions[$local->type]['failed']++;
|
||||
Message::increment("{$entity->via}.{$local->type}.failed");
|
||||
$this->logger->error(sprintf('MAPPER: %s', $e->getMessage()), [
|
||||
'id' => $cloned->id,
|
||||
'title' => $cloned->getName(),
|
||||
'state' => [
|
||||
'database' => $cloned->getAll(),
|
||||
'backend' => $entity->getAll()
|
||||
],
|
||||
]);
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
if ($this->inTraceMode()) {
|
||||
|
||||
@@ -218,36 +218,38 @@ final class MemoryMapper implements iImport
|
||||
}
|
||||
|
||||
// -- this sometimes leads to never ending updates as data from backends conflicts.
|
||||
if (true === (clone $cloned)->apply(entity: $entity, fields: $keys)->isChanged(fields: $keys)) {
|
||||
$localFields = array_merge($keys, [iState::COLUMN_GUIDS]);
|
||||
$this->changed[$pointer] = $pointer;
|
||||
Message::increment("{$entity->via}.{$entity->type}.updated");
|
||||
if (true === (bool)ag($this->options, Options::MAPPER_ALWAYS_UPDATE_META)) {
|
||||
if (true === (clone $cloned)->apply(entity: $entity, fields: $keys)->isChanged(fields: $keys)) {
|
||||
$localFields = array_merge($keys, [iState::COLUMN_GUIDS]);
|
||||
$this->changed[$pointer] = $pointer;
|
||||
Message::increment("{$entity->via}.{$entity->type}.updated");
|
||||
|
||||
$entity->guids = Guid::makeVirtualGuid(
|
||||
$entity->via,
|
||||
ag($entity->getMetadata($entity->via), iState::COLUMN_ID)
|
||||
);
|
||||
$entity->guids = Guid::makeVirtualGuid(
|
||||
$entity->via,
|
||||
ag($entity->getMetadata($entity->via), iState::COLUMN_ID)
|
||||
);
|
||||
|
||||
$this->objects[$pointer] = $this->objects[$pointer]->apply(
|
||||
entity: $entity,
|
||||
fields: array_merge($localFields, [iState::COLUMN_EXTRA])
|
||||
);
|
||||
$this->objects[$pointer] = $this->objects[$pointer]->apply(
|
||||
entity: $entity,
|
||||
fields: array_merge($localFields, [iState::COLUMN_EXTRA])
|
||||
);
|
||||
|
||||
$this->removePointers($cloned)->addPointers($this->objects[$pointer], $pointer);
|
||||
$this->removePointers($cloned)->addPointers($this->objects[$pointer], $pointer);
|
||||
|
||||
$changes = $this->objects[$pointer]->diff(fields: $keys);
|
||||
$changes = $this->objects[$pointer]->diff(fields: $keys);
|
||||
|
||||
if (count($changes) >= 1) {
|
||||
$this->logger->notice('MAPPER: [%(backend)] updated [%(title)] metadata.', [
|
||||
'id' => $cloned->id,
|
||||
'backend' => $entity->via,
|
||||
'title' => $cloned->getName(),
|
||||
'changes' => $changes,
|
||||
'fields' => implode(',', $localFields),
|
||||
]);
|
||||
if (count($changes) >= 1) {
|
||||
$this->logger->notice('MAPPER: [%(backend)] updated [%(title)] metadata.', [
|
||||
'id' => $cloned->id,
|
||||
'backend' => $entity->via,
|
||||
'title' => $cloned->getName(),
|
||||
'changes' => $changes,
|
||||
'fields' => implode(',', $localFields),
|
||||
]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
if ($this->inTraceMode()) {
|
||||
|
||||
@@ -14,6 +14,7 @@ final class Options
|
||||
public const IGNORE_DATE = 'IGNORE_DATE';
|
||||
public const EXPORT_ALLOWED_TIME_DIFF = 'EXPORT_TIME_DIFF';
|
||||
public const RAW_RESPONSE = 'SHOW_RAW_RESPONSE';
|
||||
public const MAPPER_ALWAYS_UPDATE_META = 'ALWAYS_UPDATE_META';
|
||||
public const MAPPER_DISABLE_AUTOCOMMIT = 'DISABLE_AUTOCOMMIT';
|
||||
public const IMPORT_METADATA_ONLY = 'IMPORT_METADATA_ONLY';
|
||||
public const MISMATCH_DEEP_SCAN = 'MISMATCH_DEEP_SCAN';
|
||||
|
||||
Reference in New Issue
Block a user