You are here

function _forena_copy_reports in Forena Reports 7.3

Same name and namespace in other branches
  1. 6.2 forena.admin.inc \_forena_copy_reports()
  2. 6 forena.admin.inc \_forena_copy_reports()
  3. 7 forena.admin.inc \_forena_copy_reports()
  4. 7.2 forena.admin.inc \_forena_copy_reports()

Recursively , all report files from the source directory to the destination directory

Parameters

$src_dir Source directory to copy files from:

1 call to _forena_copy_reports()
forena_sync_reports in ./forena.module
Enter description here ...

File

./forena.module, line 1258

Code

function _forena_copy_reports($src_dir, $overwrite = FALSE, $subdir = FALSE) {
  static $dest_dir = '';
  static $i = 0;
  if (!$subdir) {
    $dest_dir = forena_report_path();
  }
  if (!file_exists($dest_dir)) {
    mkdir($dest_dir);
  }
  $d = dir($src_dir);
  while (false !== ($rpt_file = $d
    ->read())) {
    $src_file = $d->path . '/' . $rpt_file;
    $dest_file = $dest_dir . '/' . $rpt_file;
    if (is_file($src_file)) {
      if (is_writable($dest_file) && $overwrite || !file_exists($dest_file)) {
        file_put_contents($dest_file, file_get_contents($src_file));
        $i++;
      }
      else {
        drupal_set_message($dest_file . ' not writeable', 'error');
      }
    }
    else {
      if (strpos($rpt_file, '.') !== 0) {

        // Recurse into sub directory
        $src_save = $src_dir;
        $dest_save = $dest_dir;
        $dest_dir .= '/' . $rpt_file;
        $src_dir .= '/' . $rpt_file;
        _forena_copy_reports($src_dir, $overwrite, TRUE);
        $src_dir = $src_save;
        $dest_dir = $dest_save;
      }
    }
  }
  $d
    ->close();
  return $i;
}