Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot create entry if its enabled for a disabled site #10499

Closed
lukasNo1 opened this issue Feb 8, 2022 · 16 comments
Closed

Cannot create entry if its enabled for a disabled site #10499

lukasNo1 opened this issue Feb 8, 2022 · 16 comments
Labels

Comments

@lukasNo1
Copy link

lukasNo1 commented Feb 8, 2022

Description

I tried creating a new entry for a site with the following code:

  $entry = new Entry();
  $entry->siteId = 2; // enabled site
  $entry->typeId = ...;
  $entry->sectionId = ..;
  $entry->authorId = ..;
  $entry->enabled = true;
  $entry->title = 'New entry';
  
  Craft::$app->elements->saveElement($entry);

Which yields the following error:

... [error][application] Couldn’t propagate element to other site due to validation errors:
- Your system isn’t set up to save content for the site “1”.

The section is enabled both for the enabled site "2", which i try to save the entry in and the disabled site "1".

Im not sure if this is a bug, or intentional.

If i create it in the CP, everything works and it is also propagating to the disabled site.

Steps to reproduce

  1. Create two sites "1" and "2"
  2. Create a section which is enabled for both sites
  3. Disable site "1"
  4. Try to save a new entry with the elements service

Additional info

  • Craft version: 3.7.30.1
@lukasNo1 lukasNo1 added the bug label Feb 8, 2022
@lukasNo1 lukasNo1 changed the title Cannot create entry if its enabled for a disabled section Cannot create entry if its enabled for a disabled site Feb 8, 2022
@brandonkelly
Copy link
Member

This should be fixed now for the next release. If you have time in the next couple hours, it would be awesome if you could test for me, though.

To get the fix early, change your craftcms/cms requirement in composer.json to "dev-develop as 3.7.31" and run composer update.

There’s a new DB migration so you’ll also need to run php craft up or press the “Finish up” button in the control panel.

@brandonkelly
Copy link
Member

Craft 3.7.32 is out now with the fix. Hopefully it works 🤞🏻

@lukasNo1
Copy link
Author

lukasNo1 commented Feb 9, 2022

I just got the chance to test it, unfortunately i still get the same error message

[-][1][][error][application] Couldn’t propagate element to other site due to validation errors:

  • Your system isn’t set up to save content for the site “1”.
[1][9cf78faea10b5738f2d5796b3cc9c3d4][error][yii\base\Exception] yii\base\Exception: Couldn’t propagate element to other site. in /var/www/backend/vendor/craftcms/cms/src/services/Elements.php:2923
Stack trace:
#0 /var/www/backend/vendor/craftcms/cms/src/services/Elements.php(2708): craft\services\Elements->_propagateElement(Object(craft\elements\Entry), Array, Object(craft\elements\Entry))
#1 /var/www/backend/vendor/craftcms/cms/src/services/Elements.php(784): craft\services\Elements->_saveElementInternal(Object(craft\elements\Entry), true, true, true)
#2 /var/www/backend/modules/module/src/controllers/ApiController.php(36): craft\services\Elements->saveElement(Object(craft\elements\Entry))
#3 [internal function]: module\controllers\ApiController->actionTest()

@brandonkelly brandonkelly reopened this Feb 10, 2022
@brandonkelly
Copy link
Member

Check your logs for the following text:

Couldn’t propagate element to other site due to validation errors:

What’s the full output?

@lukasNo1
Copy link
Author

I have tested it on 2 different projects, both have the same error when deactivating a site.

2022-02-10 08:00:42 [-][1][5e8d5c019ee519ff518587428a6e30e6][error][application] Couldn’t propagate element to other site due to validation errors:
- Your system isn’t set up to save content for the site “4”.
2022-02-10 08:00:42 [-][1][5e8d5c019ee519ff518587428a6e30e6][error][yii\base\Exception] yii\base\Exception: Couldn’t propagate element to other site. in /var/www/backend/vendor/craftcms/cms/src/services/Elements.php:2923
Stack trace:
#0 /var/www/backend/vendor/craftcms/cms/src/services/Elements.php(2708): craft\services\Elements->_propagateElement(Object(craft\elements\Entry), Array, Object(craft\elements\Entry))
#1 /var/www/backend/vendor/craftcms/cms/src/services/Elements.php(784): craft\services\Elements->_saveElementInternal(Object(craft\elements\Entry), true, true, true)
#2 /var/www/backend/modules/module/src/controllers/ApiController.php(37): craft\services\Elements->saveElement(Object(craft\elements\Entry))
#3 [internal function]: module\controllers\ApiController->actionTest()
#4 /var/www/backend/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#5 /var/www/backend/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#6 /var/www/backend/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('test', Array)
#7 /var/www/backend/vendor/craftcms/cms/src/web/Application.php(292): yii\base\Module->runAction('module/api/test', Array)
#8 /var/www/backend/vendor/craftcms/cms/src/web/Application.php(601): craft\web\Application->runAction('module/api/test', Array)
#9 /var/www/backend/vendor/craftcms/cms/src/web/Application.php(271): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#10 /var/www/backend/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#11 /var/www/backend/crafter/bootstrap/crafter.php(23): yii\base\Application->run()
#12 /var/www/backend/crafter/bootstrap/start.php(23): CrafterApp->run()
#13 /var/www/public/en/index.php(5): require_once('/var/www/backen...')
#14 {main}
2022-02-10 08:00:41 [-][1][5e8d5c019ee519ff518587428a6e30e6][info][application] $_GET = []

$_POST = []

$_FILES = []

$_COOKIE = [
....
]

$_SESSION = [
 ....
]

$_SERVER = [
    'PHP_EXTRA_CONFIGURE_ARGS' => '--enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data --disable-cgi'
    'HOSTNAME' => '8cc9eda74812'
    'COMPOSER_MEMORY_LIMIT' => '-1'
    'PHP_INI_DIR' => '/usr/local/etc/php'
    'HOME' => '/var/www'
    'PHP_LDFLAGS' => '-Wl,-O1 -pie'
    'PHP_CFLAGS' => '-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
    'PHP_VERSION' => '7.4.20'
    'GPG_KEYS' => '42670A7FE4D0441C8E4632349E4FDC074A4EF02D 5A52880781F755608BF815FC910DEB46F53EA312'
    'PHP_CPPFLAGS' => '-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
    'PHP_ASC_URL' => 'https://www.php.net/distributions/php-7.4.20.tar.xz.asc'
    'PHP_URL' => 'https://www.php.net/distributions/php-7.4.20.tar.xz'
    'PATH' => '/usr/local/apache2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
    'LANG' => 'C.UTF-8'
    'PHPIZE_DEPS' => 'autoconf 		dpkg-dev 		file 		g++ 		gcc 		libc-dev 		make 		pkg-config 		re2c'
    'PWD' => '/var/www'
    'PHP_SHA256' => '1fa46ca6790d780bf2cb48961df65f0ca3640c4533f0bca743cd61b71cb66335'
    'USER' => 'www-data'
    'SCRIPT_NAME' => '/en/index.php'
    'REQUEST_URI' => '/en/actions/module/api/test'
    'QUERY_STRING' => ''
    'REQUEST_METHOD' => 'GET'
    'SERVER_PROTOCOL' => 'HTTP/1.1'
    'GATEWAY_INTERFACE' => 'CGI/1.1'
    'REDIRECT_URL' => '/en/actions/module/api/test'
    'REMOTE_PORT' => '61608'
    'SCRIPT_FILENAME' => '/var/www/public/en/index.php'
    'SERVER_ADMIN' => 'lw@goldinteractive.ch'
    'CONTEXT_DOCUMENT_ROOT' => '/var/www/public/'
    'CONTEXT_PREFIX' => ''
    'REQUEST_SCHEME' => 'http'
    'DOCUMENT_ROOT' => '/var/www/public/'
    'REMOTE_ADDR' => '172.29.0.1'
    'SERVER_PORT' => '8001'
    'SERVER_ADDR' => '172.29.0.4'
    'SERVER_NAME' => 'localhost'
    'SERVER_SOFTWARE' => 'Apache/2.4.46 (Unix)'
    'SERVER_SIGNATURE' => ''
    'HTTP_COOKIE' => '_ga=GA1.1.508611391.1635146481; disclaimer-agreed=true; _pk_id.1.1fff=d28294b956ee740f.1634900861.6.1637152193.1637152192.; remember_web_59ba36addc2b2f9401580f014c7f58ea4e30989d=eyJpdiI6IkRIRnFDREw0OVwvSVE5NmJIS1BwYzdnPT0iLCJ2YWx1ZSI6ImsyVDNWVTRlY0Y3aysrd1puSDdCUW9Ld2kxNCtKUWlxK1RHSTF5ZDBuclNGZ1o1aHRKQXE0UWxoaWMwY0NPaWhGWkhrYnFvck4wb1dCVEZwWmFhdFVKT0Z2ZnVBaHRKM0dBZThTYndrbHZZPSIsIm1hYyI6ImMxODMxY2YxNTk3Njg2OWM2NjllNTllYzhiNzQwMzUxNTU3ODYzMTBmZDM4Y2YyYWZkMDMxOTFmOWRiNTcwY2QifQ%3D%3D; Phpstorm-77bcfe0c=ca1f355a-8d80-4d77-9148-f069363be002; cookie-agreed=2; disclaimeragreed=true; cookieconsent_status=dismiss; Craft-44bcc948-02ce-4827-becf-dd701a5a57b9:siteId=2; popup-1518294-341259=true; form_posted_1=1643108141; _gcl_au=1.1.1532441258.1643371771; XSRF-TOKEN=eyJpdiI6IjZYdjh6MlBFR2Q2WGRyMnM2bmVJcmc9PSIsInZhbHVlIjoia0k3UVZnNDluZlwvZFBnMmxPMlZ3V3Jienp5ZkRzaksyOXJtQ2dJK3RGTFlwdFRcLzNLTm9VUDlTYjh6ZHpLU0RCIiwibWFjIjoiNGIxYjk4NWRlMmQxNzIzODQ5MjFhN2M4MmRiMjNiNWNmMzg1MWMzMTg5ODllMGI1ZmIwMzNlNmFhNmE0MDM4NCJ9; ultra_session=eyJpdiI6IkxZQitYa2sza1VsWTJabVE2SnlUOWc9PSIsInZhbHVlIjoiRHpqUnY3NzhJVE5OR2twYlhpMzlxRmJQK3dGdnVRU2QrcURQTEdjZEREVlROZ1JqMWhPMjBETmlvVkFNYVBRaiIsIm1hYyI6Ijk1NzAxODZmNjhlMGQzODYxY2YzZTkyNGQ5ZGJiYzAzNDc0ZDJlYWQ2OGY3NGY0NDk0YTdjYTc3MWFlYWQwYWUifQ%3D%3D; _ga_9K7ZC2V4JT=GS1.1.1644409527.8.1.1644409889.0; _gid=GA1.1.297472302.1644412065; 1031b8c41dfff97a311a7ac99863bdc5_username=cf2ffa316fccd97085e8ad5ef2af7f88d28532fb7d8126a34c56acfb9d508a0ca%3A2%3A%7Bi%3A0%3Bs%3A41%3A%221031b8c41dfff97a311a7ac99863bdc5_username%22%3Bi%3A1%3Bs%3A5%3A%22admin%22%3B%7D; CraftSessionId=5e8d5c019ee519ff518587428a6e30e6; 1031b8c41dfff97a311a7ac99863bdc5_identity=74febac355e2fad165ae7103ddd70e7ebecc5e6f1df818b4e151b982c91f9830a%3A2%3A%7Bi%3A0%3Bs%3A41%3A%221031b8c41dfff97a311a7ac99863bdc5_identity%22%3Bi%3A1%3Bs%3A163%3A%22%5B1%2C%22%5B%5C%226TCNuI3ge0MtAArI0eDs3ABVuVJGQ6PECMZ-yc_ti-SCWRYb9obyk2t93K4rHbu38etfIPQ-DiqXbOpOivxH1Pe_BU5DaMZ40VXc%5C%22%2Cnull%2C%5C%221fc7dcee4b92527bbbc893a4520b6cfd%5C%22%5D%22%2C31536000%5D%22%3B%7D; CRAFT_CSRF_TOKEN=d3426cb155f4d0e817c8d7ab96a69452d1857efa3ace4a2d297b101e4f5c4785a%3A2%3A%7Bi%3A0%3Bs%3A16%3A%22CRAFT_CSRF_TOKEN%22%3Bi%3A1%3Bs%3A208%3A%225xO7ZnJUWED2EzcoN69-SVIh_R0BDBR5lldYu-BF%7Cbe3a882afc5bb5dbb5dd59838bbecfc9ee0bc096e6d83c85353af67fedfcf37a5xO7ZnJUWED2EzcoN69-SVIh_R0BDBR5lldYu-BF%7C1%7C%242y%2413%247xi9glir.Pl.HabuClrQwuXL84WoeDbwMcWav86Vkl.7iH0VpPDJy%22%3B%7D'
    'HTTP_ACCEPT_LANGUAGE' => 'de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7,lb;q=0.6,fy;q=0.5,fr;q=0.4,it;q=0.3'
    'HTTP_ACCEPT_ENCODING' => 'gzip, deflate, br'
    'HTTP_SEC_FETCH_DEST' => 'document'
    'HTTP_SEC_FETCH_USER' => '?1'
    'HTTP_SEC_FETCH_MODE' => 'navigate'
    'HTTP_SEC_FETCH_SITE' => 'none'
    'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9'
    'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36'
    'HTTP_UPGRADE_INSECURE_REQUESTS' => '1'
    'HTTP_SEC_CH_UA_PLATFORM' => '\"macOS\"'
    'HTTP_SEC_CH_UA_MOBILE' => '?0'
    'HTTP_SEC_CH_UA' => '\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"98\", \"Google Chrome\";v=\"98\"'
    'HTTP_CONNECTION' => 'keep-alive'
    'HTTP_HOST' => 'localhost:8001'
    'REDIRECT_STATUS' => '200'
    'FCGI_ROLE' => 'RESPONDER'
    'PHP_SELF' => '/en/index.php'
    'REQUEST_TIME_FLOAT' => 1644476441.8095
    'REQUEST_TIME' => 1644476441
    'argv' => []
    'argc' => 0
    'ENV' => 'local'
    'DB_HOST' => 'host.docker.internal'
    'DB_PORT' => '3306'
    'DB_DATABASE' => '....'
    'DB_USERNAME' => '....'
    'DB_PASSWORD' => '••••'
    'DEV_MODE' => '0'
    'CACHE' => '0'
    'FULLPAGE_CACHE' => '0'
    'BASE_URL' => 'http://localhost:8001'
]

@brandonkelly
Copy link
Member

@lukasNo1 Are you still having issues with this? Just tested again locally and am unable to reproduce your error with the same general setup.

@lukasNo1
Copy link
Author

Yes it it still the same error. However i also tested it with a completely fresh craft installation and there it works. Seems to be something in our existing projects. I'll have a look into it.

@bzin
Copy link

bzin commented May 3, 2022

Hi @brandonkelly, I am currently having this problem with a project where I created a new site language but need to disable another. Now my graphql mutations do not work but I still have a valid sites. My message is 'Couldn’t propagate element to other site.'.

@brandonkelly
Copy link
Member

@bzin By “disable another” – did you actually delete the other site? Or just mark it as disabled in its settings?

@bzin
Copy link

bzin commented May 9, 2022

Hi @brandonkelly , the Sites were just disabled in the settings. We use these to have different languages for our content structure. Different servers might have different enabled Sites.

@brandonkelly
Copy link
Member

Are you programmatically disabling them on deployment or something? Are you disabling the primary site ever, by chance? If so, that is not supported and will lead to bugs.

@bzin
Copy link

bzin commented May 16, 2022

Not, the primary site but I do try to disable the ones that are not being used.

@brandonkelly
Copy link
Member

This should be fixed now for the next release.

To get the fix early, change your craftcms/cms requirement in composer.json to "dev-develop as 4.0.4" and run composer update.

@brandonkelly
Copy link
Member

Craft 4.0.5 is out now with that fix.

@brandonkelly
Copy link
Member

This is fixed in Craft 3.7.51 as well, now (#11741).

@bzin
Copy link

bzin commented Aug 10, 2022

This is great @brandonkelly! I will check if this can be useful for us on the project we still rely on Craft 3.

We will not be able to update to 4 at this moment... at least some plugin dependencies are solved 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants