timkelty / craftcms-site-sync

Sync content to locales on element save.
MIT License
40 stars 9 forks source link

Conflict with Sprout Forms plugin #7

Closed superwick closed 7 years ago

superwick commented 7 years ago

When the Locale Sync plugin is enabled, and Sprout Forms is enabled, Locale Sync will cause an error when trying to create a new Sprout Form and change the default form handle.

2016/12/15 14:37:14 [error] [system.db.CDbCommand] CDbCommand::fetch() failed: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'klipsch_staging.craft_sproutformscontent_form1' doesn't exist. The SQL statement executed was: SELECT *
FROM `craft_sproutformscontent_form1`
WHERE (`elementId`=:pnlimW2ymc) AND (`locale`=:psNN739cdI).
2016/12/15 14:37:14 [error] [exception.CDbException] CDbException: CDbCommand failed to execute the SQL statement: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'klipsch_staging.craft_sproutformscontent_form1' doesn't exist in /mnt/klipschweb-data-prod1/www/klipsch-staging/app/craft/app/framework/db/CDbCommand.php:543
Stack trace:
#0 /mnt/klipschweb-data-prod1/www/klipsch-staging/app/craft/app/framework/db/CDbCommand.php(415): CDbCommand->queryInternal('fetch', Array, Array)
#1 /mnt/klipschweb-data-prod1/www/klipsch-staging/app/craft/app/services/ContentService.php(65): CDbCommand->queryRow()
#2 /mnt/klipschweb-data-prod1/www/klipsch-staging/app/craft/app/models/BaseElementModel.php(815): Craft\ContentService->getContent(Object(Craft\SproutForms_FormModel))
#3 /mnt/klipschweb-data-prod1/www/klipsch-staging/app/craft/app/framework/base/CComponent.php(111): Craft\BaseElementModel->getContent()
#4 /mnt/klipschweb-data-prod1/www/klipsch-staging/app/craft/app/models/BaseModel.php(87): CComponent->__get('content')
#5 /mnt/klipschweb-data-prod1/www/klipsch-staging/app/craft/app/models/BaseElementModel.php(141): Craft\BaseModel->__get('content')
#6 /mnt/klipschweb-data-prod1/www/klipsch-staging/app/craft/plugins/localesync/services/LocaleSyncService.php(121): Craft\BaseElementModel->__get('content')
#7 /mnt/klipschweb-data-prod1/www/klipsch-staging/app/craft/plugins/localesync/services/LocaleSyncService.php(93): Craft\LocaleSyncService->updateElement(Object(Craft\SproutForms_FormModel), 'title')
#8 /mnt/klipschweb-data-prod1/www/klipsch-staging/app/craft/plugins/localesync/LocaleSyncPlugin.php(28): Craft\LocaleSyncService->syncElementContent(Object(Craft\Event), NULL)
#9 /mnt/klipschweb-data-prod1/www/klipsch-staging/app/craft/app/framework/base/CComponent.php(567): Craft\LocaleSyncPlugin->Craft\{closure}(Object(Craft\Event))
#10 /mnt/klipschweb-data-prod1/www/klipsch-staging/app/craft/app/services/ElementsService.php(2359): CComponent->raiseEvent('onbeforesaveele...', Object(Craft\Event))
#11 /mnt/klipschweb-data-prod1/www/klipsch-staging/app/craft/app/services/ElementsService.php(1380): Craft\ElementsService->onBeforeSaveElement(Object(Craft\Event))
#12 /mnt/klipschweb-data-prod1/www/klipsch-staging/app/craft/plugins/sproutforms/services/SproutForms_FormsService.php(172): Craft\ElementsService->saveElement(Object(Craft\SproutForms_FormModel))
#13 /mnt/klipschweb-data-prod1/www/klipsch-staging/app/craft/plugins/sproutforms/controllers/SproutForms_FormsController.php(106): Craft\SproutForms_FormsService->saveForm(Object(Craft\SproutForms_FormModel))
#14 /mnt/klipschweb-data-prod1/www/klipsch-staging/app/craft/app/framework/web/actions/CInlineAction.php(49): Craft\SproutForms_FormsController->actionSaveForm()
#15 /mnt/klipschweb-data-prod1/www/klipsch-staging/app/craft/app/framework/web/CController.php(308): CInlineAction->runWithParams(Array)
#16 /mnt/klipschweb-data-prod1/www/klipsch-staging/app/craft/app/framework/web/CController.php(286): CController->runAction(Object(CInlineAction))
#17 /mnt/klipschweb-data-prod1/www/klipsch-staging/app/craft/app/framework/web/CController.php(265): CController->runActionWithFilters(Object(CInlineAction), Array)
#18 /mnt/klipschweb-data-prod1/www/klipsch-staging/app/craft/app/framework/web/CWebApplication.php(282): CController->run('saveForm')
#19 /mnt/klipschweb-data-prod1/www/klipsch-staging/app/craft/app/etc/web/WebApp.php(817): CWebApplication->runController('sproutForms/for...')
#20 /mnt/klipschweb-data-prod1/www/klipsch-staging/app/craft/app/etc/web/WebApp.php(287): Craft\WebApp->_processActionRequest()
#21 /mnt/klipschweb-data-prod1/www/klipsch-staging/app/craft/app/framework/base/CApplication.php(185): Craft\WebApp->processRequest()
#22 /mnt/klipschweb-data-prod1/www/klipsch-staging/app/craft/app/index.php(62): CApplication->run()
#23 /mnt/klipschweb-data-prod1/www/klipsch-staging/app/public_staged/index.php(19): require_once('/mnt/klipschweb...')
#24 {main}
REQUEST_URI=/admin/sproutforms/forms/edit/46798
HTTP_REFERER=http://staging.klipsch.com/admin/sproutforms/forms/edit/46798

I was able to get around this with a null check in the Craft\LocaleSyncService->syncElementContent method. Will post a PR soon.

timkelty commented 7 years ago

Yikes! Thanks for the issue. I'll be looking for your PR.

timkelty commented 7 years ago

@superwick finally got around to testing this.

I'm not seeing this with the latest Sprout Forms (2.5.5). I also added a condition to bail out early if the element doesn't have more than 1 locale, so could help too if it is still happening for some reason.

Please try with the latest of both plugins and let me know if it isn't fixed.