ILIAS  trunk Revision v11.0_alpha-1831-g8615d53dadb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ILIAS\MediaCast\BackgroundTasks\DownloadAllCollectFilesJob Class Reference

Collect files for downloading all media items. More...

+ Inheritance diagram for ILIAS\MediaCast\BackgroundTasks\DownloadAllCollectFilesJob:
+ Collaboration diagram for ILIAS\MediaCast\BackgroundTasks\DownloadAllCollectFilesJob:

Public Member Functions

 __construct ()
 
 getInputTypes ()
 
 getOutputType ()
 
 isStateless ()
 
 getExpectedTimeOfTaskInSeconds ()
 
 run (array $input, Observer $observer)
 
 collectMediaFiles (string $target_dir)
 
- 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

 createDirectory ()
 
- Protected Member Functions inherited from ILIAS\BackgroundTasks\Implementation\Tasks\AbstractTask
 checkTypes (array $values)
 
 extractType ($value)
 

Protected Attributes

int $user_id = 0
 
int $mcst_id = 0
 
int $mcst_ref_id = 0
 
ilLanguage $lng
 
string $target_directory = ""
 
string $temp_dir = ""
 
string $sanitized_title = ""
 
ilObjMediaCast $media_cast
 
- Protected Attributes inherited from ILIAS\BackgroundTasks\Implementation\Tasks\AbstractTask
array $input = []
 
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

Collect files for downloading all media items.

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

Definition at line 32 of file DownloadAllCollectFilesJob.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\MediaCast\BackgroundTasks\DownloadAllCollectFilesJob::__construct ( )

Definition at line 44 of file DownloadAllCollectFilesJob.php.

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

45  {
46  global $DIC;
47  $this->lng = $DIC->language();
48  $this->lng->loadLanguageModule('mcst');
49  $this->logger = $DIC->logger()->mcst();
50 
51  $this->sanitized_title = "images";
52  }
global $DIC
Definition: shib_login.php:22
+ Here is the call graph for this function:

Member Function Documentation

◆ collectMediaFiles()

ILIAS\MediaCast\BackgroundTasks\DownloadAllCollectFilesJob::collectMediaFiles ( string  $target_dir)

Definition at line 110 of file DownloadAllCollectFilesJob.php.

References Vendor\Package\$e.

Referenced by ILIAS\MediaCast\BackgroundTasks\DownloadAllCollectFilesJob\run().

110  : void
111  {
112  $cnt = 0;
113  foreach ($this->media_cast->getSortedItemsArray() as $item) {
114  $mob = new \ilObjMediaObject($item["mob_id"]);
115  $med = $mob->getMediaItem("Standard");
116 
117  $cnt++;
118  $str_cnt = str_pad($cnt, 4, "0", STR_PAD_LEFT);
119 
120  if ($med->getLocationType() === "Reference") {
121  $resource = $med->getLocation();
122  copy($resource, $target_dir . DIRECTORY_SEPARATOR . $str_cnt . basename($resource));
123  } else {
124  try { // this skips broken objects
125  $stream = $med->getLocationStream();
126  file_put_contents(
127  $target_dir . DIRECTORY_SEPARATOR . $str_cnt . $med->getLocation(),
128  $stream->getContents()
129  );
130  } catch (\Exception $e) {
131  }
132  }
133  }
134  }
+ Here is the caller graph for this function:

◆ createDirectory()

ILIAS\MediaCast\BackgroundTasks\DownloadAllCollectFilesJob::createDirectory ( )
protected

Definition at line 97 of file DownloadAllCollectFilesJob.php.

References $path, ILIAS\MediaCast\BackgroundTasks\DownloadAllCollectFilesJob\$sanitized_title, ILIAS\MediaCast\BackgroundTasks\DownloadAllCollectFilesJob\$target_directory, ilFileUtils\ilTempnam(), and ilFileUtils\makeDirParents().

Referenced by ILIAS\MediaCast\BackgroundTasks\DownloadAllCollectFilesJob\run().

97  : string
98  {
99  // temp dir
100  $this->temp_dir = \ilFileUtils::ilTempnam();
101 
102  // target dir
103  $path = $this->temp_dir . DIRECTORY_SEPARATOR;
104  $this->target_directory = $path . $this->sanitized_title;
105  \ilFileUtils::makeDirParents($this->target_directory);
106 
108  }
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
$path
Definition: ltiservices.php:29
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()

ILIAS\MediaCast\BackgroundTasks\DownloadAllCollectFilesJob::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 73 of file DownloadAllCollectFilesJob.php.

73  : int
74  {
75  return 30;
76  }

◆ getInputTypes()

ILIAS\MediaCast\BackgroundTasks\DownloadAllCollectFilesJob::getInputTypes ( )
Returns
Type[] A list of types that are taken as input.

Implements ILIAS\BackgroundTasks\Task.

Definition at line 54 of file DownloadAllCollectFilesJob.php.

54  : array
55  {
56  return
57  [
58  new SingleType(IntegerValue::class),
59  new SingleType(IntegerValue::class)
60  ];
61  }

◆ getOutputType()

ILIAS\MediaCast\BackgroundTasks\DownloadAllCollectFilesJob::getOutputType ( )

Implements ILIAS\BackgroundTasks\Task.

Definition at line 63 of file DownloadAllCollectFilesJob.php.

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

◆ isStateless()

ILIAS\MediaCast\BackgroundTasks\DownloadAllCollectFilesJob::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 68 of file DownloadAllCollectFilesJob.php.

68  : bool
69  {
70  return true;
71  }

◆ run()

ILIAS\MediaCast\BackgroundTasks\DownloadAllCollectFilesJob::run ( array  $input,
Observer  $observer 
)
Parameters
Value[]$input This will be a list of Values hinted by getInputTypes.
Observer$observerNotify the bucket about your progress!
Returns
Value The returned Value must be of the type hinted by getOutputType.

Implements ILIAS\BackgroundTasks\Task\Job.

Definition at line 78 of file DownloadAllCollectFilesJob.php.

References $out, ILIAS\MediaCast\BackgroundTasks\DownloadAllCollectFilesJob\collectMediaFiles(), ILIAS\MediaCast\BackgroundTasks\DownloadAllCollectFilesJob\createDirectory(), ILIAS\BackgroundTasks\Implementation\Values\ScalarValues\ScalarValue\getValue(), and ILIAS\Repository\logger().

78  : StringValue
79  {
80  $this->user_id = $input[0]->getValue();
81  $this->mcst_ref_id = $input[1]->getValue();
82 
83  $this->logger->debug("Get Mediacast " . $this->mcst_ref_id);
84  $this->media_cast = new \ilObjMediaCast($this->mcst_ref_id);
85 
86  $target_dir = $this->createDirectory();
87 
88  $this->logger->debug("Collect in " . $target_dir);
89  $this->collectMediaFiles($target_dir);
90  $this->logger->debug("Finished collecting.");
91 
92  $out = new StringValue();
93  $out->setValue($target_dir);
94  return $out;
95  }
$out
Definition: buildRTE.php:24
+ Here is the call graph for this function:

Field Documentation

◆ $lng

ilLanguage ILIAS\MediaCast\BackgroundTasks\DownloadAllCollectFilesJob::$lng
protected

Definition at line 38 of file DownloadAllCollectFilesJob.php.

◆ $logger

ilLogger ILIAS\MediaCast\BackgroundTasks\DownloadAllCollectFilesJob::$logger = null
private

Definition at line 34 of file DownloadAllCollectFilesJob.php.

◆ $mcst_id

int ILIAS\MediaCast\BackgroundTasks\DownloadAllCollectFilesJob::$mcst_id = 0
protected

Definition at line 36 of file DownloadAllCollectFilesJob.php.

◆ $mcst_ref_id

int ILIAS\MediaCast\BackgroundTasks\DownloadAllCollectFilesJob::$mcst_ref_id = 0
protected

Definition at line 37 of file DownloadAllCollectFilesJob.php.

◆ $media_cast

ilObjMediaCast ILIAS\MediaCast\BackgroundTasks\DownloadAllCollectFilesJob::$media_cast
protected

Definition at line 42 of file DownloadAllCollectFilesJob.php.

◆ $sanitized_title

string ILIAS\MediaCast\BackgroundTasks\DownloadAllCollectFilesJob::$sanitized_title = ""
protected

◆ $target_directory

string ILIAS\MediaCast\BackgroundTasks\DownloadAllCollectFilesJob::$target_directory = ""
protected

◆ $temp_dir

string ILIAS\MediaCast\BackgroundTasks\DownloadAllCollectFilesJob::$temp_dir = ""
protected

Definition at line 40 of file DownloadAllCollectFilesJob.php.

◆ $user_id

int ILIAS\MediaCast\BackgroundTasks\DownloadAllCollectFilesJob::$user_id = 0
protected

Definition at line 35 of file DownloadAllCollectFilesJob.php.


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