ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
ilCopyFilesToTempDirectoryJob Class Reference

Description of class class. More...

+ Inheritance diagram for ilCopyFilesToTempDirectoryJob:
+ Collaboration diagram for ilCopyFilesToTempDirectoryJob:

Public Member Functions

 __construct ()
 Constructor. More...
 
 getInputTypes ()
 
 getOutputType ()
 
 isStateless ()
 
 run (array $input, Observer $observer)
 run the job More...
 
 getExpectedTimeOfTaskInSeconds ()
 
Returns
int the amount of seconds this task usually taskes. If your task-duration scales with the the amount of data, try to set a possible high value of try to calculate it. If a task duration exceeds this value, it will be displayed as "possibly failed" to the user
More...
 
- Public Member Functions inherited from ILIAS\BackgroundTasks\Implementation\Tasks\AbstractJob
 getInput ()
 
Returns
mixed returns the input array
More...
 
- Public Member Functions inherited from ILIAS\BackgroundTasks\Implementation\Tasks\AbstractTask
 setInput (array $values)
 
 getOutput ()
 
 getInput ()
 
 getType ()
 
 unfoldTask ()
 Unfold the task. More...
 
 getRemoveOption ()
 
Returns
Option An Option to remove the current task and do some cleanup if possible. This Option is displayed if the Bucket is completed. You do not have to provide an additional Option to remove in your UserInteraction, the remove-Option is added to the list of Options (last position)
See also
self::getAbortOption();
More...
 
 getAbortOption ()
 
Returns
Option In case a Job is failed or did not respond for some time, an Abort-Option is displayed. There is already a Standard-Abort-Option registered, you can override with your own and do some cleanup if possible.
More...
 

Protected Member Functions

 createUniqueTempDirectory ()
 
 createTargetDirectory ($a_tmpdir)
 
 copyFiles ($tmpdir, ilCopyDefinition $definition)
 Copy files. More...
 
- Protected Member Functions inherited from ILIAS\BackgroundTasks\Implementation\Tasks\AbstractTask
 checkTypes ($values)
 
 extractType ($value)
 

Protected Attributes

 $target_directory
 
- Protected Attributes inherited from ILIAS\BackgroundTasks\Implementation\Tasks\AbstractTask
 $input = []
 
 $output
 

Private Attributes

 $logger = null
 

Additional Inherited Members

- Data Fields inherited from ILIAS\BackgroundTasks\Implementation\Tasks\AbstractTask
const MAIN_REMOVE = 'bt_main_remove'
 
const MAIN_ABORT = 'bt_main_abort'
 

Detailed Description

Description of class class.

Author
Stefan Meyer smeye.nosp@m.r.il.nosp@m.ias@g.nosp@m.mx.d.nosp@m.e

Definition at line 17 of file class.ilCopyFilesToTempDirectoryJob.php.

Constructor & Destructor Documentation

◆ __construct()

ilCopyFilesToTempDirectoryJob::__construct ( )

Constructor.

Definition at line 33 of file class.ilCopyFilesToTempDirectoryJob.php.

References $GLOBALS.

34  {
35  $this->logger = $GLOBALS['DIC']->logger()->cal();
36  }
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64

Member Function Documentation

◆ copyFiles()

ilCopyFilesToTempDirectoryJob::copyFiles (   $tmpdir,
ilCopyDefinition  $definition 
)
protected

Copy files.

Parameters
string$tmpdir
ilCopyDefinition$definition

Definition at line 131 of file class.ilCopyFilesToTempDirectoryJob.php.

References ilCopyDefinition\COPY_SOURCE_DIR, ilCopyDefinition\COPY_TARGET_DIR, ilCopyDefinition\getCopyDefinitions(), and ilUtil\makeDirParents().

Referenced by run().

132  {
133  foreach ($definition->getCopyDefinitions() as $copy_task) {
134  if($copy_task[ilCopyDefinition::COPY_SOURCE_DIR] === '') { // see https://mantis.ilias.de/view.php?id=31328
135  continue;
136  }
137  $this->logger->debug('Creating directory: ' . $tmpdir . '/' . dirname($copy_task[ilCopyDefinition::COPY_TARGET_DIR]));
139  $tmpdir . '/' . dirname($copy_task[ilCopyDefinition::COPY_TARGET_DIR])
140  );
141 
142 
143  if (!file_exists($copy_task[ilCopyDefinition::COPY_SOURCE_DIR])) {
144  // if the "file" to be copied is an empty folder the directory has to be created so it will be contained in the download zip
145  $is_empty_folder = preg_match_all("/\/$/", $copy_task[ilCopyDefinition::COPY_TARGET_DIR]);
146  if ($is_empty_folder) {
147  mkdir($tmpdir . '/' . $copy_task[ilCopyDefinition::COPY_TARGET_DIR]);
148  $this->logger->notice('Empty folder has been created: ' . $tmpdir . '/' . $copy_task[ilCopyDefinition::COPY_SOURCE_DIR]);
149  } else {
150  $this->logger->notice('Cannot find file: ' . $copy_task[ilCopyDefinition::COPY_SOURCE_DIR]);
151  }
152  continue;
153  }
154 
155 
156  $this->logger->debug(
157  'Copying from: ' .
158  $copy_task[ilCopyDefinition::COPY_SOURCE_DIR] .
159  ' to ' .
160  $tmpdir . '/' . $copy_task[ilCopyDefinition::COPY_TARGET_DIR]
161  );
162 
163  copy(
164  $copy_task[ilCopyDefinition::COPY_SOURCE_DIR],
165  $tmpdir . '/' . $copy_task[ilCopyDefinition::COPY_TARGET_DIR]
166  );
167  }
168 
169  return;
170  }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
getCopyDefinitions()
Get copy definitions.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createTargetDirectory()

ilCopyFilesToTempDirectoryJob::createTargetDirectory (   $a_tmpdir)
protected

Definition at line 115 of file class.ilCopyFilesToTempDirectoryJob.php.

References $target_directory, and ilUtil\makeDirParents().

Referenced by run().

116  {
117  $final_dir = $a_tmpdir . "/" . $this->target_directory;
118  ilUtil::makeDirParents($final_dir);
119  $this->logger->info('New final directory: ' . $final_dir);
120 
121  return $final_dir;
122  }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createUniqueTempDirectory()

ilCopyFilesToTempDirectoryJob::createUniqueTempDirectory ( )
protected
Returns
string absolute path to new temp directory
Todo:
refactor to new file system access Create unique temp directory

Definition at line 105 of file class.ilCopyFilesToTempDirectoryJob.php.

References ilUtil\ilTempnam(), and ilUtil\makeDirParents().

Referenced by run().

106  {
107  $tmpdir = ilUtil::ilTempnam();
108  ilUtil::makeDirParents($tmpdir);
109  $this->logger->info('New temp directory: ' . $tmpdir);
110 
111  return $tmpdir;
112  }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
static ilTempnam($a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getExpectedTimeOfTaskInSeconds()

ilCopyFilesToTempDirectoryJob::getExpectedTimeOfTaskInSeconds ( )

Returns
int the amount of seconds this task usually taskes. If your task-duration scales with the the amount of data, try to set a possible high value of try to calculate it. If a task duration exceeds this value, it will be displayed as "possibly failed" to the user

Implements ILIAS\BackgroundTasks\Task\Job.

Definition at line 176 of file class.ilCopyFilesToTempDirectoryJob.php.

177  {
178  return 30;
179  }

◆ getInputTypes()

ilCopyFilesToTempDirectoryJob::getInputTypes ( )
Returns
Type[] A list of types that are taken as input.

Implements ILIAS\BackgroundTasks\Task.

Definition at line 41 of file class.ilCopyFilesToTempDirectoryJob.php.

42  {
43  return
44  [
45  new SingleType(ilCopyDefinition::class),
46  ];
47  }

◆ getOutputType()

ilCopyFilesToTempDirectoryJob::getOutputType ( )
Returns
SingleType
Todo:
output should be file type

Implements ILIAS\BackgroundTasks\Task.

Definition at line 54 of file class.ilCopyFilesToTempDirectoryJob.php.

55  {
56  return new SingleType(StringValue::class);
57  }

◆ isStateless()

ilCopyFilesToTempDirectoryJob::isStateless ( )
Returns
bool returns true iff the job's output ONLY depends on the input. Stateless task results may be cached!

Implements ILIAS\BackgroundTasks\Task\Job.

Definition at line 60 of file class.ilCopyFilesToTempDirectoryJob.php.

61  {
62  return true;
63  }

◆ run()

ilCopyFilesToTempDirectoryJob::run ( array  $input,
Observer  $observer 
)

run the job

Parameters
Value$input
Observer$observer

Implements ILIAS\BackgroundTasks\Task\Job.

Definition at line 72 of file class.ilCopyFilesToTempDirectoryJob.php.

References $out, copyFiles(), createTargetDirectory(), and createUniqueTempDirectory().

73  {
74  $definition = $input[0];
75 
76  $this->logger->info('Called copy files job');
77 
78  $this->target_directory = $definition->getTempDir();
79 
80  // create temp directory
81  $tmpdir = $this->createUniqueTempDirectory();
82  $targetdir = $this->createTargetDirectory($tmpdir);
83 
84  // copy files from source to temp directory
85  //$this->copyFiles($targetdir, $input[0]);
86  $this->copyFiles($targetdir, $definition);
87 
88  // zip
89 
90  // return zip file name
91  $this->logger->debug('Returning new tempdirectory: ' . $targetdir);
92 
93  $out = new StringValue();
94  $out->setValue($targetdir);
95 
96  return $out;
97  }
copyFiles($tmpdir, ilCopyDefinition $definition)
Copy files.
+ Here is the call graph for this function:

Field Documentation

◆ $logger

ilCopyFilesToTempDirectoryJob::$logger = null
private

Definition at line 23 of file class.ilCopyFilesToTempDirectoryJob.php.

◆ $target_directory

ilCopyFilesToTempDirectoryJob::$target_directory
protected

Definition at line 27 of file class.ilCopyFilesToTempDirectoryJob.php.

Referenced by createTargetDirectory().


The documentation for this class was generated from the following file: