ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator 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
array 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 (string $a_tmpdir)
 
 copyFiles (string $tmpdir, ilCopyDefinition $definition)
 Copy files. More...
 
- Protected Member Functions inherited from ILIAS\BackgroundTasks\Implementation\Tasks\AbstractTask
 checkTypes (array $values)
 
 extractType ($value)
 

Protected Attributes

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

Private Attributes

ilLogger $logger
 

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 32 of file class.ilCopyFilesToTempDirectoryJob.php.

Constructor & Destructor Documentation

◆ __construct()

ilCopyFilesToTempDirectoryJob::__construct ( )

Constructor.

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

References $DIC, and ILIAS\Repository\logger().

42  {
43  global $DIC;
44  $this->logger = $DIC->logger()->cal();
45  }
global $DIC
Definition: shib_login.php:22
+ Here is the call graph for this function:

Member Function Documentation

◆ copyFiles()

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

Copy files.

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

References ilCopyDefinition\COPY_SOURCE_DIR, ilCopyDefinition\COPY_TARGET_DIR, ilCopyDefinition\getCopyDefinitions(), ILIAS\Repository\logger(), and ilFileUtils\makeDirParents().

Referenced by run().

135  : void
136  {
137  foreach ($definition->getCopyDefinitions() as $copy_task) {
138  $source_dir_or_file = $copy_task[ilCopyDefinition::COPY_SOURCE_DIR];
139  $target_dir_or_file = $copy_task[ilCopyDefinition::COPY_TARGET_DIR];
140  $absolute_path_of_target_dir_or_file = $tmpdir . '/' . $target_dir_or_file;
141  $absolute_directory_of_target_dir_or_file = $tmpdir . '/' . dirname($target_dir_or_file);
142 
143  $this->logger->debug('Creating directory: ' . $tmpdir . '/' . dirname($target_dir_or_file));
144 
146  $absolute_directory_of_target_dir_or_file
147  );
148 
149  if (!file_exists($source_dir_or_file)) {
150  // 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
151  $is_empty_folder = preg_match_all("/\/$/", $target_dir_or_file);
152  if ($is_empty_folder && !file_exists($absolute_path_of_target_dir_or_file)) {
153  mkdir($absolute_path_of_target_dir_or_file);
154  $this->logger->notice('Empty folder has been created: ' . $tmpdir . '/' . $source_dir_or_file);
155  } else {
156  $this->logger->notice('Cannot find file: ' . $source_dir_or_file);
157  }
158  continue;
159  }
160 
161  $this->logger->debug(
162  'Copying from: ' .
163  $source_dir_or_file .
164  ' to ' .
165  $absolute_path_of_target_dir_or_file
166  );
167  if (
168  !is_dir($source_dir_or_file) && is_file($source_dir_or_file)
169  && !is_dir($absolute_path_of_target_dir_or_file)
170  ) {
171  copy(
172  $source_dir_or_file,
173  $absolute_path_of_target_dir_or_file
174  );
175  }
176  }
177  }
getCopyDefinitions()
Get copy definitions.
static makeDirParents(string $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:

◆ createTargetDirectory()

ilCopyFilesToTempDirectoryJob::createTargetDirectory ( string  $a_tmpdir)
protected

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

References $target_directory, ILIAS\Repository\logger(), and ilFileUtils\makeDirParents().

Referenced by run().

122  : string
123  {
124  $final_dir = $a_tmpdir . "/" . $this->target_directory;
125  ilFileUtils::makeDirParents($final_dir);
126  $this->logger->info('New final directory: ' . $final_dir);
127 
128  return $final_dir;
129  }
static makeDirParents(string $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 112 of file class.ilCopyFilesToTempDirectoryJob.php.

References ilFileUtils\ilTempnam(), ILIAS\Repository\logger(), and ilFileUtils\makeDirParents().

Referenced by run().

112  : string
113  {
114  $tmpdir = ilFileUtils::ilTempnam();
116  $this->logger->info('New temp directory: ' . $tmpdir);
117 
118  return $tmpdir;
119  }
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static ilTempnam(?string $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 183 of file class.ilCopyFilesToTempDirectoryJob.php.

183  : int
184  {
185  return 30;
186  }

◆ getInputTypes()

ilCopyFilesToTempDirectoryJob::getInputTypes ( )
Returns
SingleType[]

Implements ILIAS\BackgroundTasks\Task.

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

51  : array
52  {
53  return
54  [
55  new SingleType(ilCopyDefinition::class),
56  ];
57  }

◆ getOutputType()

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

Implements ILIAS\BackgroundTasks\Task.

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

63  : Type
64  {
65  return new SingleType(StringValue::class);
66  }

◆ 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 69 of file class.ilCopyFilesToTempDirectoryJob.php.

69  : bool
70  {
71  return true;
72  }

◆ run()

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

run the job

Parameters
Value$input

Implements ILIAS\BackgroundTasks\Task\Job.

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

References $out, copyFiles(), createTargetDirectory(), createUniqueTempDirectory(), and ILIAS\Repository\logger().

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

Field Documentation

◆ $logger

ilLogger ilCopyFilesToTempDirectoryJob::$logger
private

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

◆ $target_directory

string ilCopyFilesToTempDirectoryJob::$target_directory = ''
protected

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

Referenced by createTargetDirectory().


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