ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilCopyWorkspaceFilesToTempDirectoryJob Class Reference

Description of class class. More...

+ Inheritance diagram for ilCopyWorkspaceFilesToTempDirectoryJob:
+ Collaboration diagram for ilCopyWorkspaceFilesToTempDirectoryJob:

Public Member Functions

 __construct ()
 
 getInputTypes ()
 
 getOutputType ()
 
 isStateless ()
 
 run (array $input, Observer $observer)
 
 getExpectedTimeOfTaskInSeconds ()
 
- 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 ()
 Create unique temp directory. More...
 
 createTargetDirectory (string $a_tmpdir)
 
 copyFiles (string $tmpdir, ilWorkspaceCopyDefinition $definition)
 
- 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 = 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
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

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

Constructor & Destructor Documentation

◆ __construct()

ilCopyWorkspaceFilesToTempDirectoryJob::__construct ( )

Definition at line 38 of file class.ilCopyWorkspaceFilesToTempDirectoryJob.php.

References ilLoggerFactory\getLogger(), and ILIAS\Repository\logger().

39  {
40  $this->logger = ilLoggerFactory::getLogger("pwsp");
41  }
static getLogger(string $a_component_id)
Get component logger.
+ Here is the call graph for this function:

Member Function Documentation

◆ copyFiles()

ilCopyWorkspaceFilesToTempDirectoryJob::copyFiles ( string  $tmpdir,
ilWorkspaceCopyDefinition  $definition 
)
protected

Definition at line 107 of file class.ilCopyWorkspaceFilesToTempDirectoryJob.php.

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

Referenced by run().

110  : void {
111  foreach ($definition->getCopyDefinitions() as $copy_task) {
112  if (!file_exists($copy_task[ilWorkspaceCopyDefinition::COPY_SOURCE_DIR])) {
113  // 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
114  $is_empty_folder = preg_match_all("/\/$/", $copy_task[ilWorkspaceCopyDefinition::COPY_TARGET_DIR]);
115  if ($is_empty_folder) {
117  $this->logger->notice('Empty folder has been created: ' . $tmpdir . '/' . $copy_task[ilWorkspaceCopyDefinition::COPY_SOURCE_DIR]);
118  } else {
119  $this->logger->notice('Cannot find file: ' . $copy_task[ilWorkspaceCopyDefinition::COPY_SOURCE_DIR]);
120  }
121  continue;
122  }
123  $this->logger->debug('Creating directory: ' . $tmpdir . '/' . dirname($copy_task[ilWorkspaceCopyDefinition::COPY_TARGET_DIR]));
125  $tmpdir . '/' . dirname($copy_task[ilWorkspaceCopyDefinition::COPY_TARGET_DIR])
126  );
127 
128  $this->logger->debug(
129  'Copying from: ' .
130  $copy_task[ilWorkspaceCopyDefinition::COPY_SOURCE_DIR] .
131  ' to ' .
132  $tmpdir . '/' . $copy_task[ilWorkspaceCopyDefinition::COPY_TARGET_DIR]
133  );
134 
135  copy(
136  $copy_task[ilWorkspaceCopyDefinition::COPY_SOURCE_DIR],
137  $tmpdir . '/' . $copy_task[ilWorkspaceCopyDefinition::COPY_TARGET_DIR]
138  );
139  }
140  }
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()

ilCopyWorkspaceFilesToTempDirectoryJob::createTargetDirectory ( string  $a_tmpdir)
protected

Definition at line 99 of file class.ilCopyWorkspaceFilesToTempDirectoryJob.php.

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

Referenced by run().

99  : string
100  {
101  $final_dir = $a_tmpdir . "/" . $this->target_directory;
102  ilFileUtils::makeDirParents($final_dir);
103  $this->logger->info('New final directory: ' . $final_dir);
104  return $final_dir;
105  }
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()

ilCopyWorkspaceFilesToTempDirectoryJob::createUniqueTempDirectory ( )
protected

Create unique temp directory.

Returns
string absolute path to new temp directory

Definition at line 91 of file class.ilCopyWorkspaceFilesToTempDirectoryJob.php.

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

Referenced by run().

91  : string
92  {
93  $tmpdir = ilFileUtils::ilTempnam();
95  $this->logger->info('New temp directory: ' . $tmpdir);
96  return $tmpdir;
97  }
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()

ilCopyWorkspaceFilesToTempDirectoryJob::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 142 of file class.ilCopyWorkspaceFilesToTempDirectoryJob.php.

142  : int
143  {
144  return 30;
145  }

◆ getInputTypes()

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

Implements ILIAS\BackgroundTasks\Task.

Definition at line 43 of file class.ilCopyWorkspaceFilesToTempDirectoryJob.php.

43  : array
44  {
45  return
46  [
47  new SingleType(ilWorkspaceCopyDefinition::class)
48  ];
49  }

◆ getOutputType()

ilCopyWorkspaceFilesToTempDirectoryJob::getOutputType ( )

Implements ILIAS\BackgroundTasks\Task.

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

51  : Type
52  {
53  return new SingleType(StringValue::class);
54  }

◆ isStateless()

ilCopyWorkspaceFilesToTempDirectoryJob::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 56 of file class.ilCopyWorkspaceFilesToTempDirectoryJob.php.

56  : bool
57  {
58  return true;
59  }

◆ run()

ilCopyWorkspaceFilesToTempDirectoryJob::run ( array  $input,
Observer  $observer 
)
Parameters

Implements ILIAS\BackgroundTasks\Task\Job.

Definition at line 61 of file class.ilCopyWorkspaceFilesToTempDirectoryJob.php.

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

61  : Value
62  {
63  $definition = $input[0];
64 
65  $this->logger->info('Called copy files job');
66 
67  $this->target_directory = $definition->getTempDir();
68 
69  // create temp directory
70  $tmpdir = $this->createUniqueTempDirectory();
71  $targetdir = $this->createTargetDirectory($tmpdir);
72 
73  // copy files from source to temp directory
74  //$this->copyFiles($targetdir, $input[0]);
75  $this->copyFiles($targetdir, $definition);
76 
77  // zip
78 
79  // return zip file name
80  $this->logger->debug('Returning new tempdirectory: ' . $targetdir);
81 
82  $out = new StringValue();
83  $out->setValue($targetdir);
84  return $out;
85  }
copyFiles(string $tmpdir, ilWorkspaceCopyDefinition $definition)
$out
Definition: buildRTE.php:24
+ Here is the call graph for this function:

Field Documentation

◆ $logger

ilLogger ilCopyWorkspaceFilesToTempDirectoryJob::$logger = null
private

◆ $target_directory

string ilCopyWorkspaceFilesToTempDirectoryJob::$target_directory
protected

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