Skip to content

Commit

Permalink
Merge pull request #101 from esmero/ISSUE-100
Browse files Browse the repository at this point in the history
ISSUE-100 and ISSUE-99: Fixes PHP8 issues (general)
  • Loading branch information
DiegoPino authored Jun 7, 2022
2 parents a08822f + 6c7a1a2 commit 26d4ef5
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/AmiUtilityService.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ public function file_get($uri, File $zip_file = NULL) {
elseif ($zip_file) {
// Try with the ZIP file in case there is a ZIP and local failed
// Use the Zip file uuid to prefix the destination.
// @TODO file_build_uri is deprecated replace before Drupal 10.0.0
$localfile = file_build_uri(
$this->fileSystem->basename($ami_temp_folder . $zip_file->uuid() . '/' . urldecode($parsed_url['path']))
);
Expand Down
12 changes: 12 additions & 0 deletions src/Controller/AmiRowAutocompleteHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,18 @@ public static function ajaxPreviewAmiSet($form, FormStateInterface $form_state)
'mode' => 'application/json',
],
];
$output['json']['dataOriginal'] = [
'#type' => 'codemirror',
'#title' => t('Original JSON of this ADO <b>{{ dataOriginal.keyname.lod_endpoint_type }}</b> :'),
'#rows' => 60,
'#value' => json_encode($context['dataOriginal'], JSON_PRETTY_PRINT),
'#codemirror' => [
'lineNumbers' => FALSE,
'toolbar' => FALSE,
'readOnly' => TRUE,
'mode' => 'application/json',
],
];

// Try to Ensure we're using the twig from user's input instead of the entity's
// default.
Expand Down
11 changes: 11 additions & 0 deletions src/Form/amiSetEntityProcessForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StreamWrapper\StreamWrapperInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;

Expand Down Expand Up @@ -279,12 +280,22 @@ public function buildForm(array $form, FormStateInterface $form_state) {
];
}

/* Give users a view of Free space in temporary */
$bytes = disk_free_space(\Drupal::service('file_system')->getTempDirectory());
$si_prefix = array( 'B', 'KB', 'MB', 'GB', 'TB', 'EB', 'ZB', 'YB' );
$base = 1024;
$class = min((int)log($bytes , $base) , count($si_prefix) - 1);

$form['status'] = [
'#tree' => TRUE,
'#type' => 'fieldset',
'#title' => $this->t('Desired ADOs statuses after this <em><b>@op</b></em> operation process.',
['@op' => $op]
),
'#description' => $this->t('You have @free remaining free space on your Drupal temporary filesystem. Please be aware of that before running a batch with large files', [
'@free' => sprintf('%1.2f' , $bytes / pow($base,$class)) . ' ' . $si_prefix[$class],
]
),
];
$access = TRUE;
foreach($bundles as $propertypath) {
Expand Down
8 changes: 8 additions & 0 deletions src/Plugin/Action/AmiStrawberryfieldCSVexport.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,13 @@ protected function sendToFile($output) {
if ($file_id && $this->configuration['create_ami_set']) {
$amisetdata = new \stdClass();
$amisetdata->plugin = 'spreadsheet';
/* start definitions to make php8 happy */
$amisetdata->pluginconfig = new \stdClass();
$amisetdata->adomapping = new \stdClass();
$amisetdata->mapping = new \stdClass();
$amisetdata->adomapping->base = new \stdClass();
$amisetdata->adomapping->uuid = new \stdClass();
$amisetdata->mapping->custommapping_settings = new \stdClass();
$amisetdata->pluginconfig->op = 'update';
$amisetdata->pluginconfig->file = [$file_id];
$amisetdata->adomapping->base->label = "label";
Expand All @@ -374,6 +381,7 @@ protected function sendToFile($output) {
$amisetdata->mapping->globalmapping = "custom";
// Set by ::execute()
foreach ($this->context['sandbox']['type_bundle'] as $type => $bundle_field) {
$amisetdata->mapping->custommapping_settings->{$type} = new \stdClass();
$amisetdata->mapping->custommapping_settings->{$type}->files = $this->context['sandbox']['file_columns'] ?? [];
$amisetdata->mapping->custommapping_settings->{$type}->bundle = $bundle_field;
$amisetdata->mapping->custommapping_settings->{$type}->metadata = "direct";
Expand Down
15 changes: 11 additions & 4 deletions src/Plugin/QueueWorker/IngestADOQueueWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public function processItem($data) {
if (!empty($processed_file_data['as_data']) && !empty($processed_file_data['file_id'])) {
// Last sanity check and make file temporary
// TODO: remove on SBF 1.0.0 since we are going to also persist files where the source is
// of streamwrapper temporary://
// of streamwrapper temporary:// type
/* @var \Drupal\file\FileInterface $file */
$file = $this->entityTypeManager->getStorage('file')->load($processed_file_data['file_id']);
if ($file) {
Expand Down Expand Up @@ -563,8 +563,14 @@ private function persistEntity(\stdClass $data, array $processed_metadata) {
$status = $data->info['status'][$bundle] ?? 0;
// default Sortfile which will respect the ingest order. If there was already one set, preserve.
$sort_files = isset($processed_metadata['ap:tasks']) && isset($processed_metadata['ap:tasks']['ap:sortfiles']) ? $processed_metadata['ap:tasks']['ap:sortfiles'] : 'index';
if (is_array($processed_metadata['ap:tasks'])) {
$processed_metadata['ap:tasks']['ap:sortfiles'] = $sort_files;
}
else {
$processed_metadata['ap:tasks'] = [];
$processed_metadata['ap:tasks']['ap:sortfiles'] = $sort_files;
}

$processed_metadata['ap:tasks']['ap:sortfiles'] = $sort_files;
// JSON_ENCODE AGAIN!
$jsonstring = json_encode($processed_metadata, JSON_PRETTY_PRINT, 50);

Expand All @@ -577,7 +583,6 @@ private function persistEntity(\stdClass $data, array $processed_metadata) {
$field_name => $jsonstring
];


/** @var \Drupal\Core\Entity\EntityPublishedInterface $node */
try {
if ($op ==='create') {
Expand Down Expand Up @@ -624,7 +629,9 @@ private function persistEntity(\stdClass $data, array $processed_metadata) {
// Means new processing is adding these and they are already in the mapping. Is safe Files enabled?
if ($data->info['ops_safefiles']) {
// We take the old file ids and merge the new ones. Nothing gets lost ever.
$processed_metadata[$filekey] = array_merge($original_value[$filekey] ?? [], $processed_metadata[$filekey] ?? []);
// If there were no new ones, or new ones were URLs and failed processing
// The $processed_metadata[$filekey] might be a string or empty!
$processed_metadata[$filekey] = array_merge((array) $original_value[$filekey] ?? [], is_array($processed_metadata[$filekey]) ? $processed_metadata[$filekey] : []);
}
}
}
Expand Down

0 comments on commit 26d4ef5

Please sign in to comment.