/** * @param array $files * @param int $orderID * @return HTMLText */ protected function initiateOfflineProcessing(array $files, $orderID) { // is there already an existing temp file for this combination? $existingFile = DownloadTempFile::get_by_files($files); if ($existingFile && $existingFile->exists()) { if ($existingFile->ProcessingState === DownloadTempFile::COMPLETE) { $this->addToLog($orderID, $files, $existingFile); return $this->sendTempFile($existingFile); } else { return $this->displayCrunchingPage($existingFile); } } // this will get logged when crunching is complete Session::set('DownloadableProcessingOrderID', $orderID); // Create an empty DownloadTempFile $parent = Folder::find_or_make(Config::inst()->get('Downloadable', 'zip_folder')); $dl = new DownloadTempFile(); $dl->setParentID($parent->ID); $dl->Title = sha1(uniqid()); $dl->Name = $dl->Title . '.' . (count($files) == 1 ? $files[0]->getExtension() : 'zip'); $dl->write(); foreach ($files as $file) { $dl->SourceFiles()->add($file); } $dl->updateFileKey(); $dl->write(); // Display the "crunching" page so the user isn't left wondering what's going on return $this->displayCrunchingPage($dl); }
/** * Sends the temp file in a safe way for large files. * If X-sendfile is enabled it uses that, otherwise it uses a * redirect. This is safe because the temp files all have random * names and will be deleted within a few days. * * @param DownloadTempFile $file * @return SS_HTTPResponse */ protected function sendTempFile(DownloadTempFile $file) { $file->LastUsedAt = date('Y-m-d H:i:s'); $file->write(); if (Config::inst()->get('Downloadable', 'use_xsendfile')) { $this->sendFile($file); } else { return $this->redirect($file->Link()); } }