function do_main() { $config = KTConfig::getSingleton(); $useQueue = $config->get('export/useDownloadQueue', true); // Create the export code $exportCode = KTUtil::randomString(); $this->oZip = new ZipFolder('', $exportCode); if (!$this->oZip->checkConvertEncoding()) { redirect(KTBrowseUtil::getUrlForFolder($this->oFolder)); exit(0); } $bNoisy = $config->get("tweaks/noisyBulkOperations"); $bNotifications = $config->get('export/enablenotifications', 'on') == 'on' ? true : false; $sCurrentFolderId = $this->oFolder->getId(); $url = KTUtil::addQueryStringSelf(sprintf('action=downloadZipFile&fFolderId=%d&exportcode=%s', $sCurrentFolderId, $exportCode)); $folderurl = KTBrowseUtil::getUrlForFolder($this->oFolder); if ($useQueue) { DownloadQueue::addItem($exportCode, $sCurrentFolderId, $sCurrentFolderId, 'folder'); $task_url = KTUtil::kt_url() . '/bin/ajaxtasks/downloadTask.php'; $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate('ktcore/action/bulk_download'); $aParams = array('folder_url' => $folderurl, 'url' => $task_url, 'code' => $exportCode, 'download_url' => $url); return $oTemplate->render($aParams); } // Get all folders and sub-folders $sWhereClause = "parent_folder_ids = '{$sCurrentFolderId}' OR\n parent_folder_ids LIKE '{$sCurrentFolderId},%' OR\n parent_folder_ids LIKE '%,{$sCurrentFolderId},%' OR\n parent_folder_ids LIKE '%,{$sCurrentFolderId}'"; $aFolderList = $this->oFolder->getList($sWhereClause); // Get any folder shortcuts within the folders $aLinkedFolders = KTBulkAction::getLinkingEntities($aFolderList); $aFolderList = array_merge($aFolderList, $aLinkedFolders); // Add the folders to the zip file $aFolderObjects = array($sCurrentFolderId => $this->oFolder); if (!empty($aFolderList)) { foreach ($aFolderList as $oFolderItem) { $itemId = $oFolderItem->getId(); $linkedFolder = $oFolderItem->getLinkedFolderId(); // If the folder has been added or is a shortcut then skip // The shortcut folders don't need to be added as their targets will be added. if (array_key_exists($itemId, $aFolderObjects) || !empty($linkedFolder)) { continue; } $this->oZip->addFolderToZip($oFolderItem); $aFolderObjects[$oFolderItem->getId()] = $oFolderItem; } } // Get the list of folder ids $aFolderIds = array_keys($aFolderObjects); // Get all documents in the folder list $aQuery = $this->buildQuery($aFolderIds); $aDocumentIds = DBUtil::getResultArrayKey($aQuery, 'id'); if (PEAR::isError($aDocumentIds)) { $this->addErrorMessage(_kt('There was a problem exporting the documents: ') . $aDocumentIds->getMessage()); redirect(KTBrowseUtil::getUrlForFolder($this->oFolder)); exit(0); } // Redirect if there are no documents and no folders to export if (empty($aDocumentIds) && empty($aFolderList)) { $this->addErrorMessage(_kt("No documents found to export")); redirect(KTBrowseUtil::getUrlForFolder($this->oFolder)); exit(0); } $this->oPage->template = "kt3/minimal_page"; $this->handleOutput(""); // Add the documents to the zip file if (!empty($aDocumentIds)) { foreach ($aDocumentIds as $iId) { $oDocument = Document::get($iId); $sFolderId = $oDocument->getFolderID(); if (!KTWorkflowUtil::actionEnabledForDocument($oDocument, 'ktcore.actions.document.view')) { $this->addErrorMessage($oDocument->getName() . ': ' . _kt('Document cannot be exported as it is restricted by the workflow.')); continue; } $oFolder = isset($aFolderObjects[$sFolderId]) ? $aFolderObjects[$sFolderId] : Folder::get($sFolderId); if ($bNoisy) { $oDocumentTransaction =& new DocumentTransaction($oDocument, "Document part of bulk export", 'ktstandard.transactions.bulk_export', array()); $oDocumentTransaction->create(); } // fire subscription alerts for the downloaded document if ($bNotifications) { //$oSubscriptionEvent = new SubscriptionEvent(); //$oSubscriptionEvent->DownloadDocument($oDocument, $oFolder); } $this->oZip->addDocumentToZip($oDocument, $oFolder); } } $sExportCode = $this->oZip->createZipFile(TRUE); $oTransaction = KTFolderTransaction::createFromArray(array('folderid' => $this->oFolder->getId(), 'comment' => "Bulk export", 'transactionNS' => 'ktstandard.transactions.bulk_export', 'userid' => $_SESSION['userID'], 'ip' => Session::getClientIP())); $sReturn = '<p>' . _kt('Creating zip file. Compressing and archiving in progress ...') . '</p>'; $sReturn .= "<p style='margin-bottom: 10px;'><br /><b>" . _kt('Warning! Please wait for archiving to complete before closing the page.') . '</b><br />' . _kt('Note: Closing the page before the download link displays will cancel your Bulk Download.') . '</p>'; $sReturn .= '<p>' . _kt('Once your download is complete, click <a href="' . $folderurl . '">here</a> to return to the original folder') . "</p>\n"; print $sReturn; printf("</div></div></body></html>\n"); printf('<script language="JavaScript"> function kt_bulkexport_redirect() { document.location.href = "%s"; } callLater(2, kt_bulkexport_redirect); </script>', $url); exit(0); }
<?php chdir(dirname(__FILE__)); require_once '../../config/dmsDefaults.php'; require_once KT_LIB_DIR . '/foldermanagement/compressionArchiveUtil.inc.php'; /** * The download task provides 2 pieces of functionality. The first is to process the download queue and the second is to "ping" the download queue. * The processing of the download queue will create the archives for the bulk download action and set a flag to indicate their completion. * The "ping" will check if the flag has been set and inform the user that the archive is ready for download. */ $queue = new DownloadQueue(); // Check for a ping then check if the download is finished $ping = isset($_POST['ping']) ? $_POST['ping'] : false; if ($ping == 'ping') { $code = $_POST['code']; $status = $queue->isDownloadAvailable($code); if ($status === false) { echo 'wait'; } else { $str = ''; // display any error messages if (!empty($status)) { $str = '<div><b>' . _kt('The following errors occurred during the download') . ': </><br />'; $str .= '<table style="padding-top: 5px;" cellspacing="0" cellpadding="5">'; foreach ($status as $msg) { $str .= '<tr><td style="border: 1px #888 solid;">' . $msg . '</td></tr>'; } $str .= '</table></div>'; } echo $str; }
function perform_action($oEntity) { // TODO find a way to do bulk email $exportCode = $_SESSION['exportcode']; $this->oZip = ZipFolder::get($exportCode); $oQueue = new DownloadQueue(); $config = KTConfig::getSingleton(); $useQueue = $config->get('export/useDownloadQueue'); if (is_a($oEntity, 'Document')) { $oDocument = $oEntity; if ($oDocument->isSymbolicLink()) { $oDocument->switchToLinkedCore(); } if ($useQueue) { DownloadQueue::addItem($this->sExportCode, $this->oFolder->getId(), $oDocument->iId, 'document'); } else { $oQueue->addDocument($this->oZip, $oDocument->iId); } } else { if (is_a($oEntity, 'Folder')) { $aDocuments = array(); $oFolder = $oEntity; if ($oFolder->isSymbolicLink()) { $oFolder = $oFolder->getLinkedFolder(); } $sFolderId = $oFolder->getId(); if ($useQueue) { DownloadQueue::addItem($this->sExportCode, $this->oFolder->getId(), $sFolderId, 'folder'); } else { $oQueue->addFolder($this->oZip, $sFolderId); } } } return "DownloadDocument"; }