public static function ExternalPackageController::cleanDirectoryFiles in Opigno module 8
Same name and namespace in other branches
- 3.x src/Controller/ExternalPackageController.php \Drupal\opigno_module\Controller\ExternalPackageController::cleanDirectoryFiles()
Cleans up ppt conversion directory.
Parameters
string $ppt_dir_real_path: Real path to Drupal public files.
array $files: Uploaded file objects.
1 call to ExternalPackageController::cleanDirectoryFiles()
- ExternalPackageController::ajaxFormExternalPackageFormSubmit in src/
Controller/ ExternalPackageController.php - Custom submit handler added via the function opigno_module_form_alter().
File
- src/
Controller/ ExternalPackageController.php, line 529
Class
- ExternalPackageController
- Class ActivitiesBrowserController.
Namespace
Drupal\opigno_module\ControllerCode
public static function cleanDirectoryFiles($ppt_dir_real_path, array $files = NULL) {
// Latest H5P lib core deletes uploaded files but not from database.
// Delete uploaded files from database.
if ($files) {
foreach ($files as $file) {
if ($f = File::load($file
->id())) {
try {
$f
->delete();
} catch (\Exception $e) {
\Drupal::logger('opigno_module')
->error($e
->getMessage());
\Drupal::messenger()
->addMessage($e
->getMessage(), 'error');
}
}
}
}
// Latest H5P lib core deletes H5P uploaded content directory.
// Delete files in a directory if not deleted.
/** @var \Drupal\Core\File\FileSystemInterface $file_system */
$file_system = \Drupal::service('file_system');
if (is_dir($ppt_dir_real_path)) {
$files = $file_system
->scanDirectory($ppt_dir_real_path, '/.*\\.*$/');
if ($files) {
foreach ($files as $file) {
try {
if (file_exists($file->uri)) {
\Drupal::service('file_system')
->delete($file->uri);
}
} catch (\Exception $e) {
\Drupal::logger('opigno_module')
->error($e
->getMessage());
\Drupal::messenger()
->addMessage($e
->getMessage(), 'error');
}
}
}
}
}