You are here

protected function FileSystemBase::scanInclude in Forena Reports 8

Parse a drectory

Parameters

string $directory:

1 call to FileSystemBase::scanInclude()
FileSystemBase::scan in src/File/FileSystemBase.php

File

src/File/FileSystemBase.php, line 76
FileSystemBase.inc File toolbox for manipulating files contained tn the report directory.

Class

FileSystemBase

Namespace

Drupal\forena\File

Code

protected function scanInclude($directory) {
  $is_include = strpos($directory, $this->dir) !== 0;
  $files = array();
  $this
    ->scanDirectory($directory, $files);
  foreach ($files as $ext => $files_of_type) {
    foreach ($files_of_type as $file => $mtime) {

      // Determine file name without extension.
      $base_name = substr($file, strlen($directory) + 1, -1 * (strlen($ext) + 1));

      // NO Cache entry exists.
      if (!isset($this->cache[$ext][$base_name])) {
        $obj = new \stdClass();
        $obj->file = $file;
        $obj->ext = $ext;
        $obj->base = $base_name;
        $obj->mtime = $mtime;
        $obj->include = $is_include;
        $obj->override = FALSE;
        $this
          ->extractMetaData($obj);
        $this->cache[$ext][$base_name] = $obj;
      }
      else {

        // If its our first pass on this replace the entry
        $entry = $this->cache[$ext][$base_name];

        // Find out if we are replacing an include
        if (!$is_include && $entry->include) {
          $entry->file = $file;
          $entry->mtime = $mtime;
          $entry->include = $is_include;
          $entry->override = TRUE;
          $this
            ->extractMetaData($entry);
          $this->needSave = TRUE;
        }

        // Find out it is the same file and it needs to be changed.
        if ($entry->file == $file && $entry->mtime != $mtime) {
          $entry->mtime = $mtime;
          $this
            ->extractMetaData($entry);
          $this->needSave = TRUE;
        }

        // If its a different file make sure its override is set
        if ($entry->file != $file && !$entry->override) {
          $entry->override = TRUE;
          $this->needSave = TRUE;
        }
        unset($this->filesToDelete[$ext][$base_name]);
      }
    }
  }
}