Skip to content
Snippets Groups Projects
Commit 4a5ebe61 authored by catch's avatar catch
Browse files

Issue #3461817 by catch: Support stream wrappers for tincan activity

parent 7e8180a8
Branches
No related tags found
No related merge requests found
......@@ -11,6 +11,16 @@ use Drupal\Core\Render\Markup;
use Drupal\Core\Url;
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_field_widget_info_alter().
*/
function opigno_tincan_activity_field_widget_info_alter(&$info) {
$info['file_generic']['field_types'][] = 'opigno_tincan_package';
if (\Drupal::moduleHandler()->moduleExists('s3fs_cors')) {
$info['s3fs_cors_file_widget']['field_types'][] = 'opigno_tincan_package';
}
}
/**
* Implements hook_file_delete().
*/
......
......@@ -183,13 +183,21 @@ class TincanService implements TincanServiceInterface {
* If the file is unsupported.
*/
public static function unzipPackage($file) {
$path = \Drupal::service('file_system')->realpath($file->getFileUri());
$path = $file->getFileUri();
// Copy the file to a temporary directory so that it can be extracted if
// the stream wrapper does not support ZipArchive.
$temp_file = 'temporary://tincan-' . $file->id . '.zip';
$file_system = \Drupal::service('file_system');
$path = $file_system->copy($path, $temp_file);
$zip = new \ZipArchive();
$result = $zip->open($path);
$result = $zip->open($file_system->realpath($path));
if ($result === TRUE) {
$extract_dir = self::getExtractPath($file);
$file_system->prepareDirectory($extract_dir);
$zip->extractTo($extract_dir);
$zip->close();
$file_system->delete($temp_file);
}
else {
$error = 'none';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment