Add support for STATIC_EXPORT_REQUEST_BUILD env var
Due to the new way of exporting data by the ExporterStackExecutor (where data export is delayed until the end of Symfony's request process) we have encountered an edge case:
- On CLI, change a node and save it (hence, triggering an export).
- After that, manually trigger a build.
- That build, in fact, does not run, because the above export operation is not yet executed. And being on a CLI, the export operation does not request a build
public function onPublish(SchedulerEvent $event) {
$node = $event->getNode();
$node->save();
// The above save() call will export the node, but a build won't be
// requested, so manually request a build.
// ... $staticBuilder initialization code deleted for the sake of clarity
$staticBuilder->init();
}
So we cannot use this approach to manually trigger a build. Instead, that build must be requested by the ExporterStackExecutor. When running on Drupal's UI, ExporterStackExecutor does request a build, but on CLI there is no way to opt-in/out on requesting a build. STATIC_EXPORT_REQUEST_BUILD
environmental variable solves this problem, turning the above code into this:
public function onPublish(SchedulerEvent $event) {
$node = $event->getNode();
putenv("STATIC_EXPORT_REQUEST_BUILD=true");
$node->save();
putenv("STATIC_EXPORT_REQUEST_BUILD"); // Delete env var
}
To opt-out on requesting a build, simply use putenv("STATIC_EXPORT_REQUEST_BUILD=false");