ILIAS  release_7 Revision v7.30-3-g800a261c036
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 ()
 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, ilWorkspaceCopyDefinition $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
killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

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

Constructor & Destructor Documentation

◆ __construct()

ilCopyWorkspaceFilesToTempDirectoryJob::__construct ( )

Constructor.

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

References ilLoggerFactory\getLogger().

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

Member Function Documentation

◆ copyFiles()

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

Copy files.

Parameters
string$tmpdir
ilWorkspaceCopyDefinition$definition

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

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

Referenced by run().

123  {
124  foreach ($definition->getCopyDefinitions() as $copy_task) {
125  if (!file_exists($copy_task[ilWorkspaceCopyDefinition::COPY_SOURCE_DIR])) {
126  // 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
127  $is_empty_folder = preg_match_all("/\/$/", $copy_task[ilWorkspaceCopyDefinition::COPY_TARGET_DIR]);
128  if ($is_empty_folder) {
129  mkdir($tmpdir . '/' . $copy_task[ilWorkspaceCopyDefinition::COPY_TARGET_DIR]);
130  $this->logger->notice('Empty folder has been created: ' . $tmpdir . '/' . $copy_task[ilWorkspaceCopyDefinition::COPY_SOURCE_DIR]);
131  } else {
132  $this->logger->notice('Cannot find file: ' . $copy_task[ilWorkspaceCopyDefinition::COPY_SOURCE_DIR]);
133  }
134  continue;
135  }
136  $this->logger->debug('Creating directory: ' . $tmpdir . '/' . dirname($copy_task[ilWorkspaceCopyDefinition::COPY_TARGET_DIR]));
138  $tmpdir . '/' . dirname($copy_task[ilWorkspaceCopyDefinition::COPY_TARGET_DIR])
139  );
140 
141  $this->logger->debug(
142  'Copying from: ' .
143  $copy_task[ilWorkspaceCopyDefinition::COPY_SOURCE_DIR] .
144  ' to ' .
145  $tmpdir . '/' . $copy_task[ilWorkspaceCopyDefinition::COPY_TARGET_DIR]
146  );
147 
148  copy(
149  $copy_task[ilWorkspaceCopyDefinition::COPY_SOURCE_DIR],
150  $tmpdir . '/' . $copy_task[ilWorkspaceCopyDefinition::COPY_TARGET_DIR]
151  );
152  }
153  return;
154  }
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:

◆ createTargetDirectory()

ilCopyWorkspaceFilesToTempDirectoryJob::createTargetDirectory (   $a_tmpdir)
protected

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

References $target_directory, and ilUtil\makeDirParents().

Referenced by run().

109  {
110  $final_dir = $a_tmpdir . "/" . $this->target_directory;
111  ilUtil::makeDirParents($final_dir);
112  $this->logger->info('New final directory: ' . $final_dir);
113  return $final_dir;
114  }
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()

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

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

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

Referenced by run().

101  {
102  $tmpdir = ilUtil::ilTempnam();
103  ilUtil::makeDirParents($tmpdir);
104  $this->logger->info('New temp directory: ' . $tmpdir);
105  return $tmpdir;
106  }
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()

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

160  {
161  return 30;
162  }

◆ getInputTypes()

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

Implements ILIAS\BackgroundTasks\Task.

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

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

◆ getOutputType()

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

Implements ILIAS\BackgroundTasks\Task.

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

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

◆ 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 59 of file class.ilCopyWorkspaceFilesToTempDirectoryJob.php.

60  {
61  return true;
62  }

◆ run()

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

run the job

Parameters
Value$input
Observer$observer

Implements ILIAS\BackgroundTasks\Task\Job.

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

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

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

Field Documentation

◆ $logger

ilCopyWorkspaceFilesToTempDirectoryJob::$logger = null
private

◆ $target_directory

ilCopyWorkspaceFilesToTempDirectoryJob::$target_directory
protected

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