From cde4cc4377795cb0482e94b2258947060b882c7b Mon Sep 17 00:00:00 2001 From: Diego Pino Navarro Date: Tue, 7 Jul 2020 11:23:54 -0400 Subject: [PATCH 1/9] Drupal\Component\Plugin\ConfigurablePluginInterface is deprecated --- src/Plugin/StrawberryfieldKeyNameProviderInterface.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Plugin/StrawberryfieldKeyNameProviderInterface.php b/src/Plugin/StrawberryfieldKeyNameProviderInterface.php index 58a68aa..c0761ab 100644 --- a/src/Plugin/StrawberryfieldKeyNameProviderInterface.php +++ b/src/Plugin/StrawberryfieldKeyNameProviderInterface.php @@ -9,7 +9,8 @@ namespace Drupal\strawberryfield\Plugin; use Drupal\Component\Plugin\PluginInspectionInterface; use Drupal\Core\Plugin\PluginWithFormsInterface; -use Drupal\Component\Plugin\ConfigurablePluginInterface; +use Drupal\Component\Plugin\ConfigurableInterface; +use Drupal\Component\Plugin\DependentPluginInterface; /** * Defines and Interface for StrawberryfieldKeyNameProvider Plugins @@ -18,7 +19,7 @@ * * @package Drupal\strawberryfield\Plugin */ -interface StrawberryfieldKeyNameProviderInterface extends PluginInspectionInterface, PluginWithFormsInterface, ConfigurablePluginInterface{ +interface StrawberryfieldKeyNameProviderInterface extends PluginInspectionInterface, PluginWithFormsInterface, ConfigurableInterface, DependentPluginInterface{ /** From ab5bdd76b442d488180be842006196ac2a79ee8e Mon Sep 17 00:00:00 2001 From: Diego Pino Navarro Date: Tue, 7 Jul 2020 11:24:39 -0400 Subject: [PATCH 2/9] Call to deprecated method uriScheme() is deprecated --- src/StrawberryfieldFilePersisterService.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/StrawberryfieldFilePersisterService.php b/src/StrawberryfieldFilePersisterService.php index eeda7b1..7c33eca 100644 --- a/src/StrawberryfieldFilePersisterService.php +++ b/src/StrawberryfieldFilePersisterService.php @@ -228,9 +228,9 @@ public function getDestinationUri( $current_uri, PATHINFO_EXTENSION ); - $file_parts['destination_scheme'] = $this->fileSystem->uriScheme( - $file->getFileUri() - ); + $file_parts['destination_scheme'] = $this->streamWrapperManager + ->getScheme($current_uri); + list($file_parts['destination_filetype'],) = explode( '/', $file->getMimeType() From 3e2638a954af9099880f754a3defa86d93ffb125 Mon Sep 17 00:00:00 2001 From: Diego Pino Navarro Date: Tue, 7 Jul 2020 11:27:49 -0400 Subject: [PATCH 3/9] Call to deprecated function file_default_scheme() is deprecated --- src/Plugin/Field/FieldType/StrawberryFieldFileComputedItem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugin/Field/FieldType/StrawberryFieldFileComputedItem.php b/src/Plugin/Field/FieldType/StrawberryFieldFileComputedItem.php index 3f542a3..7af2ffb 100644 --- a/src/Plugin/Field/FieldType/StrawberryFieldFileComputedItem.php +++ b/src/Plugin/Field/FieldType/StrawberryFieldFileComputedItem.php @@ -93,7 +93,7 @@ public static function defaultStorageSettings() { 'target_type' => 'file', 'display_field' => FALSE, 'display_default' => FALSE, - 'uri_scheme' => file_default_scheme(), + 'uri_scheme' => \Drupal::config('system.file')->get('default_scheme') ] + parent::defaultStorageSettings(); } From d848a91879a1b6fa1e02683c7e6769d16997d55d Mon Sep 17 00:00:00 2001 From: Diego Pino Navarro Date: Tue, 7 Jul 2020 11:33:23 -0400 Subject: [PATCH 4/9] drupal_set_message needs to be gone --- src/Form/keyNameProviderEntityDeleteForm.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Form/keyNameProviderEntityDeleteForm.php b/src/Form/keyNameProviderEntityDeleteForm.php index 320d922..bd8ebc3 100644 --- a/src/Form/keyNameProviderEntityDeleteForm.php +++ b/src/Form/keyNameProviderEntityDeleteForm.php @@ -37,8 +37,7 @@ public function getConfirmText() { */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->entity->delete(); - - drupal_set_message( + $this->messenger()->addMessage( $this->t('content @type: deleted @label.', [ '@type' => $this->entity->bundle(), From 4d545270d1154016f1436116d149e6d94439898c Mon Sep 17 00:00:00 2001 From: Diego Pino Navarro Date: Wed, 8 Jul 2020 18:03:50 -0400 Subject: [PATCH 5/9] Push 9.x Compat notice Still unsure about the Events and the dispatch method, which according to Symfony should be inversed by Version 4.3, but looking at webprofiler and Core they all still use the old nomenclature. --- composer.json | 1 + src/Event/StrawberryfieldCrudEvent.php | 2 +- strawberryfield.info.yml | 3 +-- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 5ac5d16..322349c 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,7 @@ } ], "require": { + "drupal/core": "^8.8 || ^9", "ml/json-ld": "^1.1", "mtdowling/jmespath.php":"^2.5", "swaggest/json-schema":"^0.12.25", diff --git a/src/Event/StrawberryfieldCrudEvent.php b/src/Event/StrawberryfieldCrudEvent.php index 3969c05..6874224 100644 --- a/src/Event/StrawberryfieldCrudEvent.php +++ b/src/Event/StrawberryfieldCrudEvent.php @@ -40,7 +40,7 @@ class StrawberryfieldCrudEvent extends Event { * @var array * */ - private $processedby; + private $processedby = []; /** * Construct a new entity event. diff --git a/strawberryfield.info.yml b/strawberryfield.info.yml index fa8b73e..80d1a27 100644 --- a/strawberryfield.info.yml +++ b/strawberryfield.info.yml @@ -2,10 +2,9 @@ name: Strawberry Field description: Creates a field type that stores JSON and makes it available to other Drupal modules. package: Archipelago type: module -core: 8.x +core_version_requirement: ^8.8 || ^9 php: 7.1 dependencies: - - 'drupal:system (>= 8.7)' - 'drupal:user' - 'drupal:field' - 'drupal:serialization' From 436342042b28a03a12a28a4f549b66710b91ead4 Mon Sep 17 00:00:00 2001 From: Diego Pino Navarro Date: Wed, 8 Jul 2020 18:04:02 -0400 Subject: [PATCH 6/9] Small double security here --- src/Plugin/DataType/StrawberryValuesViaJmesPathFromJson.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugin/DataType/StrawberryValuesViaJmesPathFromJson.php b/src/Plugin/DataType/StrawberryValuesViaJmesPathFromJson.php index 08f304a..b9d615d 100644 --- a/src/Plugin/DataType/StrawberryValuesViaJmesPathFromJson.php +++ b/src/Plugin/DataType/StrawberryValuesViaJmesPathFromJson.php @@ -61,7 +61,7 @@ public function process($langcode = NULL) $jmespath_array = array_map('trim', explode(',', $jmespaths)); $jmespath_result = []; foreach ($jmespath_array as $jmespath) { - $jmespath_result[] = $item->searchPath($jmespath,FALSE); + $jmespath_result[] = $item->searchPath(trim($jmespath),FALSE); } $jmespath_result_to_expose = []; From 84a078fbd2567e1fa26fc4500611f32f41e9b412 Mon Sep 17 00:00:00 2001 From: Diego Pino Navarro Date: Wed, 8 Jul 2020 18:13:14 -0400 Subject: [PATCH 7/9] Fix for good Benchmark drupal log message. Only get microtime if benchmark says yes. --- strawberryfield.module | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/strawberryfield.module b/strawberryfield.module index 356f2ad..3b67351 100644 --- a/strawberryfield.module +++ b/strawberryfield.module @@ -32,11 +32,12 @@ function strawberryfield_node_presave(ContentEntityInterface $entity) { // When benchmark is enabled a simple but effective report will be found in the reports/logs if ($config->get('benchmark')) { $bench = TRUE; + $start_time = microtime(true); } // Introducing our newest development, the processing time stats! // Starting on PHP 7.3 we should use hrtime for docker and VMS. // https://www.php.net/manual/en/function.microtime.php - $start_time = microtime(true); + //@TODO make bench simply an Event Method! That way we can measure every //Event by calling it and for new ones. Etc. @@ -49,11 +50,15 @@ function strawberryfield_node_presave(ContentEntityInterface $entity) { if ($bench) { $end_time = microtime(TRUE); // Removed bsuc - $time = round($end_time, $start_time, 4); + $time = round($end_time - $start_time, 4); $max_memory = memory_get_peak_usage(TRUE); - $events = implode("\n\r",$event->getProcessedBy()); + $events = ''; + foreach($event->getProcessedBy() as $event_info) { + $success = $event_info['success']? 'Successful' : 'Failure'; + $events .= $event_info['class'].'=>'.$success.'\n\r>'; + } \Drupal::logger('strawberryfield')->notice( - 'ADO with UUID @uuid spend @time in seconds on all presave event subscriber processing and max memory usage was @maxmem. Event Subscribers that run where the following
@events', + 'ADO with UUID @uuid spent @time seconds on all presave event subscriber processing and max memory usage was @maxmem. Event Subscribers that run where the following
@events', [ '@uuid' => $entity->uuid(), '@time' => $time, From 98923d4f515c3377467fe2ca781391af2fc1b70b Mon Sep 17 00:00:00 2001 From: Diego Pino Navarro Date: Wed, 8 Jul 2020 18:16:11 -0400 Subject: [PATCH 8/9] Use escapeshellarg instead of escapeshellcmd --- src/StrawberryfieldFilePersisterService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/StrawberryfieldFilePersisterService.php b/src/StrawberryfieldFilePersisterService.php index 7c33eca..503a7e1 100644 --- a/src/StrawberryfieldFilePersisterService.php +++ b/src/StrawberryfieldFilePersisterService.php @@ -1024,13 +1024,13 @@ public function getBaseFileMetadata(FileInterface $file) { $output_exif = ''; $output_fido = ''; $result_exif = exec( - $exif_exec_path . ' -json -q -a -gps:all -Common "-gps*" -xmp:all -ImageWidth -ImageHeight -Canon -Nikon-AllDates -pdf:all -ee -MIMEType ' . escapeshellcmd($templocation), + $exif_exec_path . ' -json -q -a -gps:all -Common "-gps*" -xmp:all -ImageWidth -ImageHeight -Canon -Nikon-AllDates -pdf:all -ee -MIMEType ' . escapeshellarg($templocation), $output_exif, $status_exif ); $result_fido = exec( - $fido_exec_path . ' ' . escapeshellcmd($templocation), + $fido_exec_path . ' ' . escapeshellarg($templocation), $output_fido, $status_fido ); From 63d38356169ea3558118ff94cb38533ea5f27af2 Mon Sep 17 00:00:00 2001 From: Diego Pino Navarro Date: Wed, 8 Jul 2020 19:04:44 -0400 Subject: [PATCH 9/9] Format list of events executed during presave If benchmark is enabled of course --- strawberryfield.module | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/strawberryfield.module b/strawberryfield.module index 3b67351..da1cea8 100644 --- a/strawberryfield.module +++ b/strawberryfield.module @@ -55,15 +55,16 @@ function strawberryfield_node_presave(ContentEntityInterface $entity) { $events = ''; foreach($event->getProcessedBy() as $event_info) { $success = $event_info['success']? 'Successful' : 'Failure'; - $events .= $event_info['class'].'=>'.$success.'\n\r>'; + $events .= '
  • '.$event_info['class']. ' => '.$success.'
  • '; } + $events_markup = \Drupal\Core\Render\Markup::create($events); \Drupal::logger('strawberryfield')->notice( - 'ADO with UUID @uuid spent @time seconds on all presave event subscriber processing and max memory usage was @maxmem. Event Subscribers that run where the following
    @events', + 'ADO with UUID @uuid spent @time seconds on all presave event subscriber processing and max memory usage was @maxmem.
    Event Subscribers that could run were the following:
      @events
    ', [ '@uuid' => $entity->uuid(), '@time' => $time, '@maxmem' => \Drupal::service('strawberryfield.utility')->formatBytes($max_memory, 2), - '@events' => $events, + '@events' => $events_markup, ] ); }