diff --git a/composer.json b/composer.json index 4d3dff7c4..55c8f187b 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,6 @@ "drupal/recurring_events": "*", "ymcatwincities/daxko_sso": "*", "drupal/jsonapi_image_styles": "^1.0@beta", - "drupal/file_entity": "*", "drupal/csv_serialization": "^1", "ext-json": "*", "ext-zlib": "*" diff --git a/modules/openy_gc_log/config/install/file_entity.type.archive.yml b/modules/openy_gc_log/config/install/file_entity.type.archive.yml deleted file mode 100644 index fe001f9be..000000000 --- a/modules/openy_gc_log/config/install/file_entity.type.archive.yml +++ /dev/null @@ -1,29 +0,0 @@ -langcode: en -status: true -dependencies: { } -id: archive -label: Archive -description: 'Archive type of files. Here you can find/edit/delete/add the stored data from different parts of the system.' -mimetypes: - - "application/zip\r" - - "application/rar\r" - - "application/x-cpio\r" - - "application/x-shar\r" - - "application/x-tar\r" - - "application/x-bzip2\r" - - "application/gzip\r" - - "application/x-lzip\r" - - "application/x-lzma\r" - - "application/x-lzop\r" - - "application/x-snappy-framed\r" - - "application/x-xz\r" - - "application/x-compress\r" - - "application/x-7z-compressed\r" - - "application/x-ace-compressed\r" - - "application/x-astrotite-afa\r" - - "application/vnd.ms-cab-compressed\r" - - "application/x-apple-diskimage\r" - - "application/x-lzh\r" - - "application/x-rar-compressed\r" - - "application/x-stuffit\r" - - "application/x-gtar" diff --git a/modules/openy_gc_log/config/install/views.view.virtual_y_logs.yml b/modules/openy_gc_log/config/install/views.view.virtual_y_logs.yml index bdbe55bfe..7532a026f 100644 --- a/modules/openy_gc_log/config/install/views.view.virtual_y_logs.yml +++ b/modules/openy_gc_log/config/install/views.view.virtual_y_logs.yml @@ -3,8 +3,6 @@ status: true dependencies: module: - openy_gc_log -_core: - default_config_hash: H-mchKrbgMyLCwLeWlXsdWI-s3cOq_tN6HXhYV0FEyM id: virtual_y_logs label: 'Virtual Y Logs' module: views @@ -334,7 +332,7 @@ display: relationship: none group_type: group admin_label: '' - label: User Action + label: 'User Action' exclude: false alter: alter_text: false @@ -695,7 +693,7 @@ display: operator: contains value: node 2: - title: Videoconference/Online Translation + title: 'Videoconference/Online Translation' operator: contains value: series 3: @@ -766,51 +764,6 @@ display: entity_type: log_entity entity_field: entity_bundle plugin_id: string - entity_id: - id: entity_id - table: log_entity - field: entity_id - relationship: none - group_type: group - admin_label: '' - operator: contains - value: '' - group: 1 - exposed: true - expose: - operator_id: entity_id_op - label: 'Entity Id' - description: '' - use_operator: false - operator: entity_id_op - operator_limit_selection: false - operator_list: { } - identifier: entity_id - required: false - remember: false - multiple: false - remember_roles: - authenticated: authenticated - anonymous: '0' - administrator: '0' - contributor: '0' - editor: '0' - placeholder: '' - is_grouped: false - group_info: - label: '' - description: '' - identifier: '' - optional: true - widget: select - multiple: false - remember: false - default_group: All - default_group_multiple: { } - group_items: { } - entity_type: log_entity - entity_field: entity_id - plugin_id: string sorts: { } title: 'Virtual Y Logs' header: { } diff --git a/modules/openy_gc_log/openy_gc_log.info.yml b/modules/openy_gc_log/openy_gc_log.info.yml index 8a09896ee..834d9b0bf 100644 --- a/modules/openy_gc_log/openy_gc_log.info.yml +++ b/modules/openy_gc_log/openy_gc_log.info.yml @@ -8,4 +8,3 @@ core_version_requirement: ^8 || ^9 dependencies: - drupal:views - drupal:csv_serialization - - drupal:file_entity diff --git a/modules/openy_gc_log/openy_gc_log.links.menu.yml b/modules/openy_gc_log/openy_gc_log.links.menu.yml index f6580beb2..1370fe084 100644 --- a/modules/openy_gc_log/openy_gc_log.links.menu.yml +++ b/modules/openy_gc_log/openy_gc_log.links.menu.yml @@ -6,3 +6,14 @@ openy_gated_content.logs: description: 'List Log entity entities' parent: openy_gated_content.openy weight: 100 + +openy_gated_content.logs_archives: + title: 'Logs Archives' + route_name: view.files.page_1 + description: 'List Log entity entities' + parent: openy_gated_content.openy + weight: 101 + options: + query: + filename: virtual-y + filemime: application/x-gzip diff --git a/modules/openy_gc_log/openy_gc_log.permissions.yml b/modules/openy_gc_log/openy_gc_log.permissions.yml index 791febda7..9156c6e04 100644 --- a/modules/openy_gc_log/openy_gc_log.permissions.yml +++ b/modules/openy_gc_log/openy_gc_log.permissions.yml @@ -12,8 +12,5 @@ delete log entity entities: edit log entity entities: title: 'Edit Log entity entities' -view published log entity entities: - title: 'View published Log entity entities' - -view unpublished log entity entities: - title: 'View unpublished Log entity entities' +view log entity entities: + title: 'View Log entity entities' diff --git a/modules/openy_gc_log/openy_gc_log.services.yml b/modules/openy_gc_log/openy_gc_log.services.yml index 9666c4e65..11adaad70 100644 --- a/modules/openy_gc_log/openy_gc_log.services.yml +++ b/modules/openy_gc_log/openy_gc_log.services.yml @@ -1,7 +1,7 @@ services: openy_gc_log.log_archiver: class: Drupal\openy_gc_log\LogArchiver - arguments: ['@entity_type.manager', '@logger.channel.openy_gc_log', '@config.factory'] + arguments: ['@entity_type.manager', '@logger.channel.openy_gc_log', '@config.factory', '@file_system', '@settings'] logger.channel.openy_gc_log: parent: logger.channel_base diff --git a/modules/openy_gc_log/src/LogArchiver.php b/modules/openy_gc_log/src/LogArchiver.php index 003c5b4e3..4cc932acb 100644 --- a/modules/openy_gc_log/src/LogArchiver.php +++ b/modules/openy_gc_log/src/LogArchiver.php @@ -4,9 +4,11 @@ use Drupal\Core\Config\ConfigFactory; use Drupal\Core\Entity\EntityTypeManager; +use Drupal\Core\File\FileSystem; use Drupal\Core\Logger\LoggerChannel; +use Drupal\Core\Site\Settings; use Drupal\csv_serialization\Encoder\CsvEncoder; -use Drupal\file_entity\Entity\FileEntity; +use Drupal\file\Entity\File; /** * LogArchiver service. @@ -15,6 +17,8 @@ class LogArchiver { const WORKER_CHUNK_SIZE = 600; + const BASE_ARCHIVE_PATH = 'vy_logs'; + /** * Log Ids. * @@ -65,6 +69,20 @@ class LogArchiver { */ private $config; + /** + * FileSystem. + * + * @var \Drupal\Core\File\FileSystem + */ + protected $fileSystem; + + /** + * Site Settings. + * + * @var \Drupal\Core\Site\Settings + */ + protected $settings; + /** * LogArchiver constructor. * @@ -74,15 +92,23 @@ class LogArchiver { * LoggerChannel. * @param \Drupal\Core\Config\ConfigFactory $configFactory * ConfigFactory. + * @param \Drupal\Core\File\FileSystem $fileSystem + * FileSystem. + * @param \Drupal\Core\Site\Settings $settings + * Settings. */ public function __construct( EntityTypeManager $entityTypeManager, LoggerChannel $logger, - ConfigFactory $configFactory + ConfigFactory $configFactory, + FileSystem $fileSystem, + Settings $settings ) { $this->entityTypeManager = $entityTypeManager; $this->logger = $logger; $this->config = $configFactory; + $this->fileSystem = $fileSystem; + $this->settings = $settings; } /** @@ -143,6 +169,33 @@ protected function loadLogEntities() { return $this; } + /** + * Check is private dir enabled. + */ + protected function isPrivateDirEnabled() { + return $this->settings::get('file_private_path', FALSE); + } + + /** + * Prepare directory for logs. + */ + protected function prepareYearDirectory($dir) { + if ($this->isPrivateDirEnabled()) { + $dir = 'private://' . self::BASE_ARCHIVE_PATH . DIRECTORY_SEPARATOR . $dir; + } + else { + $salt = $this->settings::getHashSalt(); + $dir = 'public://' . self::BASE_ARCHIVE_PATH . DIRECTORY_SEPARATOR . $salt . + DIRECTORY_SEPARATOR . $dir; + } + if (!$this->fileSystem->prepareDirectory($dir, + FileSystem::CREATE_DIRECTORY)) { + throw new \RuntimeException(sprintf('Can not create directory "%s"', $dir)); + } + + return $dir; + } + /** * Make filename. */ @@ -180,9 +233,16 @@ protected function prepareLogsForExport() { * Create new file entity. */ protected function createNewFileEntity($fileName) { - $file = FileEntity::create(['bundle' => 'archive', 'type' => 'archive']); + $fileYear = date('Y', (int) $this->preparedLogs[$fileName][0]['created']); + $yearDir = $this->prepareYearDirectory($fileYear); + $file = File::create(); $file->setFilename($fileName); - $file->setFileUri("public://{$fileName}"); + if ($this->isPrivateDirEnabled()) { + $file->setFileUri($yearDir . DIRECTORY_SEPARATOR . $fileName); + } + else { + $file->setFileUri($yearDir . DIRECTORY_SEPARATOR . md5(mt_rand()) . '-' . $fileName); + } $file->setMimeType('application/x-gzip'); $file->setPermanent(); return $file; @@ -198,7 +258,8 @@ protected function loadFileEntities() { ->condition('filename', array_keys($this->preparedLogs), 'in') ->execute(); - $file_entities = FileEntity::loadMultiple($file_ids); + $file_entities = $this->entityTypeManager + ->getStorage('file')->loadMultiple($file_ids); $this->fileEntities = []; foreach ($file_entities as $file_entity) { diff --git a/modules/openy_gc_log/src/LogEntityAccessControlHandler.php b/modules/openy_gc_log/src/LogEntityAccessControlHandler.php index 56a6de60c..ea1371c89 100644 --- a/modules/openy_gc_log/src/LogEntityAccessControlHandler.php +++ b/modules/openy_gc_log/src/LogEntityAccessControlHandler.php @@ -24,11 +24,7 @@ protected function checkAccess(EntityInterface $entity, $operation, AccountInter case 'view': - if (!$entity->isPublished()) { - return AccessResult::allowedIfHasPermission($account, 'view unpublished log entity entities'); - } - - return AccessResult::allowedIfHasPermission($account, 'view published log entity entities'); + return AccessResult::allowedIfHasPermission($account, 'view log entity entities'); case 'update':