/**
* @param $documentId
* @param $config
* @throws \Exception
*/
public function preparePdfGeneration($documentId, $config)
{
$document = $this->getPrintDocument($documentId);
if (Model\Tool\TmpStore::get($document->getLockKey())) {
throw new \Exception("Process with given document alredy running.");
}
Model\Tool\TmpStore::add($document->getLockKey(), true);
$jobConfig = new \stdClass();
$jobConfig->documentId = $documentId;
$jobConfig->config = $config;
$this->saveJobConfigObjectFile($jobConfig);
$this->updateStatus($documentId, 0, "prepare_pdf_generation");
$args = ["-p " . $jobConfig->documentId];
$env = \Pimcore\Config::getEnvironment();
if ($env !== false) {
$args[] = "--environment=" . $env;
}
$cmd = Tool\Console::getPhpCli() . " " . realpath(PIMCORE_PATH . DIRECTORY_SEPARATOR . "cli" . DIRECTORY_SEPARATOR . "console.php") . " web2print:pdf-creation " . implode(" ", $args);
Logger::info($cmd);
if (!$config['disableBackgroundExecution']) {
Tool\Console::execInBackground($cmd, PIMCORE_LOG_DIRECTORY . DIRECTORY_SEPARATOR . "web2print-output.log");
} else {
Processor::getInstance()->startPdfGeneration($jobConfig->documentId);
}
}