ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilCalendarCopyFilesToTempDirectoryJob Class Reference

Description of class class. More...

+ Inheritance diagram for ilCalendarCopyFilesToTempDirectoryJob:
+ Collaboration diagram for ilCalendarCopyFilesToTempDirectoryJob:

Public Member Functions

 __construct ()
 Constructor. More...
 
 getInputTypes ()
 
 getOutputType ()
 
 isStateless ()
 
 run (array $input, Observer $observer)
 
 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, ilCalendarRessourceStorageCopyDefinition $definition)
 Copy files. More...
 
 copyWithRId (string $tmpdir, array $copy_task)
 
 copyWithAbsolutePath (string $tmpdir, array $copy_task)
 
- Protected Member Functions inherited from ILIAS\BackgroundTasks\Implementation\Tasks\AbstractTask
 checkTypes ($values)
 
 extractType ($value)
 

Protected Attributes

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

Private Attributes

ilLogger $logger
 
ILIAS ResourceStorage Services $irss
 

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 36 of file class.ilCalendarCopyFilesToTempDirectoryJob.php.

Constructor & Destructor Documentation

◆ __construct()

ilCalendarCopyFilesToTempDirectoryJob::__construct ( )

Constructor.

Definition at line 46 of file class.ilCalendarCopyFilesToTempDirectoryJob.php.

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

47  {
48  global $DIC;
49 
50  $this->irss = $DIC->resourceStorage();
51  $this->logger = $DIC->logger()->cal();
52  }
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ copyFiles()

ilCalendarCopyFilesToTempDirectoryJob::copyFiles ( string  $tmpdir,
ilCalendarRessourceStorageCopyDefinition  $definition 
)
protected

Copy files.

Definition at line 136 of file class.ilCalendarCopyFilesToTempDirectoryJob.php.

References ilCalendarRessourceStorageCopyDefinition\COPY_RESSOURCE_ID, copyWithAbsolutePath(), copyWithRId(), and ilCalendarRessourceStorageCopyDefinition\getCopyDefinitions().

Referenced by run().

136  : void
137  {
138  foreach ($definition->getCopyDefinitions() as $copy_task) {
140  $this->copyWithRId($tmpdir, $copy_task);
141  } else {
142  $this->copyWithAbsolutePath($tmpdir, $copy_task);
143  }
144  }
145  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ copyWithAbsolutePath()

ilCalendarCopyFilesToTempDirectoryJob::copyWithAbsolutePath ( string  $tmpdir,
array  $copy_task 
)
protected

Definition at line 168 of file class.ilCalendarCopyFilesToTempDirectoryJob.php.

References ilCalendarRessourceStorageCopyDefinition\COPY_ABSOLUTE_PATH, ilCalendarRessourceStorageCopyDefinition\COPY_TARGET_DIR, ILIAS\Repository\logger(), and ilFileUtils\makeDirParents().

Referenced by copyFiles().

169  {
172 
173  if (!file_exists($absolute_path)) {
174  $this->logger->notice('Cannot find file: ' . $absolute_path);
175  return;
176  }
177 
178  $this->logger->debug('Creating directory: ' . $tmpdir . '/' . dirname($target_dir));
179  ilFileUtils::makeDirParents($tmpdir . '/' . dirname($target_dir));
180  $this->logger->debug('Copying from: ' . $absolute_path . ' to ' . $tmpdir . '/' . $target_dir);
181 
182  copy($absolute_path, $tmpdir . '/' . $target_dir);
183  }
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:

◆ copyWithRId()

ilCalendarCopyFilesToTempDirectoryJob::copyWithRId ( string  $tmpdir,
array  $copy_task 
)
protected

Definition at line 147 of file class.ilCalendarCopyFilesToTempDirectoryJob.php.

References ilCalendarRessourceStorageCopyDefinition\COPY_RESSOURCE_ID, ilCalendarRessourceStorageCopyDefinition\COPY_TARGET_DIR, ILIAS\Repository\logger(), and ilFileUtils\makeDirParents().

Referenced by copyFiles().

148  {
151  $resource_identification = $this->irss->manage()->find($rid);
152 
153  if(is_null($resource_identification)) {
154  $this->logger->notice('Cannot ressource identification of rid: ' . $rid);
155  return;
156  }
157 
158  $this->logger->debug('Creating directory: ' . $tmpdir . '/' . dirname($target_dir));
159  ilFileUtils::makeDirParents($tmpdir . '/' . dirname($target_dir));
160  $this->logger->debug('Copying ressource with id: ' . $rid . ' to ' . $tmpdir . '/' . $target_dir);
161 
162  file_put_contents(
164  $this->irss->consume()->stream($resource_identification)->getStream()
165  );
166  }
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()

ilCalendarCopyFilesToTempDirectoryJob::createTargetDirectory ( string  $a_tmpdir)
protected

Definition at line 125 of file class.ilCalendarCopyFilesToTempDirectoryJob.php.

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

Referenced by run().

125  : string
126  {
127  $final_dir = $a_tmpdir . "/" . $this->target_directory;
128  ilFileUtils::makeDirParents($final_dir);
129  $this->logger->info('New final directory: ' . $final_dir);
130  return $final_dir;
131  }
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()

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

Definition at line 117 of file class.ilCalendarCopyFilesToTempDirectoryJob.php.

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

Referenced by run().

117  : string
118  {
119  $tmpdir = ilFileUtils::ilTempnam();
121  $this->logger->info('New temp directory: ' . $tmpdir);
122  return $tmpdir;
123  }
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()

ilCalendarCopyFilesToTempDirectoryJob::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 188 of file class.ilCalendarCopyFilesToTempDirectoryJob.php.

188  : int
189  {
190  return 30;
191  }

◆ getInputTypes()

ilCalendarCopyFilesToTempDirectoryJob::getInputTypes ( )

Implements ILIAS\BackgroundTasks\Task.

Definition at line 57 of file class.ilCalendarCopyFilesToTempDirectoryJob.php.

57  : array
58  {
59  return
60  [
61  new SingleType(ilCalendarRessourceStorageCopyDefinition::class)
62  ];
63  }

◆ getOutputType()

ilCalendarCopyFilesToTempDirectoryJob::getOutputType ( )

Todo:
output should be file type

Implements ILIAS\BackgroundTasks\Task.

Definition at line 69 of file class.ilCalendarCopyFilesToTempDirectoryJob.php.

69  : Type
70  {
71  return new SingleType(StringValue::class);
72  }

◆ isStateless()

ilCalendarCopyFilesToTempDirectoryJob::isStateless ( )

Implements ILIAS\BackgroundTasks\Task\Job.

Definition at line 77 of file class.ilCalendarCopyFilesToTempDirectoryJob.php.

77  : bool
78  {
79  return true;
80  }

◆ run()

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

Implements ILIAS\BackgroundTasks\Task\Job.

Definition at line 85 of file class.ilCalendarCopyFilesToTempDirectoryJob.php.

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

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

Field Documentation

◆ $irss

ILIAS ResourceStorage Services ilCalendarCopyFilesToTempDirectoryJob::$irss
private

◆ $logger

ilLogger ilCalendarCopyFilesToTempDirectoryJob::$logger
private

◆ $target_directory

string ilCalendarCopyFilesToTempDirectoryJob::$target_directory
protected

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