Commit b329df6e authored by sun's avatar sun

#370402 by sun: Added option to download snapshot files.

parent 657b85e8
......@@ -6,6 +6,7 @@ Demo x.x-x.x, xxxx-xx-xx
Demo 5.x-1.x, xxxx-xx-xx
------------------------
#370402 by sun: Added option to download snapshot files.
#294879 by sun: Changed include file inclusion.
#496620 by evoltech: Fixed paths in README.txt.
by smk-ka: Added admin_menu cache table to exclude list.
......
......@@ -372,8 +372,13 @@ function demo_get_dumps() {
}
$option['#description'] = '';
if (!empty($info['description'])) {
$option['#description'] .= $info['description'] . '<br /><br />';
$option['#description'] .= '<p>' . $info['description'] . '</p>';
}
$targs = array(
'@info-file-url' => url('demo/download/' . $file->name . '/info'),
'@sql-file-url' => url('demo/download/' . $file->name . '/sql'),
);
$option['#description'] .= '<p>' . t('Download: <a href="@info-file-url">.info file</a>, <a href="@sql-file-url">.sql file</a>', $targs) . '</p>';
if (count($info['modules']) > 1) {
// Remove required core modules and obvious modules from module list.
$info['modules'] = array_diff($info['modules'], array('block', 'filter', 'node', 'system', 'user', 'watchdog', 'demo'));
......@@ -532,6 +537,31 @@ function demo_autocomplete($string = '') {
exit();
}
/**
* Transfer (download) a snapshot file.
*
* @param $filename
* The snapshot filename to transfer.
* @param $type
* The file type, i.e. extension to transfer.
*
* @todo Allow to download an bundled archive of snapshot files.
*/
function demo_download($filename, $type) {
$fileconfig = demo_get_fileconfig($filename);
if (!isset($fileconfig[$type . 'file']) || !file_exists($fileconfig[$type . 'file'])) {
return MENU_NOT_FOUND;
}
// Force the client to re-download and trigger a file save download.
$headers = array(
'Cache-Control: private',
'Content-Type: application/octet-stream',
'Content-Length: ' . filesize($fileconfig[$type . 'file']),
'Content-Disposition: attachment, filename=' . $fileconfig[$type],
);
file_transfer($fileconfig[$type . 'file'], $headers);
}
/**
* Sets a specific snapshot as default for cron runs or the site reset block.
*
......
......@@ -71,11 +71,16 @@ function demo_menu($may_cache) {
);
$items[] = array(
'path' => 'demo/autocomplete',
'title' => t('Demo Site autocomplete'),
'callback' => 'demo_autocomplete',
'access' => $admin_access,
'type' => MENU_CALLBACK,
);
$items[] = array(
'path' => 'demo/download',
'callback' => 'demo_download',
'access' => $admin_access,
'type' => MENU_CALLBACK,
);
}
else if (strpos($_GET['q'], 'admin/build/demo') === 0 || strpos($_GET['q'], 'demo') === 0) {
require_once drupal_get_path('module', 'demo') . '/demo.admin.inc';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment