Left sync only is available to ui admin (datastore to active story).
It is necessary create to use in drush command.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

edmargomes’s picture

This solution create:
drush config-left-sync
or
drush clsyn

We have many problems when working with versioning settings using git, because when merging two branches that have configuration changes conflicts are generated in tracked.inc.

Another problem is when the csyn drush is unable to copy the datastore settings for ActiveStore, eg when fields are changed or removed from a node. This generates an error because the synchronization (csyn) when finishing the import stage, which was not successful, perform the export sending the fields that should no longer exist.

this solution read files in the config folder ignoring tracked.inc, this way is possible to use cm files in differents branchs using git since it doesn't make the export step.

edmargomes’s picture

Status: Active » Needs review
sebas5384’s picture

Assigned: edmargomes » Unassigned

Nice patch @edmargomes ! thanks!

heddn’s picture

FileSize
3.08 KB
971 bytes

Removed some commented out code and unused variables.

edmargomes’s picture

Thanks heddn!!!

I needed to create a new update.

The problem:
When you do not use preserve-tracked option, the command sync use stopTracking to remove untracke files, but the stopTraking is exporting all configurations (activestore to datastore) and is replacing the news configurations files.

This new patch only stop tracking in untrack files after import the configurations files.

heddn’s picture

FileSize
969 bytes

Here's an interdiff.

handrus’s picture

When we need to stop tracking something left sync shouldn't try to detect dependecies.
Ex.: If I delete a field stop tracking will detect any content type that depends on it and try to stop tracking the entire CT.
The patch is very simple, just change the parameters sent to stopTracking.

heddn’s picture

Status: Needs review » Closed (won't fix)

I don't think this is really needed. After posting the patch above, I ended up going a different route.

drush csyn --preserve-tracked seems to do it. It's just terribly documented

handrus’s picture

Status: Closed (won't fix) » Needs review

@heddn there is a HUGE difference to me:
This patch does it in a way that it blindly trust what is in the files

// Do not detect dependencies when stop tracking.
$un_track_results = ConfigurationManagement::stopTracking($to_untrack, FALSE, FALSE);

while --preserve-tracked does detect dependencies:

$to_untrack = array_diff($being_tracked, $to_track);
$un_track_results = ConfigurationManagement::stopTracking($to_untrack, TRUE, TRUE);

If I want to be 100% sure that all changes are moved, specially changes on dependencies, the first approach (in this patch) is still accomplishing it better.
Reason why I'm reopening this.

edmargomes’s picture

FileSize
2.33 KB
1.52 KB

Hi Heddn,

Thanks about your comment.

But the feature is diferente. The --preserve-tracked doesn't call stop tracking. Look:

  // If we have to stop tracking some configurations, figure out which
  // configurations have to be untracked.
  if (!drush_get_option('preserve-tracked')) {

    $being_tracked = array_keys(ConfigurationManagement::trackedConfigurations(FALSE));

    $to_untrack = array_diff($being_tracked, $to_track);

    $un_track_results = ConfigurationManagement::stopTracking($to_untrack, TRUE, TRUE);

    if (count($un_track_results->getInfo('untracked'))) {
      foreach ($un_track_results->getInfo('untracked') as $untracked_config) {
        drush_log(dt('Untracked %config', array('%config' => $untracked_config)));
      }
    }
  }

When you call the clsyn command, it will update the settings (active store) the same as the file folder (data store). Exemple, if you delete permissions configuration files and call left sync, the command will do stop the tracking in this configuration. It doesn't work with preserve tracked and if you call the csyn command the permissions will be created again.

I created preserve tracked in the left sync. But, after you comment, I review the code, and drush csyn --preserve-tracked and drush clsyn --preserve-tracked has the same result. Then I removed preserve tracked in clsyn.

thanks

Status: Needs review » Needs work

The last submitted patch, 10: drush-left-sync-2460397-10.patch, failed testing.

cjwang18’s picture

Unfortunately none of the patches are working for me. There was something wrong while patching with #10 so I had to do it manually. Even then I'm getting a PDO exception (integrity constraint violation, 1062 duplicate entry)

I'm not 100% sure but I have a feeling it's because the left sync is writing datastore into activestore so it's creating rows in the database but not checking whether that row already exists. Hopefully someone can confirm and/or offer a solution.

I'm running the latest 2.x dev version of Configuration and I also have the --only-modified patch applied. That doesn't seem to matter though as same issue occurs when I revert to alpha3. Here's the stacktrace for reference.

exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'node|_block_quote|page_quote' for key 'PRIMARY'' in         [error]
/Sites/website/includes/database/database.inc:2171
Stack trace:
#0 /Sites/website/includes/database/database.inc(2171): PDOStatement->execute(Array)
#1 /Sites/website/includes/database/database.inc(683): DatabaseStatementBase->execute(Array, Array)
#2 /Sites/website/includes/database/mysql/query.inc(36): DatabaseConnection->query('INSERT INTO {ds...', Array, Array)
#3 /Sites/website/includes/common.inc(7334): InsertQuery_mysql->execute()
#4 /Sites/website/sites/all/modules/contrib/ctools/includes/export.inc(190): drupal_write_record('ds_field_settin...', Object(stdClass), Array)
#5 /Sites/website/sites/all/modules/contrib/configuration/lib/Drupal/configuration/Config/CtoolsConfiguration.php(169):
ctools_export_crud_save('ds_field_settin...', Object(stdClass))
#6 /Sites/website/sites/all/modules/contrib/configuration/lib/Drupal/configuration/Config/Configuration.php(302):
Drupal\configuration\Config\CtoolsConfiguration->saveToActiveStore(Object(Drupal\configuration\Utils\ConfigIteratorSettings))
#7 /Sites/website/sites/all/modules/contrib/configuration/lib/Drupal/configuration/Config/Configuration.php(887):
Drupal\configuration\Config\Configuration->import(Object(Drupal\configuration\Utils\ConfigIteratorSettings))
#8 /Sites/website/sites/all/modules/contrib/configuration/lib/Drupal/configuration/Config/ConfigurationManagement.php(307):
Drupal\configuration\Config\Configuration->iterate(Object(Drupal\configuration\Utils\ConfigIteratorSettings))
#9 /Sites/website/sites/all/modules/contrib/configuration/configuration.drush.inc(491):
Drupal\configuration\Config\ConfigurationManagement::importToActiveStore(Array, false, false, true)
#10 [internal function]: _configuration_left_sync()
#11 /usr/local/Cellar/drush/8.0.3/libexec/includes/command.inc(366): call_user_func_array('_configuration_...', Array)
#12 /usr/local/Cellar/drush/8.0.3/libexec/includes/command.inc(217): _drush_invoke_hooks(Array, Array)
#13 [internal function]: drush_command()
#14 /usr/local/Cellar/drush/8.0.3/libexec/includes/command.inc(185): call_user_func_array('drush_command', Array)
#15 /usr/local/Cellar/drush/8.0.3/libexec/lib/Drush/Boot/BaseBoot.php(67): drush_dispatch(Array)
#16 /usr/local/Cellar/drush/8.0.3/libexec/includes/preflight.inc(66): Drush\Boot\BaseBoot->bootstrap_and_dispatch()
#17 /usr/local/Cellar/drush/8.0.3/libexec/drush.php(12): drush_main()
#18 {main}

Thanks!

----

EDIT:
Nevermind, I read through the comments again and can confirm that drush csync --preserve-tracked does indeed work for this use case. It's also working with --only-modified too. Thanks!

handrus’s picture

Can someone review and apply #10?
I've being using it for a year in production without any problems.