Skip to content

Commit

Permalink
add a function to download all log files.
Browse files Browse the repository at this point in the history
  • Loading branch information
leetaei committed Nov 4, 2016
1 parent e83720c commit d0783e7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
18 changes: 8 additions & 10 deletions includes/class/job/mcl_job.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,19 @@ class MCL_JOB extends PUBLIC_MCL_JOB {
// Insert a new job.
if (parent::insert()) {

// If $this->working_dir is empty, assigns the default working directory.
if (empty($this->working_dir)) {
$this->working_dir = mcl_get_config_setting('mcl_working_dir');
}
// Get MCL user directory.
$mcl_user_directory = mcl_get_config_setting('mcl_working_dir') . '/user';

// Creates the user directory if not exists.
if (empty($this->user_dir)) {
$drupal_user = MCL_USER::getDrupalUser($this->user_id);
$this->user_dir = $this->working_dir . '/' . $drupal_user->name;
}
// Gets username.
$drupal_user = MCL_USER::getDrupalUser($this->user_id);
$username = $drupal_user->name;

// Updates MCL directories.
$this->user_dir = "$mcl_user_directory/$username";
$this->job_dir = $this->user_dir . '/' . $this->job_id;
$this->log_dir = $this->job_dir . '/logs';
$this->file_dir = $this->job_dir . '/files';
$this->setPropByKey('working_dir', $this->working_dir);
$this->setPropByKey('working_dir', $this->user_dir);
$this->setPropByKey('user_dir', $this->user_dir);
$this->setPropByKey('job_dir', $this->job_dir);
$this->setPropByKey('log_dir', $this->log_dir);
Expand Down
4 changes: 3 additions & 1 deletion includes/class/template/module/mcl_template_marker.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ class MCL_TEMPLATE_MARKER extends MCL_TEMPLATE {
MCL_CHADO_ORGANISM::checkOrganism($this, $line['genus'], $line['species']);

// Checks SNP_chip_name.
// MCL_CHADO_LIBRARY::checkLibrary($this, $line['snp_chip']);
$organism = MCL_CHADO_ORGANISM::getOrganism($line['genus'], $line['species']);
$type_id = $this->cvterms['SITE_CV']['SNP_chip'];
MCL_CHADO_LIBRARY::checkLibrary($this, $line['snp_chip_name'], $type_id. $organism->getOrganismID());

// Checks contacts.
MCL_CHADO_CONTACT::checkContact($this, $line['contact'], '[;,]');
Expand Down
2 changes: 1 addition & 1 deletion includes/form/mcl.job_view.form.inc
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ function _mcl_get_detail_table(MCL_JOB_UPLOAD $mcl_job) {
$rows []= array('<b>Data Template File</b>', $link_template);
$rows []= array('<b>Submit Date</b>', $mcl_job->getSubmitDate());
$rows []= array('<b>Complete Date</b>', $complete_date);
// $rows []= array('<b>Log Files</b>', $link_log);
$rows []= array('<b>Log Files</b>', $link_log);

// Table variables.
$table_vars = array(
Expand Down
25 changes: 14 additions & 11 deletions includes/mcl.inc
Original file line number Diff line number Diff line change
Expand Up @@ -161,20 +161,23 @@ function mcl_download_log($job_id) {
$log_root_dir = dirname($mcl_job->getLogDir());

// Sets zip path and name.
$filename = "mcl-$job_id-" . date("Y-m-d-G-i-s") . '.zip';
$filepath = file_directory_temp() . "/$filename";

// Zips the folder.
$cmd = "cd $log_root_dir;zip -rq $filepath logs";
exec("which zip", $output, $return_var);
if ($return_var) {
drupal_set_message("Failed to zip the folder");

// return FALSE;
$filename = "mcl-$job_id-logs.zip";
$filepath = $mcl_job->getLogDir() . "/$filename";

// Create a zip file.
$zip = new ZipArchive;
$zip->open($filepath, ZipArchive::OVERWRITE);

$files = mcl_retrive_files($mcl_job->getLogDir(), '/.*\.log$/');
foreach ($files as $file) {
$file_name = basename($file);
$rel_path = str_replace($log_root_dir, '', dirname($file));
$zip->addFile($file, "$rel_path/$file_name");
}
$zip->close();

// Attaches the zip file.
header("Content-Type: text/plain");
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=$filename");
readfile($filepath);
exit();
Expand Down

0 comments on commit d0783e7

Please sign in to comment.