Skip to content
This repository has been archived by the owner on Jul 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #16 from fivejars/master
Browse files Browse the repository at this point in the history
Hotfix: removed file_entity module from dependencies
  • Loading branch information
anpolimus authored Aug 13, 2020
2 parents 478b40e + 9d70b3d commit 88e1937
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 96 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*"
Expand Down
29 changes: 0 additions & 29 deletions modules/openy_gc_log/config/install/file_entity.type.archive.yml

This file was deleted.

51 changes: 2 additions & 49 deletions modules/openy_gc_log/config/install/views.view.virtual_y_logs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -334,7 +332,7 @@ display:
relationship: none
group_type: group
admin_label: ''
label: User Action
label: 'User Action'
exclude: false
alter:
alter_text: false
Expand Down Expand Up @@ -695,7 +693,7 @@ display:
operator: contains
value: node
2:
title: Videoconference/Online Translation
title: 'Videoconference/Online Translation'
operator: contains
value: series
3:
Expand Down Expand Up @@ -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: { }
Expand Down
1 change: 0 additions & 1 deletion modules/openy_gc_log/openy_gc_log.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ core_version_requirement: ^8 || ^9
dependencies:
- drupal:views
- drupal:csv_serialization
- drupal:file_entity
11 changes: 11 additions & 0 deletions modules/openy_gc_log/openy_gc_log.links.menu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 2 additions & 5 deletions modules/openy_gc_log/openy_gc_log.permissions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
2 changes: 1 addition & 1 deletion modules/openy_gc_log/openy_gc_log.services.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
71 changes: 66 additions & 5 deletions modules/openy_gc_log/src/LogArchiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -15,6 +17,8 @@ class LogArchiver {

const WORKER_CHUNK_SIZE = 600;

const BASE_ARCHIVE_PATH = 'vy_logs';

/**
* Log Ids.
*
Expand Down Expand Up @@ -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.
*
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
6 changes: 1 addition & 5 deletions modules/openy_gc_log/src/LogEntityAccessControlHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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':

Expand Down

0 comments on commit 88e1937

Please sign in to comment.