| @@ -1325,13 +1325,39 @@ | ||
| 1325 | 1325 | $this->cache_manager->invalidate_all_cache(); |
| 1326 | 1326 | } |
| 1327 | 1327 | |
| 1328 | 1328 | // AUTO-DEPLOY: Automatically regenerate and deploy schema when settings change |
| 1329 | - if ($success && !empty($settings['auto_deploy'])) { | |
| 1329 | + if ($success && self::should_auto_deploy($settings, $this->get_settings($context_type, $context_id))) { | |
| 1330 | 1330 | $this->auto_deploy_schema_on_settings_change($context_type, $context_id, $settings); |
| 1331 | 1331 | } |
| 1332 | 1332 | |
| 1333 | 1333 | return $success; |
| 1334 | + } | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + /** | |
| 1338 | + * Whether a save should redeploy the schema it changed. | |
| 1339 | + * | |
| 1340 | + * `auto_deploy` is a stored setting (on by default), not something a save | |
| 1341 | + * restates. Reading it off the incoming patch meant a partial save — which | |
| 1342 | + * is what the admin screen sends, one field at a time — skipped | |
| 1343 | + * auto-deploy on a site that had it switched on, and the deployed snapshot | |
| 1344 | + * the front end serves kept the name, logo and sameAs it was deployed | |
| 1345 | + * with, however often the user saved (#904, the gate #12 left in place). | |
| 1346 | + * | |
| 1347 | + * A patch that does carry the key still wins, so a caller can deploy or | |
| 1348 | + * hold deliberately. | |
| 1349 | + * | |
| 1350 | + * @param array $patch Settings being saved | |
| 1351 | + * @param array $stored Settings as stored, after the save | |
| 1352 | + * @return bool | |
| 1353 | + */ | |
| 1354 | + public static function should_auto_deploy(array $patch, array $stored): bool { | |
| 1355 | + if (array_key_exists('auto_deploy', $patch)) { | |
| 1356 | + return !empty($patch['auto_deploy']); | |
| 1357 | + } | |
| 1358 | + | |
| 1359 | + return !empty($stored['auto_deploy']); | |
| 1334 | 1360 | } |
| 1335 | 1361 | |
| 1336 | 1362 | /** |
| 1337 | 1363 | * Auto-deploy schema when settings change |